prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  When the -c option is used when starting NVDA user configuration can not be saved
  Steps to reproduce:
  
  - Open a command prompt and cd to the nvda.exe directory.
  - start nvda with `nvda.exe -c "C:\myTemp"
  - open the nvda menu and select "save configuration"
  
  An error is shown "Could not save configuration - probably read only file system".
  
  Regression caused by atomic rename/write fix. Config path is unicode without `-c`, but when `-c` is passed, the config path is ANSI. fileUtils assumes path is always Unicode.
  
  </issue>
  <code>
  [start of source/fileUtils.py]
  1 #fileUtils.py
  2 #A part of NonVisual Desktop Access (NVDA)
  3 #Copyright (C) 2017 NV Access Limited, Bram Duvigneau
  4 #This file is covered by the GNU General Public License.
  5 #See the file COPYING for more details.
  6 import os
  7 import ctypes
  8 from contextlib import contextmanager
  9 from tempfile import NamedTemporaryFile
  10 from logHandler import log
  11 
  12 #: Constant; flag for MoveFileEx(). If a file with the destination filename already exists, it is overwritten.
  13 MOVEFILE_REPLACE_EXISTING = 1
  14 
  15 @contextmanager
  16 def FaultTolerantFile(name):
  17 	'''Used to write out files in a more fault tolerant way. A temporary file is used, and replaces the 
  18 	file `name' when the context manager scope ends and the the context manager __exit__ is called. This
  19 	means writing out the complete file can be performed with less concern of corrupting the original file
  20 	if the process is interrupted by windows shutting down.
  21 
  22 	Usage:
  23 		with FaultTolerantFile("myFile.txt") as f:
  24 			f.write("This is a test")
  25 
  26 	This creates a temporary file, and the writes actually happen on this temp file. At the end of the 
  27 	`with` block, when `f` goes out of context the temporary file is closed and, this temporary file replaces "myFile.txt"
  28 	'''
  29 	dirpath, filename = os.path.split(name)
  30 	with NamedTemporaryFile(dir=dirpath, prefix=filename, suffix='.tmp', delete=False) as f:
  31 		log.debug(f.name)
  32 		yield f
  33 		f.flush()
  34 		os.fsync(f)
  35 		f.close()
  36 		moveFileResult = ctypes.windll.kernel32.MoveFileExW(f.name, name, MOVEFILE_REPLACE_EXISTING)
  37 		if moveFileResult == 0:
  38 			raise ctypes.WinError()
  39
  [end of source/fileUtils.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/source/fileUtils.py b/source/fileUtils.py
  --- a/source/fileUtils.py
  +++ b/source/fileUtils.py
  @@ -18,6 +18,7 @@
   	file `name' when the context manager scope ends and the the context manager __exit__ is called. This
   	means writing out the complete file can be performed with less concern of corrupting the original file
   	if the process is interrupted by windows shutting down.
  +	`name` must be unicode.
   
   	Usage:
   		with FaultTolerantFile("myFile.txt") as f:
  @@ -26,6 +27,8 @@
   	This creates a temporary file, and the writes actually happen on this temp file. At the end of the 
   	`with` block, when `f` goes out of context the temporary file is closed and, this temporary file replaces "myFile.txt"
   	'''
  +	if not isinstance(name, unicode):
  +		raise TypeError("name must be unicode")
   	dirpath, filename = os.path.split(name)
   	with NamedTemporaryFile(dir=dirpath, prefix=filename, suffix='.tmp', delete=False) as f:
   		log.debug(f.name)
  
verification_info: {"golden_diff": "diff --git a/source/fileUtils.py b/source/fileUtils.py\n--- a/source/fileUtils.py\n+++ b/source/fileUtils.py\n@@ -18,6 +18,7 @@\n \tfile `name' when the context manager scope ends and the the context manager __exit__ is called. This\n \tmeans writing out the complete file can be performed with less concern of corrupting the original file\n \tif the process is interrupted by windows shutting down.\n+\t`name` must be unicode.\n \n \tUsage:\n \t\twith FaultTolerantFile(\"myFile.txt\") as f:\n@@ -26,6 +27,8 @@\n \tThis creates a temporary file, and the writes actually happen on this temp file. At the end of the \n \t`with` block, when `f` goes out of context the temporary file is closed and, this temporary file replaces \"myFile.txt\"\n \t'''\n+\tif not isinstance(name, unicode):\n+\t\traise TypeError(\"name must be unicode\")\n \tdirpath, filename = os.path.split(name)\n \twith NamedTemporaryFile(dir=dirpath, prefix=filename, suffix='.tmp', delete=False) as f:\n \t\tlog.debug(f.name)\n", "issue": "When the -c option is used when starting NVDA user configuration can not be saved\nSteps to reproduce:\r\n\r\n- Open a command prompt and cd to the nvda.exe directory.\r\n- start nvda with `nvda.exe -c \"C:\\myTemp\"\r\n- open the nvda menu and select \"save configuration\"\r\n\r\nAn error is shown \"Could not save configuration - probably read only file system\".\r\n\r\nRegression caused by atomic rename/write fix. Config path is unicode without `-c`, but when `-c` is passed, the config path is ANSI. fileUtils assumes path is always Unicode.\n", "before_files": [{"content": "#fileUtils.py\n#A part of NonVisual Desktop Access (NVDA)\n#Copyright (C) 2017 NV Access Limited, Bram Duvigneau\n#This file is covered by the GNU General Public License.\n#See the file COPYING for more details.\nimport os\nimport ctypes\nfrom contextlib import contextmanager\nfrom tempfile import NamedTemporaryFile\nfrom logHandler import log\n\n#: Constant; flag for MoveFileEx(). If a file with the destination filename already exists, it is overwritten.\nMOVEFILE_REPLACE_EXISTING = 1\n\n@contextmanager\ndef FaultTolerantFile(name):\n\t'''Used to write out files in a more fault tolerant way. A temporary file is used, and replaces the \n\tfile `name' when the context manager scope ends and the the context manager __exit__ is called. This\n\tmeans writing out the complete file can be performed with less concern of corrupting the original file\n\tif the process is interrupted by windows shutting down.\n\n\tUsage:\n\t\twith FaultTolerantFile(\"myFile.txt\") as f:\n\t\t\tf.write(\"This is a test\")\n\n\tThis creates a temporary file, and the writes actually happen on this temp file. At the end of the \n\t`with` block, when `f` goes out of context the temporary file is closed and, this temporary file replaces \"myFile.txt\"\n\t'''\n\tdirpath, filename = os.path.split(name)\n\twith NamedTemporaryFile(dir=dirpath, prefix=filename, suffix='.tmp', delete=False) as f:\n\t\tlog.debug(f.name)\n\t\tyield f\n\t\tf.flush()\n\t\tos.fsync(f)\n\t\tf.close()\n\t\tmoveFileResult = ctypes.windll.kernel32.MoveFileExW(f.name, name, MOVEFILE_REPLACE_EXISTING)\n\t\tif moveFileResult == 0:\n\t\t\traise ctypes.WinError()\n", "path": "source/fileUtils.py"}]}