2 * File handling functions
4 * Copyright 1993 Erik Bos
5 * Copyright 1996, 2004 Alexandre Julliard
6 * Copyright 2003 Eric Pouech
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #include "wine/port.h"
33 #define WIN32_NO_STATUS
38 #include "kernel_private.h"
39 #include "wine/unicode.h"
40 #include "wine/debug.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(file
);
44 #define MAX_PATHNAME_LEN 1024
46 static int path_safe_mode
= -1; /* path mode set by SetSearchPathMode */
48 static const WCHAR wildcardsW
[] = {'*','?',0};
50 /* check if a file name is for an executable file (.exe or .com) */
51 static inline BOOL
is_executable( const WCHAR
*name
)
53 static const WCHAR exeW
[] = {'.','e','x','e',0};
54 static const WCHAR comW
[] = {'.','c','o','m',0};
55 int len
= strlenW(name
);
57 if (len
< 4) return FALSE
;
58 return (!strcmpiW( name
+ len
- 4, exeW
) || !strcmpiW( name
+ len
- 4, comW
));
61 /***********************************************************************
64 * copy a file name back to OEM/Ansi, but only if the buffer is large enough
66 static DWORD
copy_filename_WtoA( LPCWSTR nameW
, LPSTR buffer
, DWORD len
)
70 BOOL is_ansi
= AreFileApisANSI();
72 RtlInitUnicodeString( &strW
, nameW
);
74 ret
= is_ansi
? RtlUnicodeStringToAnsiSize(&strW
) : RtlUnicodeStringToOemSize(&strW
);
75 if (buffer
&& ret
<= len
)
80 str
.MaximumLength
= min( len
, UNICODE_STRING_MAX_CHARS
);
82 RtlUnicodeStringToAnsiString( &str
, &strW
, FALSE
);
84 RtlUnicodeStringToOemString( &str
, &strW
, FALSE
);
85 ret
= str
.Length
; /* length without terminating 0 */
90 /***********************************************************************
91 * add_boot_rename_entry
93 * Adds an entry to the registry that is loaded when windows boots and
94 * checks if there are some files to be removed or renamed/moved.
95 * <fn1> has to be valid and <fn2> may be NULL. If both pointers are
96 * non-NULL then the file is moved, otherwise it is deleted. The
97 * entry of the registry key is always appended with two zero
98 * terminated strings. If <fn2> is NULL then the second entry is
99 * simply a single 0-byte. Otherwise the second filename goes
100 * there. The entries are prepended with \??\ before the path and the
101 * second filename gets also a '!' as the first character if
102 * MOVEFILE_REPLACE_EXISTING is set. After the final string another
103 * 0-byte follows to indicate the end of the strings.
105 * \??\D:\test\file1[0]
106 * !\??\D:\test\file1_renamed[0]
107 * \??\D:\Test|delete[0]
108 * [0] <- file is to be deleted, second string empty
109 * \??\D:\test\file2[0]
110 * !\??\D:\test\file2_renamed[0]
111 * [0] <- indicates end of strings
114 * \??\D:\test\file1[0]
115 * !\??\D:\test\file1_renamed[0]
116 * \??\D:\Test|delete[0]
117 * [0] <- file is to be deleted, second string empty
118 * [0] <- indicates end of strings
121 static BOOL
add_boot_rename_entry( LPCWSTR source
, LPCWSTR dest
, DWORD flags
)
123 static const WCHAR ValueName
[] = {'P','e','n','d','i','n','g',
124 'F','i','l','e','R','e','n','a','m','e',
125 'O','p','e','r','a','t','i','o','n','s',0};
126 static const WCHAR SessionW
[] = {'\\','R','e','g','i','s','t','r','y','\\',
127 'M','a','c','h','i','n','e','\\',
128 'S','y','s','t','e','m','\\',
129 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
130 'C','o','n','t','r','o','l','\\',
131 'S','e','s','s','i','o','n',' ','M','a','n','a','g','e','r',0};
132 static const int info_size
= FIELD_OFFSET( KEY_VALUE_PARTIAL_INFORMATION
, Data
);
134 OBJECT_ATTRIBUTES attr
;
135 UNICODE_STRING nameW
, source_name
, dest_name
;
136 KEY_VALUE_PARTIAL_INFORMATION
*info
;
144 if (!RtlDosPathNameToNtPathName_U( source
, &source_name
, NULL
, NULL
))
146 SetLastError( ERROR_PATH_NOT_FOUND
);
149 dest_name
.Buffer
= NULL
;
150 if (dest
&& !RtlDosPathNameToNtPathName_U( dest
, &dest_name
, NULL
, NULL
))
152 RtlFreeUnicodeString( &source_name
);
153 SetLastError( ERROR_PATH_NOT_FOUND
);
157 attr
.Length
= sizeof(attr
);
158 attr
.RootDirectory
= 0;
159 attr
.ObjectName
= &nameW
;
161 attr
.SecurityDescriptor
= NULL
;
162 attr
.SecurityQualityOfService
= NULL
;
163 RtlInitUnicodeString( &nameW
, SessionW
);
165 if (NtCreateKey( &Reboot
, KEY_ALL_ACCESS
, &attr
, 0, NULL
, 0, NULL
) != STATUS_SUCCESS
)
167 WARN("Error creating key for reboot management [%s]\n",
168 "SYSTEM\\CurrentControlSet\\Control\\Session Manager");
169 RtlFreeUnicodeString( &source_name
);
170 RtlFreeUnicodeString( &dest_name
);
174 len1
= source_name
.Length
+ sizeof(WCHAR
);
177 len2
= dest_name
.Length
+ sizeof(WCHAR
);
178 if (flags
& MOVEFILE_REPLACE_EXISTING
)
179 len2
+= sizeof(WCHAR
); /* Plus 1 because of the leading '!' */
181 else len2
= sizeof(WCHAR
); /* minimum is the 0 characters for the empty second string */
183 RtlInitUnicodeString( &nameW
, ValueName
);
185 /* First we check if the key exists and if so how many bytes it already contains. */
186 if (NtQueryValueKey( Reboot
, &nameW
, KeyValuePartialInformation
,
187 NULL
, 0, &DataSize
) == STATUS_BUFFER_TOO_SMALL
)
189 if (!(Buffer
= HeapAlloc( GetProcessHeap(), 0, DataSize
+ len1
+ len2
+ sizeof(WCHAR
) )))
191 if (NtQueryValueKey( Reboot
, &nameW
, KeyValuePartialInformation
,
192 Buffer
, DataSize
, &DataSize
)) goto Quit
;
193 info
= (KEY_VALUE_PARTIAL_INFORMATION
*)Buffer
;
194 if (info
->Type
!= REG_MULTI_SZ
) goto Quit
;
195 if (DataSize
> sizeof(info
)) DataSize
-= sizeof(WCHAR
); /* remove terminating null (will be added back later) */
199 DataSize
= info_size
;
200 if (!(Buffer
= HeapAlloc( GetProcessHeap(), 0, DataSize
+ len1
+ len2
+ sizeof(WCHAR
) )))
204 memcpy( Buffer
+ DataSize
, source_name
.Buffer
, len1
);
206 p
= (WCHAR
*)(Buffer
+ DataSize
);
209 if (flags
& MOVEFILE_REPLACE_EXISTING
)
211 memcpy( p
, dest_name
.Buffer
, len2
);
217 DataSize
+= sizeof(WCHAR
);
221 p
= (WCHAR
*)(Buffer
+ DataSize
);
223 DataSize
+= sizeof(WCHAR
);
225 rc
= !NtSetValueKey(Reboot
, &nameW
, 0, REG_MULTI_SZ
, Buffer
+ info_size
, DataSize
- info_size
);
228 RtlFreeUnicodeString( &source_name
);
229 RtlFreeUnicodeString( &dest_name
);
230 if (Reboot
) NtClose(Reboot
);
231 HeapFree( GetProcessHeap(), 0, Buffer
);
236 /***********************************************************************
237 * GetFullPathNameW (KERNEL32.@)
239 * if the path closed with '\', *lastpart is 0
241 DWORD WINAPI
GetFullPathNameW( LPCWSTR name
, DWORD len
, LPWSTR buffer
,
244 return RtlGetFullPathName_U(name
, len
* sizeof(WCHAR
), buffer
, lastpart
) / sizeof(WCHAR
);
247 /***********************************************************************
248 * GetFullPathNameA (KERNEL32.@)
250 * if the path closed with '\', *lastpart is 0
252 DWORD WINAPI
GetFullPathNameA( LPCSTR name
, DWORD len
, LPSTR buffer
,
256 WCHAR bufferW
[MAX_PATH
], *lastpartW
= NULL
;
259 if (!(nameW
= FILE_name_AtoW( name
, FALSE
))) return 0;
261 ret
= GetFullPathNameW( nameW
, MAX_PATH
, bufferW
, &lastpartW
);
266 SetLastError(ERROR_FILENAME_EXCED_RANGE
);
269 ret
= copy_filename_WtoA( bufferW
, buffer
, len
);
270 if (ret
< len
&& lastpart
)
273 *lastpart
= buffer
+ FILE_name_WtoA( bufferW
, lastpartW
- bufferW
, NULL
, 0 );
281 /***********************************************************************
282 * GetLongPathNameW (KERNEL32.@)
285 * observed (Win2000):
286 * shortpath=NULL: LastError=ERROR_INVALID_PARAMETER, ret=0
287 * shortpath="": LastError=ERROR_PATH_NOT_FOUND, ret=0
289 DWORD WINAPI
GetLongPathNameW( LPCWSTR shortpath
, LPWSTR longpath
, DWORD longlen
)
291 WCHAR tmplongpath
[MAX_PATHNAME_LEN
];
293 DWORD sp
= 0, lp
= 0;
296 WIN32_FIND_DATAW wfd
;
300 TRACE("%s,%p,%u\n", debugstr_w(shortpath
), longpath
, longlen
);
304 SetLastError(ERROR_INVALID_PARAMETER
);
309 SetLastError(ERROR_PATH_NOT_FOUND
);
313 if (shortpath
[0] == '\\' && shortpath
[1] == '\\')
315 FIXME("UNC pathname %s\n", debugstr_w(shortpath
));
317 tmplen
= strlenW(shortpath
);
318 if (tmplen
< longlen
)
320 if (longpath
!= shortpath
) strcpyW( longpath
, shortpath
);
326 unixabsolute
= (shortpath
[0] == '/');
328 /* check for drive letter */
329 if (!unixabsolute
&& shortpath
[1] == ':' )
331 tmplongpath
[0] = shortpath
[0];
332 tmplongpath
[1] = ':';
336 if (strpbrkW(shortpath
+ sp
, wildcardsW
))
338 SetLastError(ERROR_INVALID_NAME
);
342 while (shortpath
[sp
])
344 /* check for path delimiters and reproduce them */
345 if (shortpath
[sp
] == '\\' || shortpath
[sp
] == '/')
347 tmplongpath
[lp
++] = shortpath
[sp
++];
348 tmplongpath
[lp
] = 0; /* terminate string */
353 for (; *p
&& *p
!= '/' && *p
!= '\\'; p
++);
354 tmplen
= p
- (shortpath
+ sp
);
355 lstrcpynW(tmplongpath
+ lp
, shortpath
+ sp
, tmplen
+ 1);
357 if (tmplongpath
[lp
] == '.')
359 if (tmplen
== 1 || (tmplen
== 2 && tmplongpath
[lp
+ 1] == '.'))
367 /* Check if the file exists */
368 goit
= FindFirstFileW(tmplongpath
, &wfd
);
369 if (goit
== INVALID_HANDLE_VALUE
)
371 TRACE("not found %s!\n", debugstr_w(tmplongpath
));
372 SetLastError ( ERROR_FILE_NOT_FOUND
);
377 is_legal_8dot3
= FALSE
;
378 CheckNameLegalDOS8Dot3W(tmplongpath
+ lp
, NULL
, 0, NULL
, &is_legal_8dot3
);
379 /* Use the existing file name if it's a short name */
381 strcpyW(tmplongpath
+ lp
, wfd
.cFileName
);
382 lp
+= strlenW(tmplongpath
+ lp
);
385 tmplen
= strlenW(shortpath
) - 1;
386 if ((shortpath
[tmplen
] == '/' || shortpath
[tmplen
] == '\\') &&
387 (tmplongpath
[lp
- 1] != '/' && tmplongpath
[lp
- 1] != '\\'))
388 tmplongpath
[lp
++] = shortpath
[tmplen
];
391 tmplen
= strlenW(tmplongpath
) + 1;
392 if (tmplen
<= longlen
)
394 strcpyW(longpath
, tmplongpath
);
395 TRACE("returning %s\n", debugstr_w(longpath
));
396 tmplen
--; /* length without 0 */
402 /***********************************************************************
403 * GetLongPathNameA (KERNEL32.@)
405 DWORD WINAPI
GetLongPathNameA( LPCSTR shortpath
, LPSTR longpath
, DWORD longlen
)
408 WCHAR longpathW
[MAX_PATH
];
411 TRACE("%s\n", debugstr_a(shortpath
));
413 if (!(shortpathW
= FILE_name_AtoW( shortpath
, FALSE
))) return 0;
415 ret
= GetLongPathNameW(shortpathW
, longpathW
, MAX_PATH
);
420 SetLastError(ERROR_FILENAME_EXCED_RANGE
);
423 return copy_filename_WtoA( longpathW
, longpath
, longlen
);
427 /***********************************************************************
428 * GetShortPathNameW (KERNEL32.@)
432 * longpath=NULL: LastError=ERROR_INVALID_PARAMETER, ret=0
433 * longpath="" or invalid: LastError=ERROR_BAD_PATHNAME, ret=0
435 * more observations ( with NT 3.51 (WinDD) ):
436 * longpath <= 8.3 -> just copy longpath to shortpath
438 * a) file does not exist -> return 0, LastError = ERROR_FILE_NOT_FOUND
439 * b) file does exist -> set the short filename.
440 * - trailing slashes are reproduced in the short name, even if the
441 * file is not a directory
442 * - the absolute/relative path of the short name is reproduced like found
444 * - longpath and shortpath may have the same address
447 DWORD WINAPI
GetShortPathNameW( LPCWSTR longpath
, LPWSTR shortpath
, DWORD shortlen
)
451 DWORD sp
= 0, lp
= 0;
452 DWORD tmplen
, buf_len
;
453 WIN32_FIND_DATAW wfd
;
456 TRACE("%s,%p,%u\n", debugstr_w(longpath
), shortpath
, shortlen
);
460 SetLastError(ERROR_INVALID_PARAMETER
);
465 SetLastError(ERROR_BAD_PATHNAME
);
469 /* code below only removes characters from string, never adds, so this is
470 * the largest buffer that tmpshortpath will need to have */
471 buf_len
= strlenW(longpath
) + 1;
472 tmpshortpath
= HeapAlloc(GetProcessHeap(), 0, buf_len
* sizeof(WCHAR
));
475 SetLastError(ERROR_OUTOFMEMORY
);
479 if (longpath
[0] == '\\' && longpath
[1] == '\\' && longpath
[2] == '?' && longpath
[3] == '\\')
481 memcpy(tmpshortpath
, longpath
, 4 * sizeof(WCHAR
));
485 if (strpbrkW(longpath
+ lp
, wildcardsW
))
487 HeapFree(GetProcessHeap(), 0, tmpshortpath
);
488 SetLastError(ERROR_INVALID_NAME
);
492 /* check for drive letter */
493 if (longpath
[lp
] != '/' && longpath
[lp
+ 1] == ':' )
495 tmpshortpath
[sp
] = longpath
[lp
];
496 tmpshortpath
[sp
+ 1] = ':';
503 /* check for path delimiters and reproduce them */
504 if (longpath
[lp
] == '\\' || longpath
[lp
] == '/')
506 tmpshortpath
[sp
++] = longpath
[lp
++];
507 tmpshortpath
[sp
] = 0; /* terminate string */
512 for (; *p
&& *p
!= '/' && *p
!= '\\'; p
++);
513 tmplen
= p
- (longpath
+ lp
);
514 lstrcpynW(tmpshortpath
+ sp
, longpath
+ lp
, tmplen
+ 1);
516 if (tmpshortpath
[sp
] == '.')
518 if (tmplen
== 1 || (tmplen
== 2 && tmpshortpath
[sp
+ 1] == '.'))
526 /* Check if the file exists and use the existing short file name */
527 goit
= FindFirstFileW(tmpshortpath
, &wfd
);
528 if (goit
== INVALID_HANDLE_VALUE
) goto notfound
;
531 /* In rare cases (like "a.abcd") short path may be longer than original path.
532 * Make sure we have enough space in temp buffer. */
533 if (wfd
.cAlternateFileName
[0] && tmplen
< strlenW(wfd
.cAlternateFileName
))
536 buf_len
+= strlenW(wfd
.cAlternateFileName
) - tmplen
;
537 new_buf
= HeapReAlloc(GetProcessHeap(), 0, tmpshortpath
, buf_len
* sizeof(WCHAR
));
540 HeapFree(GetProcessHeap(), 0, tmpshortpath
);
541 SetLastError(ERROR_OUTOFMEMORY
);
544 tmpshortpath
= new_buf
;
547 strcpyW(tmpshortpath
+ sp
, wfd
.cAlternateFileName
[0] ? wfd
.cAlternateFileName
: wfd
.cFileName
);
548 sp
+= strlenW(tmpshortpath
+ sp
);
551 tmpshortpath
[sp
] = 0;
553 tmplen
= strlenW(tmpshortpath
) + 1;
554 if (tmplen
<= shortlen
)
556 strcpyW(shortpath
, tmpshortpath
);
557 TRACE("returning %s\n", debugstr_w(shortpath
));
558 tmplen
--; /* length without 0 */
561 HeapFree(GetProcessHeap(), 0, tmpshortpath
);
565 HeapFree(GetProcessHeap(), 0, tmpshortpath
);
566 TRACE("not found!\n" );
567 SetLastError ( ERROR_FILE_NOT_FOUND
);
571 /***********************************************************************
572 * GetShortPathNameA (KERNEL32.@)
574 DWORD WINAPI
GetShortPathNameA( LPCSTR longpath
, LPSTR shortpath
, DWORD shortlen
)
577 WCHAR shortpathW
[MAX_PATH
];
580 TRACE("%s\n", debugstr_a(longpath
));
582 if (!(longpathW
= FILE_name_AtoW( longpath
, FALSE
))) return 0;
584 ret
= GetShortPathNameW(longpathW
, shortpathW
, MAX_PATH
);
589 SetLastError(ERROR_FILENAME_EXCED_RANGE
);
592 return copy_filename_WtoA( shortpathW
, shortpath
, shortlen
);
596 /***********************************************************************
597 * GetTempPathA (KERNEL32.@)
599 DWORD WINAPI
GetTempPathA( DWORD count
, LPSTR path
)
601 WCHAR pathW
[MAX_PATH
];
604 ret
= GetTempPathW(MAX_PATH
, pathW
);
611 SetLastError(ERROR_FILENAME_EXCED_RANGE
);
614 return copy_filename_WtoA( pathW
, path
, count
);
618 /***********************************************************************
619 * GetTempPathW (KERNEL32.@)
621 DWORD WINAPI
GetTempPathW( DWORD count
, LPWSTR path
)
623 static const WCHAR tmp
[] = { 'T', 'M', 'P', 0 };
624 static const WCHAR temp
[] = { 'T', 'E', 'M', 'P', 0 };
625 static const WCHAR userprofile
[] = { 'U','S','E','R','P','R','O','F','I','L','E',0 };
626 WCHAR tmp_path
[MAX_PATH
];
629 TRACE("%u,%p\n", count
, path
);
631 if (!(ret
= GetEnvironmentVariableW( tmp
, tmp_path
, MAX_PATH
)) &&
632 !(ret
= GetEnvironmentVariableW( temp
, tmp_path
, MAX_PATH
)) &&
633 !(ret
= GetEnvironmentVariableW( userprofile
, tmp_path
, MAX_PATH
)) &&
634 !(ret
= GetWindowsDirectoryW( tmp_path
, MAX_PATH
)))
639 SetLastError(ERROR_FILENAME_EXCED_RANGE
);
643 ret
= GetFullPathNameW(tmp_path
, MAX_PATH
, tmp_path
, NULL
);
646 if (ret
> MAX_PATH
- 2)
648 SetLastError(ERROR_FILENAME_EXCED_RANGE
);
652 if (tmp_path
[ret
-1] != '\\')
654 tmp_path
[ret
++] = '\\';
655 tmp_path
[ret
] = '\0';
658 ret
++; /* add space for terminating 0 */
662 lstrcpynW(path
, tmp_path
, count
);
663 /* the remaining buffer must be zeroed up to 32766 bytes in XP or 32767
664 * bytes after it, we will assume the > XP behavior for now */
665 memset(path
+ ret
, 0, (min(count
, 32767) - ret
) * sizeof(WCHAR
));
666 ret
--; /* return length without 0 */
670 /* the buffer must be cleared if contents will not fit */
671 memset(path
, 0, count
* sizeof(WCHAR
));
674 TRACE("returning %u, %s\n", ret
, debugstr_w(path
));
679 /***********************************************************************
680 * GetTempFileNameA (KERNEL32.@)
682 UINT WINAPI
GetTempFileNameA( LPCSTR path
, LPCSTR prefix
, UINT unique
, LPSTR buffer
)
684 WCHAR
*pathW
, *prefixW
= NULL
;
685 WCHAR bufferW
[MAX_PATH
];
688 if (!(pathW
= FILE_name_AtoW( path
, FALSE
))) return 0;
689 if (prefix
&& !(prefixW
= FILE_name_AtoW( prefix
, TRUE
))) return 0;
691 ret
= GetTempFileNameW(pathW
, prefixW
, unique
, bufferW
);
692 if (ret
) FILE_name_WtoA( bufferW
, -1, buffer
, MAX_PATH
);
694 HeapFree( GetProcessHeap(), 0, prefixW
);
698 /***********************************************************************
699 * GetTempFileNameW (KERNEL32.@)
701 UINT WINAPI
GetTempFileNameW( LPCWSTR path
, LPCWSTR prefix
, UINT unique
, LPWSTR buffer
)
703 static const WCHAR formatW
[] = {'%','x','.','t','m','p',0};
709 if ( !path
|| !buffer
)
711 SetLastError( ERROR_INVALID_PARAMETER
);
715 /* ensure that the provided directory exists */
716 attr
= GetFileAttributesW(path
);
717 if (attr
== INVALID_FILE_ATTRIBUTES
|| !(attr
& FILE_ATTRIBUTE_DIRECTORY
))
719 TRACE("path not found %s\n", debugstr_w(path
));
720 SetLastError( ERROR_DIRECTORY
);
724 strcpyW( buffer
, path
);
725 p
= buffer
+ strlenW(buffer
);
727 /* add a \, if there isn't one */
728 if ((p
== buffer
) || (p
[-1] != '\\')) *p
++ = '\\';
731 for (i
= 3; (i
> 0) && (*prefix
); i
--) *p
++ = *prefix
++;
735 if (unique
) sprintfW( p
, formatW
, unique
);
738 /* get a "random" unique number and try to create the file */
740 UINT num
= GetTickCount() & 0xffff;
743 /* avoid using the same name twice in a short interval */
744 if (last
- num
< 10) num
= last
+ 1;
749 sprintfW( p
, formatW
, unique
);
750 handle
= CreateFileW( buffer
, GENERIC_WRITE
, 0, NULL
,
751 CREATE_NEW
, FILE_ATTRIBUTE_NORMAL
, 0 );
752 if (handle
!= INVALID_HANDLE_VALUE
)
753 { /* We created it */
754 TRACE("created %s\n", debugstr_w(buffer
) );
755 CloseHandle( handle
);
759 if (GetLastError() != ERROR_FILE_EXISTS
&&
760 GetLastError() != ERROR_SHARING_VIOLATION
)
761 break; /* No need to go on */
762 if (!(++unique
& 0xffff)) unique
= 1;
763 } while (unique
!= num
);
766 TRACE("returning %s\n", debugstr_w(buffer
) );
771 /***********************************************************************
774 static BOOL
get_path_safe_mode(void)
776 static const WCHAR keyW
[] = {'\\','R','e','g','i','s','t','r','y','\\',
777 'M','a','c','h','i','n','e','\\',
778 'S','y','s','t','e','m','\\',
779 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
780 'C','o','n','t','r','o','l','\\',
781 'S','e','s','s','i','o','n',' ','M','a','n','a','g','e','r',0};
782 static const WCHAR valueW
[] = {'S','a','f','e','P','r','o','c','e','s','s','S','e','a','r','c','h','M','o','d','e',0};
784 if (path_safe_mode
== -1)
786 char buffer
[offsetof(KEY_VALUE_PARTIAL_INFORMATION
, Data
[sizeof(DWORD
)])];
787 KEY_VALUE_PARTIAL_INFORMATION
*info
= (KEY_VALUE_PARTIAL_INFORMATION
*)buffer
;
788 OBJECT_ATTRIBUTES attr
;
789 UNICODE_STRING nameW
;
791 DWORD size
= sizeof(buffer
);
794 attr
.Length
= sizeof(attr
);
795 attr
.RootDirectory
= 0;
796 attr
.ObjectName
= &nameW
;
798 attr
.SecurityDescriptor
= NULL
;
799 attr
.SecurityQualityOfService
= NULL
;
801 RtlInitUnicodeString( &nameW
, keyW
);
802 if (!NtOpenKey( &hkey
, KEY_READ
, &attr
))
804 RtlInitUnicodeString( &nameW
, valueW
);
805 if (!NtQueryValueKey( hkey
, &nameW
, KeyValuePartialInformation
, buffer
, size
, &size
) &&
806 info
->Type
== REG_DWORD
&& info
->DataLength
== sizeof(DWORD
))
807 mode
= !!*(DWORD
*)info
->Data
;
810 InterlockedCompareExchange( &path_safe_mode
, mode
, -1 );
812 return path_safe_mode
!= 0;
816 /***********************************************************************
819 * Check if the file name contains a path; helper for SearchPathW.
820 * A relative path is not considered a path unless it starts with ./ or ../
822 static inline BOOL
contains_pathW (LPCWSTR name
)
824 if (RtlDetermineDosPathNameType_U( name
) != RELATIVE_PATH
) return TRUE
;
825 if (name
[0] != '.') return FALSE
;
826 if (name
[1] == '/' || name
[1] == '\\') return TRUE
;
827 return (name
[1] == '.' && (name
[2] == '/' || name
[2] == '\\'));
830 /***********************************************************************
831 * find_actctx_dllpath
833 * Find the path (if any) of the dll from the activation context.
834 * Returned path doesn't include a name.
836 static NTSTATUS
find_actctx_dllpath(const WCHAR
*libname
, WCHAR
**path
)
838 static const WCHAR winsxsW
[] = {'\\','w','i','n','s','x','s','\\'};
839 static const WCHAR dotManifestW
[] = {'.','m','a','n','i','f','e','s','t',0};
841 ACTIVATION_CONTEXT_ASSEMBLY_DETAILED_INFORMATION
*info
;
842 ACTCTX_SECTION_KEYED_DATA data
;
843 UNICODE_STRING nameW
;
845 SIZE_T needed
, size
= 1024;
848 RtlInitUnicodeString( &nameW
, libname
);
849 data
.cbSize
= sizeof(data
);
850 status
= RtlFindActivationContextSectionString( FIND_ACTCTX_SECTION_KEY_RETURN_HACTCTX
, NULL
,
851 ACTIVATION_CONTEXT_SECTION_DLL_REDIRECTION
,
853 if (status
!= STATUS_SUCCESS
) return status
;
857 if (!(info
= HeapAlloc( GetProcessHeap(), 0, size
)))
859 status
= STATUS_NO_MEMORY
;
862 status
= RtlQueryInformationActivationContext( 0, data
.hActCtx
, &data
.ulAssemblyRosterIndex
,
863 AssemblyDetailedInformationInActivationContext
,
864 info
, size
, &needed
);
865 if (status
== STATUS_SUCCESS
) break;
866 if (status
!= STATUS_BUFFER_TOO_SMALL
) goto done
;
867 HeapFree( GetProcessHeap(), 0, info
);
869 /* restart with larger buffer */
872 if (!info
->lpAssemblyManifestPath
|| !info
->lpAssemblyDirectoryName
)
874 status
= STATUS_SXS_KEY_NOT_FOUND
;
878 if ((p
= strrchrW( info
->lpAssemblyManifestPath
, '\\' )))
880 DWORD dirlen
= info
->ulAssemblyDirectoryNameLength
/ sizeof(WCHAR
);
883 if (strncmpiW( p
, info
->lpAssemblyDirectoryName
, dirlen
) || strcmpiW( p
+ dirlen
, dotManifestW
))
885 /* manifest name does not match directory name, so it's not a global
886 * windows/winsxs manifest; use the manifest directory name instead */
887 dirlen
= p
- info
->lpAssemblyManifestPath
;
888 needed
= (dirlen
+ 1) * sizeof(WCHAR
);
889 if (!(*path
= p
= HeapAlloc( GetProcessHeap(), 0, needed
)))
891 status
= STATUS_NO_MEMORY
;
894 memcpy( p
, info
->lpAssemblyManifestPath
, dirlen
* sizeof(WCHAR
) );
900 needed
= (strlenW( DIR_Windows
) * sizeof(WCHAR
) +
901 sizeof(winsxsW
) + info
->ulAssemblyDirectoryNameLength
+ 2*sizeof(WCHAR
));
903 if (!(*path
= p
= HeapAlloc( GetProcessHeap(), 0, needed
)))
905 status
= STATUS_NO_MEMORY
;
908 strcpyW( p
, DIR_Windows
);
910 memcpy( p
, winsxsW
, sizeof(winsxsW
) );
911 p
+= ARRAY_SIZE( winsxsW
);
912 memcpy( p
, info
->lpAssemblyDirectoryName
, info
->ulAssemblyDirectoryNameLength
);
913 p
+= info
->ulAssemblyDirectoryNameLength
/ sizeof(WCHAR
);
917 HeapFree( GetProcessHeap(), 0, info
);
918 RtlReleaseActivationContext( data
.hActCtx
);
922 /***********************************************************************
923 * SearchPathW [KERNEL32.@]
925 * Searches for a specified file in the search path.
928 * path [I] Path to search (NULL means default)
929 * name [I] Filename to search for.
930 * ext [I] File extension to append to file name. The first
931 * character must be a period. This parameter is
932 * specified only if the filename given does not
933 * contain an extension.
934 * buflen [I] size of buffer, in characters
935 * buffer [O] buffer for found filename
936 * lastpart [O] address of pointer to last used character in
937 * buffer (the final '\')
940 * Success: length of string copied into buffer, not including
941 * terminating null character. If the filename found is
942 * longer than the length of the buffer, the length of the
943 * filename is returned.
947 * If the file is not found, calls SetLastError(ERROR_FILE_NOT_FOUND)
950 DWORD WINAPI
SearchPathW( LPCWSTR path
, LPCWSTR name
, LPCWSTR ext
, DWORD buflen
,
951 LPWSTR buffer
, LPWSTR
*lastpart
)
955 if (!name
|| !name
[0])
957 SetLastError(ERROR_INVALID_PARAMETER
);
961 /* If the name contains an explicit path, ignore the path */
963 if (contains_pathW(name
))
965 /* try first without extension */
966 if (RtlDoesFileExists_U( name
))
967 return GetFullPathNameW( name
, buflen
, buffer
, lastpart
);
971 LPCWSTR p
= strrchrW( name
, '.' );
972 if (p
&& !strchrW( p
, '/' ) && !strchrW( p
, '\\' ))
973 ext
= NULL
; /* Ignore the specified extension */
976 /* Allocate a buffer for the file name and extension */
980 DWORD len
= strlenW(name
) + strlenW(ext
);
982 if (!(tmp
= HeapAlloc( GetProcessHeap(), 0, (len
+ 1) * sizeof(WCHAR
) )))
984 SetLastError( ERROR_OUTOFMEMORY
);
987 strcpyW( tmp
, name
);
989 if (RtlDoesFileExists_U( tmp
))
990 ret
= GetFullPathNameW( tmp
, buflen
, buffer
, lastpart
);
991 HeapFree( GetProcessHeap(), 0, tmp
);
994 else if (path
&& path
[0]) /* search in the specified path */
996 ret
= RtlDosSearchPath_U( path
, name
, ext
, buflen
* sizeof(WCHAR
),
997 buffer
, lastpart
) / sizeof(WCHAR
);
999 else /* search in active context and default path */
1001 WCHAR
*dll_path
= NULL
, *search
= NULL
;
1002 DWORD req_len
, name_len
;
1004 req_len
= name_len
= strlenW(name
);
1006 if (strchrW( name
, '.' )) ext
= NULL
;
1009 DWORD ext_len
= strlenW(ext
);
1012 name_len
+= ext_len
;
1014 search
= HeapAlloc( GetProcessHeap(), 0, (name_len
+ ext_len
+ 1) * sizeof(WCHAR
) );
1017 SetLastError( ERROR_OUTOFMEMORY
);
1020 strcpyW( search
, name
);
1021 strcatW( search
, ext
);
1024 /* now that we have combined name we don't need extension any more */
1027 /* When file is found with activation context no attempt is made
1028 to check if it's really exist, path is returned only basing on context info. */
1029 if (find_actctx_dllpath( name
, &dll_path
) == STATUS_SUCCESS
)
1033 path_len
= strlenW(dll_path
);
1034 req_len
+= path_len
;
1036 if (lastpart
) *lastpart
= NULL
;
1038 /* count null termination char too */
1039 if (req_len
+ 1 <= buflen
)
1041 memcpy( buffer
, dll_path
, path_len
* sizeof(WCHAR
) );
1042 memcpy( &buffer
[path_len
], name
, name_len
* sizeof(WCHAR
) );
1043 buffer
[req_len
] = 0;
1044 if (lastpart
) *lastpart
= buffer
+ path_len
;
1050 HeapFree( GetProcessHeap(), 0, dll_path
);
1051 HeapFree( GetProcessHeap(), 0, search
);
1055 if ((dll_path
= MODULE_get_dll_load_path( NULL
, get_path_safe_mode() )))
1057 ret
= RtlDosSearchPath_U( dll_path
, name
, NULL
, buflen
* sizeof(WCHAR
),
1058 buffer
, lastpart
) / sizeof(WCHAR
);
1059 HeapFree( GetProcessHeap(), 0, dll_path
);
1060 HeapFree( GetProcessHeap(), 0, search
);
1064 SetLastError( ERROR_OUTOFMEMORY
);
1070 if (!ret
) SetLastError( ERROR_FILE_NOT_FOUND
);
1071 else TRACE( "found %s\n", debugstr_w(buffer
) );
1076 /***********************************************************************
1077 * SearchPathA (KERNEL32.@)
1081 DWORD WINAPI
SearchPathA( LPCSTR path
, LPCSTR name
, LPCSTR ext
,
1082 DWORD buflen
, LPSTR buffer
, LPSTR
*lastpart
)
1084 WCHAR
*pathW
= NULL
, *nameW
, *extW
= NULL
;
1085 WCHAR bufferW
[MAX_PATH
];
1090 SetLastError(ERROR_INVALID_PARAMETER
);
1094 if (!(nameW
= FILE_name_AtoW( name
, FALSE
))) return 0;
1095 if (path
&& !(pathW
= FILE_name_AtoW( path
, TRUE
))) return 0;
1097 if (ext
&& !(extW
= FILE_name_AtoW( ext
, TRUE
)))
1099 HeapFree( GetProcessHeap(), 0, pathW
);
1103 ret
= SearchPathW(pathW
, nameW
, extW
, MAX_PATH
, bufferW
, NULL
);
1105 HeapFree( GetProcessHeap(), 0, pathW
);
1106 HeapFree( GetProcessHeap(), 0, extW
);
1111 SetLastError(ERROR_FILENAME_EXCED_RANGE
);
1114 ret
= copy_filename_WtoA( bufferW
, buffer
, buflen
);
1115 if (buflen
> ret
&& lastpart
)
1116 *lastpart
= strrchr(buffer
, '\\') + 1;
1120 static BOOL
is_same_file(HANDLE h1
, HANDLE h2
)
1124 if (wine_server_handle_to_fd(h1
, 0, &fd1
, NULL
) == STATUS_SUCCESS
)
1127 if (wine_server_handle_to_fd(h2
, 0, &fd2
, NULL
) == STATUS_SUCCESS
)
1129 struct stat stat1
, stat2
;
1130 if (fstat(fd1
, &stat1
) == 0 && fstat(fd2
, &stat2
) == 0)
1131 ret
= (stat1
.st_dev
== stat2
.st_dev
&& stat1
.st_ino
== stat2
.st_ino
);
1132 wine_server_release_fd(h2
, fd2
);
1134 wine_server_release_fd(h1
, fd1
);
1139 /**************************************************************************
1140 * CopyFileW (KERNEL32.@)
1142 BOOL WINAPI
CopyFileW( LPCWSTR source
, LPCWSTR dest
, BOOL fail_if_exists
)
1144 return CopyFileExW( source
, dest
, NULL
, NULL
, NULL
,
1145 fail_if_exists
? COPY_FILE_FAIL_IF_EXISTS
: 0 );
1149 /**************************************************************************
1150 * CopyFileA (KERNEL32.@)
1152 BOOL WINAPI
CopyFileA( LPCSTR source
, LPCSTR dest
, BOOL fail_if_exists
)
1154 WCHAR
*sourceW
, *destW
;
1157 if (!(sourceW
= FILE_name_AtoW( source
, FALSE
))) return FALSE
;
1158 if (!(destW
= FILE_name_AtoW( dest
, TRUE
))) return FALSE
;
1160 ret
= CopyFileW( sourceW
, destW
, fail_if_exists
);
1162 HeapFree( GetProcessHeap(), 0, destW
);
1167 /**************************************************************************
1168 * CopyFileExW (KERNEL32.@)
1170 BOOL WINAPI
CopyFileExW(LPCWSTR source
, LPCWSTR dest
,
1171 LPPROGRESS_ROUTINE progress
, LPVOID param
,
1172 LPBOOL cancel_ptr
, DWORD flags
)
1174 static const int buffer_size
= 65536;
1176 BY_HANDLE_FILE_INFORMATION info
;
1181 if (!source
|| !dest
)
1183 SetLastError(ERROR_INVALID_PARAMETER
);
1186 if (!(buffer
= HeapAlloc( GetProcessHeap(), 0, buffer_size
)))
1188 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1192 TRACE("%s -> %s, %x\n", debugstr_w(source
), debugstr_w(dest
), flags
);
1194 if ((h1
= CreateFileW(source
, GENERIC_READ
,
1195 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
1196 NULL
, OPEN_EXISTING
, 0, 0)) == INVALID_HANDLE_VALUE
)
1198 WARN("Unable to open source %s\n", debugstr_w(source
));
1199 HeapFree( GetProcessHeap(), 0, buffer
);
1203 if (!GetFileInformationByHandle( h1
, &info
))
1205 WARN("GetFileInformationByHandle returned error for %s\n", debugstr_w(source
));
1206 HeapFree( GetProcessHeap(), 0, buffer
);
1211 if (!(flags
& COPY_FILE_FAIL_IF_EXISTS
))
1213 BOOL same_file
= FALSE
;
1214 h2
= CreateFileW( dest
, 0, FILE_SHARE_READ
| FILE_SHARE_WRITE
, NULL
,
1215 OPEN_EXISTING
, 0, 0);
1216 if (h2
!= INVALID_HANDLE_VALUE
)
1218 same_file
= is_same_file( h1
, h2
);
1223 HeapFree( GetProcessHeap(), 0, buffer
);
1225 SetLastError( ERROR_SHARING_VIOLATION
);
1230 if ((h2
= CreateFileW( dest
, GENERIC_WRITE
, FILE_SHARE_READ
| FILE_SHARE_WRITE
, NULL
,
1231 (flags
& COPY_FILE_FAIL_IF_EXISTS
) ? CREATE_NEW
: CREATE_ALWAYS
,
1232 info
.dwFileAttributes
, h1
)) == INVALID_HANDLE_VALUE
)
1234 WARN("Unable to open dest %s\n", debugstr_w(dest
));
1235 HeapFree( GetProcessHeap(), 0, buffer
);
1240 while (ReadFile( h1
, buffer
, buffer_size
, &count
, NULL
) && count
)
1246 if (!WriteFile( h2
, p
, count
, &res
, NULL
) || !res
) goto done
;
1253 /* Maintain the timestamp of source file to destination file */
1254 SetFileTime(h2
, NULL
, NULL
, &info
.ftLastWriteTime
);
1255 HeapFree( GetProcessHeap(), 0, buffer
);
1262 /**************************************************************************
1263 * CopyFileExA (KERNEL32.@)
1265 BOOL WINAPI
CopyFileExA(LPCSTR sourceFilename
, LPCSTR destFilename
,
1266 LPPROGRESS_ROUTINE progressRoutine
, LPVOID appData
,
1267 LPBOOL cancelFlagPointer
, DWORD copyFlags
)
1269 WCHAR
*sourceW
, *destW
;
1272 /* can't use the TEB buffer since we may have a callback routine */
1273 if (!(sourceW
= FILE_name_AtoW( sourceFilename
, TRUE
))) return FALSE
;
1274 if (!(destW
= FILE_name_AtoW( destFilename
, TRUE
)))
1276 HeapFree( GetProcessHeap(), 0, sourceW
);
1279 ret
= CopyFileExW(sourceW
, destW
, progressRoutine
, appData
,
1280 cancelFlagPointer
, copyFlags
);
1281 HeapFree( GetProcessHeap(), 0, sourceW
);
1282 HeapFree( GetProcessHeap(), 0, destW
);
1286 /**************************************************************************
1287 * MoveFileTransactedA (KERNEL32.@)
1289 BOOL WINAPI
MoveFileTransactedA(const char *source
, const char *dest
, LPPROGRESS_ROUTINE progress
, void *data
, DWORD flags
, HANDLE handle
)
1291 FIXME("(%s, %s, %p, %p, %d, %p)\n", debugstr_a(source
), debugstr_a(dest
), progress
, data
, flags
, handle
);
1292 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1296 /**************************************************************************
1297 * MoveFileTransactedW (KERNEL32.@)
1299 BOOL WINAPI
MoveFileTransactedW(const WCHAR
*source
, const WCHAR
*dest
, LPPROGRESS_ROUTINE progress
, void *data
, DWORD flags
, HANDLE handle
)
1301 FIXME("(%s, %s, %p, %p, %d, %p)\n", debugstr_w(source
), debugstr_w(dest
), progress
, data
, flags
, handle
);
1302 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1306 /**************************************************************************
1307 * MoveFileWithProgressW (KERNEL32.@)
1309 BOOL WINAPI
MoveFileWithProgressW( LPCWSTR source
, LPCWSTR dest
,
1310 LPPROGRESS_ROUTINE fnProgress
,
1311 LPVOID param
, DWORD flag
)
1313 FILE_BASIC_INFORMATION info
;
1314 UNICODE_STRING nt_name
;
1315 OBJECT_ATTRIBUTES attr
;
1318 HANDLE source_handle
= 0, dest_handle
= 0;
1319 ANSI_STRING source_unix
, dest_unix
;
1322 TRACE("(%s,%s,%p,%p,%04x)\n",
1323 debugstr_w(source
), debugstr_w(dest
), fnProgress
, param
, flag
);
1325 if (flag
& MOVEFILE_DELAY_UNTIL_REBOOT
)
1326 return add_boot_rename_entry( source
, dest
, flag
);
1329 return DeleteFileW( source
);
1331 /* check if we are allowed to rename the source */
1333 if (!RtlDosPathNameToNtPathName_U( source
, &nt_name
, NULL
, NULL
))
1335 SetLastError( ERROR_PATH_NOT_FOUND
);
1338 source_unix
.Buffer
= NULL
;
1339 dest_unix
.Buffer
= NULL
;
1340 attr
.Length
= sizeof(attr
);
1341 attr
.RootDirectory
= 0;
1342 attr
.Attributes
= OBJ_CASE_INSENSITIVE
;
1343 attr
.ObjectName
= &nt_name
;
1344 attr
.SecurityDescriptor
= NULL
;
1345 attr
.SecurityQualityOfService
= NULL
;
1347 status
= NtOpenFile( &source_handle
, DELETE
| SYNCHRONIZE
, &attr
, &io
,
1348 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
, FILE_SYNCHRONOUS_IO_NONALERT
);
1349 if (status
== STATUS_SUCCESS
)
1350 status
= wine_nt_to_unix_file_name( &nt_name
, &source_unix
, FILE_OPEN
, FALSE
);
1351 RtlFreeUnicodeString( &nt_name
);
1352 if (status
!= STATUS_SUCCESS
)
1354 SetLastError( RtlNtStatusToDosError(status
) );
1357 status
= NtQueryInformationFile( source_handle
, &io
, &info
, sizeof(info
), FileBasicInformation
);
1358 if (status
!= STATUS_SUCCESS
)
1360 SetLastError( RtlNtStatusToDosError(status
) );
1364 /* we must have write access to the destination, and it must */
1365 /* not exist except if MOVEFILE_REPLACE_EXISTING is set */
1367 if (!RtlDosPathNameToNtPathName_U( dest
, &nt_name
, NULL
, NULL
))
1369 SetLastError( ERROR_PATH_NOT_FOUND
);
1372 options
= FILE_NON_DIRECTORY_FILE
| FILE_SYNCHRONOUS_IO_NONALERT
;
1373 if (flag
& MOVEFILE_WRITE_THROUGH
)
1374 options
|= FILE_WRITE_THROUGH
;
1375 status
= NtOpenFile( &dest_handle
, GENERIC_READ
| GENERIC_WRITE
| SYNCHRONIZE
, &attr
, &io
,
1376 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
, options
);
1377 if (status
== STATUS_SUCCESS
) /* destination exists */
1379 if (!(flag
& MOVEFILE_REPLACE_EXISTING
))
1381 if (!is_same_file( source_handle
, dest_handle
))
1383 SetLastError( ERROR_ALREADY_EXISTS
);
1384 RtlFreeUnicodeString( &nt_name
);
1388 else if (info
.FileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) /* cannot replace directory */
1390 SetLastError( ERROR_ACCESS_DENIED
);
1394 NtClose( dest_handle
);
1397 else if (status
!= STATUS_OBJECT_NAME_NOT_FOUND
)
1399 SetLastError( RtlNtStatusToDosError(status
) );
1400 RtlFreeUnicodeString( &nt_name
);
1404 status
= wine_nt_to_unix_file_name( &nt_name
, &dest_unix
, FILE_OPEN_IF
, FALSE
);
1405 RtlFreeUnicodeString( &nt_name
);
1406 if (status
!= STATUS_SUCCESS
&& status
!= STATUS_NO_SUCH_FILE
)
1408 SetLastError( RtlNtStatusToDosError(status
) );
1412 /* now perform the rename */
1414 if (rename( source_unix
.Buffer
, dest_unix
.Buffer
) == -1)
1416 if (errno
== EXDEV
&& (flag
& MOVEFILE_COPY_ALLOWED
))
1418 NtClose( source_handle
);
1419 RtlFreeAnsiString( &source_unix
);
1420 RtlFreeAnsiString( &dest_unix
);
1421 if (!CopyFileExW( source
, dest
, fnProgress
, param
, NULL
,
1422 flag
& MOVEFILE_REPLACE_EXISTING
?
1423 0 : COPY_FILE_FAIL_IF_EXISTS
))
1425 return DeleteFileW( source
);
1428 /* if we created the destination, remove it */
1429 if (io
.Information
== FILE_CREATED
) unlink( dest_unix
.Buffer
);
1433 /* fixup executable permissions */
1435 if (is_executable( source
) != is_executable( dest
))
1438 if (stat( dest_unix
.Buffer
, &fstat
) != -1)
1440 if (is_executable( dest
))
1441 /* set executable bit where read bit is set */
1442 fstat
.st_mode
|= (fstat
.st_mode
& 0444) >> 2;
1444 fstat
.st_mode
&= ~0111;
1445 chmod( dest_unix
.Buffer
, fstat
.st_mode
);
1449 NtClose( source_handle
);
1450 RtlFreeAnsiString( &source_unix
);
1451 RtlFreeAnsiString( &dest_unix
);
1455 if (source_handle
) NtClose( source_handle
);
1456 if (dest_handle
) NtClose( dest_handle
);
1457 RtlFreeAnsiString( &source_unix
);
1458 RtlFreeAnsiString( &dest_unix
);
1462 /**************************************************************************
1463 * MoveFileWithProgressA (KERNEL32.@)
1465 BOOL WINAPI
MoveFileWithProgressA( LPCSTR source
, LPCSTR dest
,
1466 LPPROGRESS_ROUTINE fnProgress
,
1467 LPVOID param
, DWORD flag
)
1469 WCHAR
*sourceW
, *destW
;
1472 if (!(sourceW
= FILE_name_AtoW( source
, FALSE
))) return FALSE
;
1475 if (!(destW
= FILE_name_AtoW( dest
, TRUE
))) return FALSE
;
1480 ret
= MoveFileWithProgressW( sourceW
, destW
, fnProgress
, param
, flag
);
1481 HeapFree( GetProcessHeap(), 0, destW
);
1485 /**************************************************************************
1486 * MoveFileExW (KERNEL32.@)
1488 BOOL WINAPI
MoveFileExW( LPCWSTR source
, LPCWSTR dest
, DWORD flag
)
1490 return MoveFileWithProgressW( source
, dest
, NULL
, NULL
, flag
);
1493 /**************************************************************************
1494 * MoveFileExA (KERNEL32.@)
1496 BOOL WINAPI
MoveFileExA( LPCSTR source
, LPCSTR dest
, DWORD flag
)
1498 return MoveFileWithProgressA( source
, dest
, NULL
, NULL
, flag
);
1502 /**************************************************************************
1503 * MoveFileW (KERNEL32.@)
1505 * Move file or directory
1507 BOOL WINAPI
MoveFileW( LPCWSTR source
, LPCWSTR dest
)
1509 return MoveFileExW( source
, dest
, MOVEFILE_COPY_ALLOWED
);
1513 /**************************************************************************
1514 * MoveFileA (KERNEL32.@)
1516 BOOL WINAPI
MoveFileA( LPCSTR source
, LPCSTR dest
)
1518 return MoveFileExA( source
, dest
, MOVEFILE_COPY_ALLOWED
);
1522 /*************************************************************************
1523 * CreateHardLinkW (KERNEL32.@)
1525 BOOL WINAPI
CreateHardLinkW(LPCWSTR lpFileName
, LPCWSTR lpExistingFileName
,
1526 LPSECURITY_ATTRIBUTES lpSecurityAttributes
)
1529 UNICODE_STRING ntDest
, ntSource
;
1530 ANSI_STRING unixDest
, unixSource
;
1533 TRACE("(%s, %s, %p)\n", debugstr_w(lpFileName
),
1534 debugstr_w(lpExistingFileName
), lpSecurityAttributes
);
1536 ntDest
.Buffer
= ntSource
.Buffer
= NULL
;
1537 if (!RtlDosPathNameToNtPathName_U( lpFileName
, &ntDest
, NULL
, NULL
) ||
1538 !RtlDosPathNameToNtPathName_U( lpExistingFileName
, &ntSource
, NULL
, NULL
))
1540 SetLastError( ERROR_PATH_NOT_FOUND
);
1544 unixSource
.Buffer
= unixDest
.Buffer
= NULL
;
1545 status
= wine_nt_to_unix_file_name( &ntSource
, &unixSource
, FILE_OPEN
, FALSE
);
1548 status
= wine_nt_to_unix_file_name( &ntDest
, &unixDest
, FILE_CREATE
, FALSE
);
1549 if (!status
) /* destination must not exist */
1551 status
= STATUS_OBJECT_NAME_EXISTS
;
1552 } else if (status
== STATUS_NO_SUCH_FILE
)
1554 status
= STATUS_SUCCESS
;
1559 SetLastError( RtlNtStatusToDosError(status
) );
1560 else if (!link( unixSource
.Buffer
, unixDest
.Buffer
))
1562 TRACE("Hardlinked '%s' to '%s'\n", debugstr_a( unixDest
.Buffer
),
1563 debugstr_a( unixSource
.Buffer
));
1569 RtlFreeAnsiString( &unixSource
);
1570 RtlFreeAnsiString( &unixDest
);
1573 RtlFreeUnicodeString( &ntSource
);
1574 RtlFreeUnicodeString( &ntDest
);
1579 /*************************************************************************
1580 * CreateHardLinkA (KERNEL32.@)
1582 BOOL WINAPI
CreateHardLinkA(LPCSTR lpFileName
, LPCSTR lpExistingFileName
,
1583 LPSECURITY_ATTRIBUTES lpSecurityAttributes
)
1585 WCHAR
*sourceW
, *destW
;
1588 if (!(sourceW
= FILE_name_AtoW( lpExistingFileName
, TRUE
)))
1592 if (!(destW
= FILE_name_AtoW( lpFileName
, TRUE
)))
1594 HeapFree( GetProcessHeap(), 0, sourceW
);
1598 res
= CreateHardLinkW( destW
, sourceW
, lpSecurityAttributes
);
1600 HeapFree( GetProcessHeap(), 0, sourceW
);
1601 HeapFree( GetProcessHeap(), 0, destW
);
1607 /***********************************************************************
1608 * CreateDirectoryW (KERNEL32.@)
1612 * ERROR_DISK_FULL: on full disk
1613 * ERROR_ALREADY_EXISTS: if directory name exists (even as file)
1614 * ERROR_ACCESS_DENIED: on permission problems
1615 * ERROR_FILENAME_EXCED_RANGE: too long filename(s)
1617 BOOL WINAPI
CreateDirectoryW( LPCWSTR path
, LPSECURITY_ATTRIBUTES sa
)
1619 OBJECT_ATTRIBUTES attr
;
1620 UNICODE_STRING nt_name
;
1626 TRACE( "%s\n", debugstr_w(path
) );
1628 if (!RtlDosPathNameToNtPathName_U( path
, &nt_name
, NULL
, NULL
))
1630 SetLastError( ERROR_PATH_NOT_FOUND
);
1633 attr
.Length
= sizeof(attr
);
1634 attr
.RootDirectory
= 0;
1635 attr
.Attributes
= OBJ_CASE_INSENSITIVE
;
1636 attr
.ObjectName
= &nt_name
;
1637 attr
.SecurityDescriptor
= sa
? sa
->lpSecurityDescriptor
: NULL
;
1638 attr
.SecurityQualityOfService
= NULL
;
1640 status
= NtCreateFile( &handle
, GENERIC_READ
| SYNCHRONIZE
, &attr
, &io
, NULL
,
1641 FILE_ATTRIBUTE_NORMAL
, FILE_SHARE_READ
, FILE_CREATE
,
1642 FILE_DIRECTORY_FILE
| FILE_SYNCHRONOUS_IO_NONALERT
, NULL
, 0 );
1644 if (status
== STATUS_SUCCESS
)
1649 else SetLastError( RtlNtStatusToDosError(status
) );
1651 RtlFreeUnicodeString( &nt_name
);
1656 /***********************************************************************
1657 * CreateDirectoryA (KERNEL32.@)
1659 BOOL WINAPI
CreateDirectoryA( LPCSTR path
, LPSECURITY_ATTRIBUTES sa
)
1663 if (!(pathW
= FILE_name_AtoW( path
, FALSE
))) return FALSE
;
1664 return CreateDirectoryW( pathW
, sa
);
1668 /***********************************************************************
1669 * CreateDirectoryExA (KERNEL32.@)
1671 BOOL WINAPI
CreateDirectoryExA( LPCSTR
template, LPCSTR path
, LPSECURITY_ATTRIBUTES sa
)
1673 WCHAR
*pathW
, *templateW
= NULL
;
1676 if (!(pathW
= FILE_name_AtoW( path
, FALSE
))) return FALSE
;
1677 if (template && !(templateW
= FILE_name_AtoW( template, TRUE
))) return FALSE
;
1679 ret
= CreateDirectoryExW( templateW
, pathW
, sa
);
1680 HeapFree( GetProcessHeap(), 0, templateW
);
1685 /***********************************************************************
1686 * CreateDirectoryExW (KERNEL32.@)
1688 BOOL WINAPI
CreateDirectoryExW( LPCWSTR
template, LPCWSTR path
, LPSECURITY_ATTRIBUTES sa
)
1690 return CreateDirectoryW( path
, sa
);
1694 /***********************************************************************
1695 * RemoveDirectoryW (KERNEL32.@)
1697 BOOL WINAPI
RemoveDirectoryW( LPCWSTR path
)
1699 OBJECT_ATTRIBUTES attr
;
1700 UNICODE_STRING nt_name
;
1701 ANSI_STRING unix_name
;
1707 TRACE( "%s\n", debugstr_w(path
) );
1709 if (!RtlDosPathNameToNtPathName_U( path
, &nt_name
, NULL
, NULL
))
1711 SetLastError( ERROR_PATH_NOT_FOUND
);
1714 attr
.Length
= sizeof(attr
);
1715 attr
.RootDirectory
= 0;
1716 attr
.Attributes
= OBJ_CASE_INSENSITIVE
;
1717 attr
.ObjectName
= &nt_name
;
1718 attr
.SecurityDescriptor
= NULL
;
1719 attr
.SecurityQualityOfService
= NULL
;
1721 status
= NtOpenFile( &handle
, DELETE
| SYNCHRONIZE
, &attr
, &io
,
1722 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
1723 FILE_DIRECTORY_FILE
| FILE_SYNCHRONOUS_IO_NONALERT
);
1724 if (status
!= STATUS_SUCCESS
)
1726 SetLastError( RtlNtStatusToDosError(status
) );
1727 RtlFreeUnicodeString( &nt_name
);
1731 status
= wine_nt_to_unix_file_name( &nt_name
, &unix_name
, FILE_OPEN
, FALSE
);
1732 RtlFreeUnicodeString( &nt_name
);
1733 if (status
!= STATUS_SUCCESS
)
1735 SetLastError( RtlNtStatusToDosError(status
) );
1740 if (!(ret
= (rmdir( unix_name
.Buffer
) != -1))) FILE_SetDosError();
1741 RtlFreeAnsiString( &unix_name
);
1747 /***********************************************************************
1748 * RemoveDirectoryA (KERNEL32.@)
1750 BOOL WINAPI
RemoveDirectoryA( LPCSTR path
)
1754 if (!(pathW
= FILE_name_AtoW( path
, FALSE
))) return FALSE
;
1755 return RemoveDirectoryW( pathW
);
1759 /***********************************************************************
1760 * GetCurrentDirectoryW (KERNEL32.@)
1762 UINT WINAPI
GetCurrentDirectoryW( UINT buflen
, LPWSTR buf
)
1764 return RtlGetCurrentDirectory_U( buflen
* sizeof(WCHAR
), buf
) / sizeof(WCHAR
);
1768 /***********************************************************************
1769 * GetCurrentDirectoryA (KERNEL32.@)
1771 UINT WINAPI
GetCurrentDirectoryA( UINT buflen
, LPSTR buf
)
1773 WCHAR bufferW
[MAX_PATH
];
1776 if (buflen
&& buf
&& ((ULONG_PTR
)buf
>> 16) == 0)
1778 /* Win9x catches access violations here, returning zero.
1779 * This behaviour resulted in some people not noticing
1780 * that they got the argument order wrong. So let's be
1781 * nice and fail gracefully if buf is invalid and looks
1782 * more like a buflen. */
1783 SetLastError(ERROR_INVALID_PARAMETER
);
1787 ret
= RtlGetCurrentDirectory_U( sizeof(bufferW
), bufferW
);
1789 if (ret
> sizeof(bufferW
))
1791 SetLastError(ERROR_FILENAME_EXCED_RANGE
);
1794 return copy_filename_WtoA( bufferW
, buf
, buflen
);
1798 /***********************************************************************
1799 * SetCurrentDirectoryW (KERNEL32.@)
1801 BOOL WINAPI
SetCurrentDirectoryW( LPCWSTR dir
)
1803 UNICODE_STRING dirW
;
1806 RtlInitUnicodeString( &dirW
, dir
);
1807 status
= RtlSetCurrentDirectory_U( &dirW
);
1808 if (status
!= STATUS_SUCCESS
) SetLastError( RtlNtStatusToDosError(status
) );
1813 /***********************************************************************
1814 * SetCurrentDirectoryA (KERNEL32.@)
1816 BOOL WINAPI
SetCurrentDirectoryA( LPCSTR dir
)
1819 UNICODE_STRING strW
;
1822 if (!(dirW
= FILE_name_AtoW( dir
, FALSE
))) return FALSE
;
1823 RtlInitUnicodeString( &strW
, dirW
);
1824 status
= RtlSetCurrentDirectory_U( &strW
);
1825 if (status
!= STATUS_SUCCESS
) SetLastError( RtlNtStatusToDosError(status
) );
1830 /***********************************************************************
1831 * GetWindowsDirectoryW (KERNEL32.@)
1833 * See comment for GetWindowsDirectoryA.
1835 UINT WINAPI
GetWindowsDirectoryW( LPWSTR path
, UINT count
)
1837 UINT len
= strlenW( DIR_Windows
) + 1;
1838 if (path
&& count
>= len
)
1840 strcpyW( path
, DIR_Windows
);
1847 /***********************************************************************
1848 * GetWindowsDirectoryA (KERNEL32.@)
1851 * If buffer is large enough to hold full path and terminating '\0' character
1852 * function copies path to buffer and returns length of the path without '\0'.
1853 * Otherwise function returns required size including '\0' character and
1854 * does not touch the buffer.
1856 UINT WINAPI
GetWindowsDirectoryA( LPSTR path
, UINT count
)
1858 return copy_filename_WtoA( DIR_Windows
, path
, count
);
1862 /***********************************************************************
1863 * GetSystemWindowsDirectoryA (KERNEL32.@) W2K, TS4.0SP4
1865 UINT WINAPI
GetSystemWindowsDirectoryA( LPSTR path
, UINT count
)
1867 return GetWindowsDirectoryA( path
, count
);
1871 /***********************************************************************
1872 * GetSystemWindowsDirectoryW (KERNEL32.@) W2K, TS4.0SP4
1874 UINT WINAPI
GetSystemWindowsDirectoryW( LPWSTR path
, UINT count
)
1876 return GetWindowsDirectoryW( path
, count
);
1880 /***********************************************************************
1881 * GetSystemDirectoryW (KERNEL32.@)
1883 * See comment for GetWindowsDirectoryA.
1885 UINT WINAPI
GetSystemDirectoryW( LPWSTR path
, UINT count
)
1887 UINT len
= strlenW( DIR_System
) + 1;
1888 if (path
&& count
>= len
)
1890 strcpyW( path
, DIR_System
);
1897 /***********************************************************************
1898 * GetSystemDirectoryA (KERNEL32.@)
1900 * See comment for GetWindowsDirectoryA.
1902 UINT WINAPI
GetSystemDirectoryA( LPSTR path
, UINT count
)
1904 return copy_filename_WtoA( DIR_System
, path
, count
);
1908 /***********************************************************************
1909 * GetSystemWow64DirectoryW (KERNEL32.@)
1912 * - On Win32 we should return ERROR_CALL_NOT_IMPLEMENTED
1913 * - On Win64 we should return the SysWow64 (system64) directory
1915 UINT WINAPI
GetSystemWow64DirectoryW( LPWSTR path
, UINT count
)
1921 SetLastError( ERROR_CALL_NOT_IMPLEMENTED
);
1924 len
= strlenW( DIR_SysWow64
) + 1;
1925 if (path
&& count
>= len
)
1927 strcpyW( path
, DIR_SysWow64
);
1934 /***********************************************************************
1935 * GetSystemWow64DirectoryA (KERNEL32.@)
1937 * See comment for GetWindowsWow64DirectoryW.
1939 UINT WINAPI
GetSystemWow64DirectoryA( LPSTR path
, UINT count
)
1943 SetLastError( ERROR_CALL_NOT_IMPLEMENTED
);
1946 return copy_filename_WtoA( DIR_SysWow64
, path
, count
);
1950 /***********************************************************************
1951 * Wow64EnableWow64FsRedirection (KERNEL32.@)
1953 BOOLEAN WINAPI
Wow64EnableWow64FsRedirection( BOOLEAN enable
)
1955 NTSTATUS status
= RtlWow64EnableFsRedirection( enable
);
1956 if (status
) SetLastError( RtlNtStatusToDosError(status
) );
1961 /***********************************************************************
1962 * Wow64DisableWow64FsRedirection (KERNEL32.@)
1964 BOOL WINAPI
Wow64DisableWow64FsRedirection( PVOID
*old_value
)
1966 NTSTATUS status
= RtlWow64EnableFsRedirectionEx( TRUE
, (ULONG
*)old_value
);
1967 if (status
) SetLastError( RtlNtStatusToDosError(status
) );
1972 /***********************************************************************
1973 * Wow64RevertWow64FsRedirection (KERNEL32.@)
1975 BOOL WINAPI
Wow64RevertWow64FsRedirection( PVOID old_value
)
1977 NTSTATUS status
= RtlWow64EnableFsRedirection( !old_value
);
1978 if (status
) SetLastError( RtlNtStatusToDosError(status
) );
1983 /***********************************************************************
1984 * NeedCurrentDirectoryForExePathW (KERNEL32.@)
1986 BOOL WINAPI
NeedCurrentDirectoryForExePathW( LPCWSTR name
)
1988 static const WCHAR env_name
[] = {'N','o','D','e','f','a','u','l','t',
1989 'C','u','r','r','e','n','t',
1990 'D','i','r','e','c','t','o','r','y',
1991 'I','n','E','x','e','P','a','t','h',0};
1994 /* MSDN mentions some 'registry location'. We do not use registry. */
1995 FIXME("(%s): partial stub\n", debugstr_w(name
));
1997 if (strchrW(name
, '\\'))
2000 /* Check the existence of the variable, not value */
2001 if (!GetEnvironmentVariableW( env_name
, &env_val
, 1 ))
2008 /***********************************************************************
2009 * NeedCurrentDirectoryForExePathA (KERNEL32.@)
2011 BOOL WINAPI
NeedCurrentDirectoryForExePathA( LPCSTR name
)
2015 if (!(nameW
= FILE_name_AtoW( name
, FALSE
))) return TRUE
;
2016 return NeedCurrentDirectoryForExePathW( nameW
);
2020 /***********************************************************************
2021 * wine_get_unix_file_name (KERNEL32.@) Not a Windows API
2023 * Return the full Unix file name for a given path.
2024 * Returned buffer must be freed by caller.
2026 char * CDECL
wine_get_unix_file_name( LPCWSTR dosW
)
2028 UNICODE_STRING nt_name
;
2029 ANSI_STRING unix_name
;
2032 if (!RtlDosPathNameToNtPathName_U( dosW
, &nt_name
, NULL
, NULL
)) return NULL
;
2033 status
= wine_nt_to_unix_file_name( &nt_name
, &unix_name
, FILE_OPEN_IF
, FALSE
);
2034 RtlFreeUnicodeString( &nt_name
);
2035 if (status
&& status
!= STATUS_NO_SUCH_FILE
)
2037 SetLastError( RtlNtStatusToDosError( status
) );
2040 return unix_name
.Buffer
;
2044 /***********************************************************************
2045 * wine_get_dos_file_name (KERNEL32.@) Not a Windows API
2047 * Return the full DOS file name for a given Unix path.
2048 * Returned buffer must be freed by caller.
2050 WCHAR
* CDECL
wine_get_dos_file_name( LPCSTR str
)
2052 UNICODE_STRING nt_name
;
2053 ANSI_STRING unix_name
;
2057 RtlInitAnsiString( &unix_name
, str
);
2058 status
= wine_unix_to_nt_file_name( &unix_name
, &nt_name
);
2061 SetLastError( RtlNtStatusToDosError( status
) );
2064 if (nt_name
.Buffer
[5] == ':')
2066 /* get rid of the \??\ prefix */
2067 /* FIXME: should implement RtlNtPathNameToDosPathName and use that instead */
2068 len
= nt_name
.Length
- 4 * sizeof(WCHAR
);
2069 memmove( nt_name
.Buffer
, nt_name
.Buffer
+ 4, len
);
2070 nt_name
.Buffer
[len
/ sizeof(WCHAR
)] = 0;
2073 nt_name
.Buffer
[1] = '\\';
2074 return nt_name
.Buffer
;
2077 /*************************************************************************
2078 * CreateSymbolicLinkW (KERNEL32.@)
2080 BOOLEAN WINAPI
CreateSymbolicLinkW(LPCWSTR link
, LPCWSTR target
, DWORD flags
)
2082 FIXME("(%s %s %d): stub\n", debugstr_w(link
), debugstr_w(target
), flags
);
2086 /*************************************************************************
2087 * CreateSymbolicLinkA (KERNEL32.@)
2089 BOOLEAN WINAPI
CreateSymbolicLinkA(LPCSTR link
, LPCSTR target
, DWORD flags
)
2091 FIXME("(%s %s %d): stub\n", debugstr_a(link
), debugstr_a(target
), flags
);
2095 /*************************************************************************
2096 * CreateHardLinkTransactedA (KERNEL32.@)
2098 BOOL WINAPI
CreateHardLinkTransactedA(LPCSTR link
, LPCSTR target
, LPSECURITY_ATTRIBUTES sa
, HANDLE transaction
)
2100 FIXME("(%s %s %p %p): stub\n", debugstr_a(link
), debugstr_a(target
), sa
, transaction
);
2101 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
2105 /*************************************************************************
2106 * CreateHardLinkTransactedW (KERNEL32.@)
2108 BOOL WINAPI
CreateHardLinkTransactedW(LPCWSTR link
, LPCWSTR target
, LPSECURITY_ATTRIBUTES sa
, HANDLE transaction
)
2110 FIXME("(%s %s %p %p): stub\n", debugstr_w(link
), debugstr_w(target
), sa
, transaction
);
2111 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
2115 /*************************************************************************
2116 * CheckNameLegalDOS8Dot3A (KERNEL32.@)
2118 BOOL WINAPI
CheckNameLegalDOS8Dot3A(const char *name
, char *oemname
, DWORD oemname_len
,
2119 BOOL
*contains_spaces
, BOOL
*is_legal
)
2123 TRACE("(%s %p %u %p %p)\n", name
, oemname
,
2124 oemname_len
, contains_spaces
, is_legal
);
2126 if (!name
|| !is_legal
)
2129 if (!(nameW
= FILE_name_AtoW( name
, FALSE
))) return FALSE
;
2131 return CheckNameLegalDOS8Dot3W( nameW
, oemname
, oemname_len
, contains_spaces
, is_legal
);
2134 /*************************************************************************
2135 * CheckNameLegalDOS8Dot3W (KERNEL32.@)
2137 BOOL WINAPI
CheckNameLegalDOS8Dot3W(const WCHAR
*name
, char *oemname
, DWORD oemname_len
,
2138 BOOL
*contains_spaces_ret
, BOOL
*is_legal
)
2141 UNICODE_STRING nameW
;
2142 BOOLEAN contains_spaces
;
2144 TRACE("(%s %p %u %p %p)\n", wine_dbgstr_w(name
), oemname
,
2145 oemname_len
, contains_spaces_ret
, is_legal
);
2147 if (!name
|| !is_legal
)
2150 RtlInitUnicodeString( &nameW
, name
);
2153 oem_str
.Length
= oemname_len
;
2154 oem_str
.MaximumLength
= oemname_len
;
2155 oem_str
.Buffer
= oemname
;
2158 *is_legal
= RtlIsNameLegalDOS8Dot3( &nameW
, oemname
? &oem_str
: NULL
, &contains_spaces
);
2159 if (contains_spaces_ret
) *contains_spaces_ret
= contains_spaces
;
2164 /*************************************************************************
2165 * SetSearchPathMode (KERNEL32.@)
2167 BOOL WINAPI
SetSearchPathMode( DWORD flags
)
2173 case BASE_SEARCH_PATH_ENABLE_SAFE_SEARCHMODE
:
2176 case BASE_SEARCH_PATH_DISABLE_SAFE_SEARCHMODE
:
2179 case BASE_SEARCH_PATH_ENABLE_SAFE_SEARCHMODE
| BASE_SEARCH_PATH_PERMANENT
:
2180 InterlockedExchange( &path_safe_mode
, 2 );
2183 SetLastError( ERROR_INVALID_PARAMETER
);
2189 int prev
= path_safe_mode
;
2190 if (prev
== 2) break; /* permanently set */
2191 if (InterlockedCompareExchange( &path_safe_mode
, val
, prev
) == prev
) return TRUE
;
2193 SetLastError( ERROR_ACCESS_DENIED
);