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 /* check if a file name is for an executable file (.exe or .com) */
47 static inline BOOL
is_executable( const WCHAR
*name
)
49 static const WCHAR exeW
[] = {'.','e','x','e',0};
50 static const WCHAR comW
[] = {'.','c','o','m',0};
51 int len
= strlenW(name
);
53 if (len
< 4) return FALSE
;
54 return (!strcmpiW( name
+ len
- 4, exeW
) || !strcmpiW( name
+ len
- 4, comW
));
57 /***********************************************************************
60 * copy a file name back to OEM/Ansi, but only if the buffer is large enough
62 static DWORD
copy_filename_WtoA( LPCWSTR nameW
, LPSTR buffer
, DWORD len
)
66 BOOL is_ansi
= AreFileApisANSI();
68 RtlInitUnicodeString( &strW
, nameW
);
70 ret
= is_ansi
? RtlUnicodeStringToAnsiSize(&strW
) : RtlUnicodeStringToOemSize(&strW
);
71 if (buffer
&& ret
<= len
)
76 str
.MaximumLength
= min( len
, UNICODE_STRING_MAX_CHARS
);
78 RtlUnicodeStringToAnsiString( &str
, &strW
, FALSE
);
80 RtlUnicodeStringToOemString( &str
, &strW
, FALSE
);
81 ret
= str
.Length
; /* length without terminating 0 */
86 /***********************************************************************
87 * add_boot_rename_entry
89 * Adds an entry to the registry that is loaded when windows boots and
90 * checks if there are some files to be removed or renamed/moved.
91 * <fn1> has to be valid and <fn2> may be NULL. If both pointers are
92 * non-NULL then the file is moved, otherwise it is deleted. The
93 * entry of the registry key is always appended with two zero
94 * terminated strings. If <fn2> is NULL then the second entry is
95 * simply a single 0-byte. Otherwise the second filename goes
96 * there. The entries are prepended with \??\ before the path and the
97 * second filename gets also a '!' as the first character if
98 * MOVEFILE_REPLACE_EXISTING is set. After the final string another
99 * 0-byte follows to indicate the end of the strings.
101 * \??\D:\test\file1[0]
102 * !\??\D:\test\file1_renamed[0]
103 * \??\D:\Test|delete[0]
104 * [0] <- file is to be deleted, second string empty
105 * \??\D:\test\file2[0]
106 * !\??\D:\test\file2_renamed[0]
107 * [0] <- indicates end of strings
110 * \??\D:\test\file1[0]
111 * !\??\D:\test\file1_renamed[0]
112 * \??\D:\Test|delete[0]
113 * [0] <- file is to be deleted, second string empty
114 * [0] <- indicates end of strings
117 static BOOL
add_boot_rename_entry( LPCWSTR source
, LPCWSTR dest
, DWORD flags
)
119 static const WCHAR ValueName
[] = {'P','e','n','d','i','n','g',
120 'F','i','l','e','R','e','n','a','m','e',
121 'O','p','e','r','a','t','i','o','n','s',0};
122 static const WCHAR SessionW
[] = {'\\','R','e','g','i','s','t','r','y','\\',
123 'M','a','c','h','i','n','e','\\',
124 'S','y','s','t','e','m','\\',
125 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
126 'C','o','n','t','r','o','l','\\',
127 'S','e','s','s','i','o','n',' ','M','a','n','a','g','e','r',0};
128 static const int info_size
= FIELD_OFFSET( KEY_VALUE_PARTIAL_INFORMATION
, Data
);
130 OBJECT_ATTRIBUTES attr
;
131 UNICODE_STRING nameW
, source_name
, dest_name
;
132 KEY_VALUE_PARTIAL_INFORMATION
*info
;
140 if (!RtlDosPathNameToNtPathName_U( source
, &source_name
, NULL
, NULL
))
142 SetLastError( ERROR_PATH_NOT_FOUND
);
145 dest_name
.Buffer
= NULL
;
146 if (dest
&& !RtlDosPathNameToNtPathName_U( dest
, &dest_name
, NULL
, NULL
))
148 RtlFreeUnicodeString( &source_name
);
149 SetLastError( ERROR_PATH_NOT_FOUND
);
153 attr
.Length
= sizeof(attr
);
154 attr
.RootDirectory
= 0;
155 attr
.ObjectName
= &nameW
;
157 attr
.SecurityDescriptor
= NULL
;
158 attr
.SecurityQualityOfService
= NULL
;
159 RtlInitUnicodeString( &nameW
, SessionW
);
161 if (NtCreateKey( &Reboot
, KEY_ALL_ACCESS
, &attr
, 0, NULL
, 0, NULL
) != STATUS_SUCCESS
)
163 WARN("Error creating key for reboot management [%s]\n",
164 "SYSTEM\\CurrentControlSet\\Control\\Session Manager");
165 RtlFreeUnicodeString( &source_name
);
166 RtlFreeUnicodeString( &dest_name
);
170 len1
= source_name
.Length
+ sizeof(WCHAR
);
173 len2
= dest_name
.Length
+ sizeof(WCHAR
);
174 if (flags
& MOVEFILE_REPLACE_EXISTING
)
175 len2
+= sizeof(WCHAR
); /* Plus 1 because of the leading '!' */
177 else len2
= sizeof(WCHAR
); /* minimum is the 0 characters for the empty second string */
179 RtlInitUnicodeString( &nameW
, ValueName
);
181 /* First we check if the key exists and if so how many bytes it already contains. */
182 if (NtQueryValueKey( Reboot
, &nameW
, KeyValuePartialInformation
,
183 NULL
, 0, &DataSize
) == STATUS_BUFFER_TOO_SMALL
)
185 if (!(Buffer
= HeapAlloc( GetProcessHeap(), 0, DataSize
+ len1
+ len2
+ sizeof(WCHAR
) )))
187 if (NtQueryValueKey( Reboot
, &nameW
, KeyValuePartialInformation
,
188 Buffer
, DataSize
, &DataSize
)) goto Quit
;
189 info
= (KEY_VALUE_PARTIAL_INFORMATION
*)Buffer
;
190 if (info
->Type
!= REG_MULTI_SZ
) goto Quit
;
191 if (DataSize
> sizeof(info
)) DataSize
-= sizeof(WCHAR
); /* remove terminating null (will be added back later) */
195 DataSize
= info_size
;
196 if (!(Buffer
= HeapAlloc( GetProcessHeap(), 0, DataSize
+ len1
+ len2
+ sizeof(WCHAR
) )))
200 memcpy( Buffer
+ DataSize
, source_name
.Buffer
, len1
);
202 p
= (WCHAR
*)(Buffer
+ DataSize
);
205 if (flags
& MOVEFILE_REPLACE_EXISTING
)
207 memcpy( p
, dest_name
.Buffer
, len2
);
213 DataSize
+= sizeof(WCHAR
);
217 p
= (WCHAR
*)(Buffer
+ DataSize
);
219 DataSize
+= sizeof(WCHAR
);
221 rc
= !NtSetValueKey(Reboot
, &nameW
, 0, REG_MULTI_SZ
, Buffer
+ info_size
, DataSize
- info_size
);
224 RtlFreeUnicodeString( &source_name
);
225 RtlFreeUnicodeString( &dest_name
);
226 if (Reboot
) NtClose(Reboot
);
227 HeapFree( GetProcessHeap(), 0, Buffer
);
233 /***********************************************************************
234 * GetShortPathNameA (KERNEL32.@)
236 DWORD WINAPI
GetShortPathNameA( LPCSTR longpath
, LPSTR shortpath
, DWORD shortlen
)
239 WCHAR shortpathW
[MAX_PATH
];
242 TRACE("%s\n", debugstr_a(longpath
));
244 if (!(longpathW
= FILE_name_AtoW( longpath
, FALSE
))) return 0;
246 ret
= GetShortPathNameW(longpathW
, shortpathW
, MAX_PATH
);
251 SetLastError(ERROR_FILENAME_EXCED_RANGE
);
254 return copy_filename_WtoA( shortpathW
, shortpath
, shortlen
);
258 static BOOL
is_same_file(HANDLE h1
, HANDLE h2
)
262 if (wine_server_handle_to_fd(h1
, 0, &fd1
, NULL
) == STATUS_SUCCESS
)
265 if (wine_server_handle_to_fd(h2
, 0, &fd2
, NULL
) == STATUS_SUCCESS
)
267 struct stat stat1
, stat2
;
268 if (fstat(fd1
, &stat1
) == 0 && fstat(fd2
, &stat2
) == 0)
269 ret
= (stat1
.st_dev
== stat2
.st_dev
&& stat1
.st_ino
== stat2
.st_ino
);
270 wine_server_release_fd(h2
, fd2
);
272 wine_server_release_fd(h1
, fd1
);
277 /**************************************************************************
278 * CopyFileW (KERNEL32.@)
280 BOOL WINAPI
CopyFileW( LPCWSTR source
, LPCWSTR dest
, BOOL fail_if_exists
)
282 return CopyFileExW( source
, dest
, NULL
, NULL
, NULL
,
283 fail_if_exists
? COPY_FILE_FAIL_IF_EXISTS
: 0 );
287 /**************************************************************************
288 * CopyFileA (KERNEL32.@)
290 BOOL WINAPI
CopyFileA( LPCSTR source
, LPCSTR dest
, BOOL fail_if_exists
)
292 WCHAR
*sourceW
, *destW
;
295 if (!(sourceW
= FILE_name_AtoW( source
, FALSE
))) return FALSE
;
296 if (!(destW
= FILE_name_AtoW( dest
, TRUE
))) return FALSE
;
298 ret
= CopyFileW( sourceW
, destW
, fail_if_exists
);
300 HeapFree( GetProcessHeap(), 0, destW
);
305 /**************************************************************************
306 * CopyFileExW (KERNEL32.@)
308 BOOL WINAPI
CopyFileExW(LPCWSTR source
, LPCWSTR dest
,
309 LPPROGRESS_ROUTINE progress
, LPVOID param
,
310 LPBOOL cancel_ptr
, DWORD flags
)
312 static const int buffer_size
= 65536;
314 BY_HANDLE_FILE_INFORMATION info
;
319 if (!source
|| !dest
)
321 SetLastError(ERROR_INVALID_PARAMETER
);
324 if (!(buffer
= HeapAlloc( GetProcessHeap(), 0, buffer_size
)))
326 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
330 TRACE("%s -> %s, %x\n", debugstr_w(source
), debugstr_w(dest
), flags
);
332 if ((h1
= CreateFileW(source
, GENERIC_READ
,
333 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
334 NULL
, OPEN_EXISTING
, 0, 0)) == INVALID_HANDLE_VALUE
)
336 WARN("Unable to open source %s\n", debugstr_w(source
));
337 HeapFree( GetProcessHeap(), 0, buffer
);
341 if (!GetFileInformationByHandle( h1
, &info
))
343 WARN("GetFileInformationByHandle returned error for %s\n", debugstr_w(source
));
344 HeapFree( GetProcessHeap(), 0, buffer
);
349 if (!(flags
& COPY_FILE_FAIL_IF_EXISTS
))
351 BOOL same_file
= FALSE
;
352 h2
= CreateFileW( dest
, 0, FILE_SHARE_READ
| FILE_SHARE_WRITE
, NULL
,
353 OPEN_EXISTING
, 0, 0);
354 if (h2
!= INVALID_HANDLE_VALUE
)
356 same_file
= is_same_file( h1
, h2
);
361 HeapFree( GetProcessHeap(), 0, buffer
);
363 SetLastError( ERROR_SHARING_VIOLATION
);
368 if ((h2
= CreateFileW( dest
, GENERIC_WRITE
, FILE_SHARE_READ
| FILE_SHARE_WRITE
, NULL
,
369 (flags
& COPY_FILE_FAIL_IF_EXISTS
) ? CREATE_NEW
: CREATE_ALWAYS
,
370 info
.dwFileAttributes
, h1
)) == INVALID_HANDLE_VALUE
)
372 WARN("Unable to open dest %s\n", debugstr_w(dest
));
373 HeapFree( GetProcessHeap(), 0, buffer
);
378 while (ReadFile( h1
, buffer
, buffer_size
, &count
, NULL
) && count
)
384 if (!WriteFile( h2
, p
, count
, &res
, NULL
) || !res
) goto done
;
391 /* Maintain the timestamp of source file to destination file */
392 SetFileTime(h2
, NULL
, NULL
, &info
.ftLastWriteTime
);
393 HeapFree( GetProcessHeap(), 0, buffer
);
400 /**************************************************************************
401 * CopyFileExA (KERNEL32.@)
403 BOOL WINAPI
CopyFileExA(LPCSTR sourceFilename
, LPCSTR destFilename
,
404 LPPROGRESS_ROUTINE progressRoutine
, LPVOID appData
,
405 LPBOOL cancelFlagPointer
, DWORD copyFlags
)
407 WCHAR
*sourceW
, *destW
;
410 /* can't use the TEB buffer since we may have a callback routine */
411 if (!(sourceW
= FILE_name_AtoW( sourceFilename
, TRUE
))) return FALSE
;
412 if (!(destW
= FILE_name_AtoW( destFilename
, TRUE
)))
414 HeapFree( GetProcessHeap(), 0, sourceW
);
417 ret
= CopyFileExW(sourceW
, destW
, progressRoutine
, appData
,
418 cancelFlagPointer
, copyFlags
);
419 HeapFree( GetProcessHeap(), 0, sourceW
);
420 HeapFree( GetProcessHeap(), 0, destW
);
424 /**************************************************************************
425 * MoveFileTransactedA (KERNEL32.@)
427 BOOL WINAPI
MoveFileTransactedA(const char *source
, const char *dest
, LPPROGRESS_ROUTINE progress
, void *data
, DWORD flags
, HANDLE handle
)
429 FIXME("(%s, %s, %p, %p, %d, %p)\n", debugstr_a(source
), debugstr_a(dest
), progress
, data
, flags
, handle
);
430 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
434 /**************************************************************************
435 * MoveFileTransactedW (KERNEL32.@)
437 BOOL WINAPI
MoveFileTransactedW(const WCHAR
*source
, const WCHAR
*dest
, LPPROGRESS_ROUTINE progress
, void *data
, DWORD flags
, HANDLE handle
)
439 FIXME("(%s, %s, %p, %p, %d, %p)\n", debugstr_w(source
), debugstr_w(dest
), progress
, data
, flags
, handle
);
440 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
444 /**************************************************************************
445 * MoveFileWithProgressW (KERNEL32.@)
447 BOOL WINAPI
MoveFileWithProgressW( LPCWSTR source
, LPCWSTR dest
,
448 LPPROGRESS_ROUTINE fnProgress
,
449 LPVOID param
, DWORD flag
)
451 FILE_RENAME_INFORMATION
*rename_info
;
452 FILE_BASIC_INFORMATION info
;
453 UNICODE_STRING nt_name
;
454 OBJECT_ATTRIBUTES attr
;
457 HANDLE source_handle
= 0;
460 TRACE("(%s,%s,%p,%p,%04x)\n",
461 debugstr_w(source
), debugstr_w(dest
), fnProgress
, param
, flag
);
463 if (flag
& MOVEFILE_DELAY_UNTIL_REBOOT
)
464 return add_boot_rename_entry( source
, dest
, flag
);
467 return DeleteFileW( source
);
469 /* check if we are allowed to rename the source */
471 if (!RtlDosPathNameToNtPathName_U( source
, &nt_name
, NULL
, NULL
))
473 SetLastError( ERROR_PATH_NOT_FOUND
);
476 attr
.Length
= sizeof(attr
);
477 attr
.RootDirectory
= 0;
478 attr
.Attributes
= OBJ_CASE_INSENSITIVE
;
479 attr
.ObjectName
= &nt_name
;
480 attr
.SecurityDescriptor
= NULL
;
481 attr
.SecurityQualityOfService
= NULL
;
483 status
= NtOpenFile( &source_handle
, DELETE
| SYNCHRONIZE
, &attr
, &io
,
484 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
, FILE_SYNCHRONOUS_IO_NONALERT
);
485 RtlFreeUnicodeString( &nt_name
);
486 if (status
!= STATUS_SUCCESS
)
488 SetLastError( RtlNtStatusToDosError(status
) );
491 status
= NtQueryInformationFile( source_handle
, &io
, &info
, sizeof(info
), FileBasicInformation
);
492 if (status
!= STATUS_SUCCESS
)
494 SetLastError( RtlNtStatusToDosError(status
) );
498 if (!RtlDosPathNameToNtPathName_U( dest
, &nt_name
, NULL
, NULL
))
500 SetLastError( ERROR_PATH_NOT_FOUND
);
504 size
= offsetof( FILE_RENAME_INFORMATION
, FileName
) + nt_name
.Length
;
505 if (!(rename_info
= HeapAlloc( GetProcessHeap(), 0, size
)))
508 rename_info
->ReplaceIfExists
= !!(flag
& MOVEFILE_REPLACE_EXISTING
);
509 rename_info
->RootDirectory
= NULL
;
510 rename_info
->FileNameLength
= nt_name
.Length
;
511 memcpy( rename_info
->FileName
, nt_name
.Buffer
, nt_name
.Length
);
512 RtlFreeUnicodeString( &nt_name
);
513 status
= NtSetInformationFile( source_handle
, &io
, rename_info
, size
, FileRenameInformation
);
514 if (status
== STATUS_NOT_SAME_DEVICE
&& (flag
& MOVEFILE_COPY_ALLOWED
))
516 NtClose( source_handle
);
517 if (!CopyFileExW( source
, dest
, fnProgress
, param
, NULL
,
518 flag
& MOVEFILE_REPLACE_EXISTING
?
519 0 : COPY_FILE_FAIL_IF_EXISTS
))
521 return DeleteFileW( source
);
524 NtClose( source_handle
);
525 return set_ntstatus( status
);
528 if (source_handle
) NtClose( source_handle
);
532 /**************************************************************************
533 * MoveFileWithProgressA (KERNEL32.@)
535 BOOL WINAPI
MoveFileWithProgressA( LPCSTR source
, LPCSTR dest
,
536 LPPROGRESS_ROUTINE fnProgress
,
537 LPVOID param
, DWORD flag
)
539 WCHAR
*sourceW
, *destW
;
542 if (!(sourceW
= FILE_name_AtoW( source
, FALSE
))) return FALSE
;
545 if (!(destW
= FILE_name_AtoW( dest
, TRUE
))) return FALSE
;
550 ret
= MoveFileWithProgressW( sourceW
, destW
, fnProgress
, param
, flag
);
551 HeapFree( GetProcessHeap(), 0, destW
);
555 /**************************************************************************
556 * MoveFileExW (KERNEL32.@)
558 BOOL WINAPI
MoveFileExW( LPCWSTR source
, LPCWSTR dest
, DWORD flag
)
560 return MoveFileWithProgressW( source
, dest
, NULL
, NULL
, flag
);
563 /**************************************************************************
564 * MoveFileExA (KERNEL32.@)
566 BOOL WINAPI
MoveFileExA( LPCSTR source
, LPCSTR dest
, DWORD flag
)
568 return MoveFileWithProgressA( source
, dest
, NULL
, NULL
, flag
);
572 /**************************************************************************
573 * MoveFileW (KERNEL32.@)
575 * Move file or directory
577 BOOL WINAPI
MoveFileW( LPCWSTR source
, LPCWSTR dest
)
579 return MoveFileExW( source
, dest
, MOVEFILE_COPY_ALLOWED
);
583 /**************************************************************************
584 * MoveFileA (KERNEL32.@)
586 BOOL WINAPI
MoveFileA( LPCSTR source
, LPCSTR dest
)
588 return MoveFileExA( source
, dest
, MOVEFILE_COPY_ALLOWED
);
592 /*************************************************************************
593 * CreateHardLinkW (KERNEL32.@)
595 BOOL WINAPI
CreateHardLinkW(LPCWSTR lpFileName
, LPCWSTR lpExistingFileName
,
596 LPSECURITY_ATTRIBUTES lpSecurityAttributes
)
598 UNICODE_STRING ntDest
, ntSource
;
599 FILE_LINK_INFORMATION
*info
= NULL
;
600 OBJECT_ATTRIBUTES attr
;
606 TRACE("(%s, %s, %p)\n", debugstr_w(lpFileName
),
607 debugstr_w(lpExistingFileName
), lpSecurityAttributes
);
609 ntDest
.Buffer
= ntSource
.Buffer
= NULL
;
610 if (!RtlDosPathNameToNtPathName_U( lpFileName
, &ntDest
, NULL
, NULL
) ||
611 !RtlDosPathNameToNtPathName_U( lpExistingFileName
, &ntSource
, NULL
, NULL
))
613 SetLastError( ERROR_PATH_NOT_FOUND
);
617 size
= offsetof( FILE_LINK_INFORMATION
, FileName
) + ntDest
.Length
;
618 if (!(info
= HeapAlloc( GetProcessHeap(), 0, size
)))
620 SetLastError( ERROR_OUTOFMEMORY
);
624 InitializeObjectAttributes( &attr
, &ntSource
, OBJ_CASE_INSENSITIVE
, 0, NULL
);
625 if (!(ret
= set_ntstatus( NtOpenFile( &file
, SYNCHRONIZE
, &attr
, &io
, FILE_SHARE_READ
| FILE_SHARE_WRITE
,
626 FILE_SYNCHRONOUS_IO_NONALERT
) )))
629 info
->ReplaceIfExists
= FALSE
;
630 info
->RootDirectory
= NULL
;
631 info
->FileNameLength
= ntDest
.Length
;
632 memcpy( info
->FileName
, ntDest
.Buffer
, ntDest
.Length
);
633 ret
= set_ntstatus( NtSetInformationFile( file
, &io
, info
, size
, FileLinkInformation
) );
638 RtlFreeUnicodeString( &ntSource
);
639 RtlFreeUnicodeString( &ntDest
);
640 HeapFree( GetProcessHeap(), 0, info
);
645 /*************************************************************************
646 * CreateHardLinkA (KERNEL32.@)
648 BOOL WINAPI
CreateHardLinkA(LPCSTR lpFileName
, LPCSTR lpExistingFileName
,
649 LPSECURITY_ATTRIBUTES lpSecurityAttributes
)
651 WCHAR
*sourceW
, *destW
;
654 if (!(sourceW
= FILE_name_AtoW( lpExistingFileName
, TRUE
)))
658 if (!(destW
= FILE_name_AtoW( lpFileName
, TRUE
)))
660 HeapFree( GetProcessHeap(), 0, sourceW
);
664 res
= CreateHardLinkW( destW
, sourceW
, lpSecurityAttributes
);
666 HeapFree( GetProcessHeap(), 0, sourceW
);
667 HeapFree( GetProcessHeap(), 0, destW
);
673 /***********************************************************************
674 * CreateDirectoryExA (KERNEL32.@)
676 BOOL WINAPI
CreateDirectoryExA( LPCSTR
template, LPCSTR path
, LPSECURITY_ATTRIBUTES sa
)
678 WCHAR
*pathW
, *templateW
= NULL
;
681 if (!(pathW
= FILE_name_AtoW( path
, FALSE
))) return FALSE
;
682 if (template && !(templateW
= FILE_name_AtoW( template, TRUE
))) return FALSE
;
684 ret
= CreateDirectoryExW( templateW
, pathW
, sa
);
685 HeapFree( GetProcessHeap(), 0, templateW
);
690 /***********************************************************************
691 * RemoveDirectoryW (KERNEL32.@)
693 BOOL WINAPI
RemoveDirectoryW( LPCWSTR path
)
695 OBJECT_ATTRIBUTES attr
;
696 UNICODE_STRING nt_name
;
697 ANSI_STRING unix_name
;
703 TRACE( "%s\n", debugstr_w(path
) );
705 if (!RtlDosPathNameToNtPathName_U( path
, &nt_name
, NULL
, NULL
))
707 SetLastError( ERROR_PATH_NOT_FOUND
);
710 attr
.Length
= sizeof(attr
);
711 attr
.RootDirectory
= 0;
712 attr
.Attributes
= OBJ_CASE_INSENSITIVE
;
713 attr
.ObjectName
= &nt_name
;
714 attr
.SecurityDescriptor
= NULL
;
715 attr
.SecurityQualityOfService
= NULL
;
717 if (!set_ntstatus( NtOpenFile( &handle
, DELETE
| SYNCHRONIZE
, &attr
, &io
,
718 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
719 FILE_DIRECTORY_FILE
| FILE_SYNCHRONOUS_IO_NONALERT
)))
721 RtlFreeUnicodeString( &nt_name
);
725 status
= wine_nt_to_unix_file_name( &nt_name
, &unix_name
, FILE_OPEN
, FALSE
);
726 RtlFreeUnicodeString( &nt_name
);
727 if (!set_ntstatus( status
))
733 if (!(ret
= (rmdir( unix_name
.Buffer
) != -1))) FILE_SetDosError();
734 RtlFreeAnsiString( &unix_name
);
740 /***********************************************************************
741 * RemoveDirectoryA (KERNEL32.@)
743 BOOL WINAPI
RemoveDirectoryA( LPCSTR path
)
747 if (!(pathW
= FILE_name_AtoW( path
, FALSE
))) return FALSE
;
748 return RemoveDirectoryW( pathW
);
752 /***********************************************************************
753 * GetSystemDirectoryW (KERNEL32.@)
755 * See comment for GetWindowsDirectoryA.
757 UINT WINAPI
GetSystemDirectoryW( LPWSTR path
, UINT count
)
759 UINT len
= strlenW( DIR_System
) + 1;
760 if (path
&& count
>= len
)
762 strcpyW( path
, DIR_System
);
769 /***********************************************************************
770 * GetSystemDirectoryA (KERNEL32.@)
772 * See comment for GetWindowsDirectoryA.
774 UINT WINAPI
GetSystemDirectoryA( LPSTR path
, UINT count
)
776 return copy_filename_WtoA( DIR_System
, path
, count
);
780 /***********************************************************************
781 * Wow64EnableWow64FsRedirection (KERNEL32.@)
783 * Microsoft C++ Redistributable installers are depending on all %eax bits being set.
785 DWORD
/*BOOLEAN*/ WINAPI
KERNEL32_Wow64EnableWow64FsRedirection( BOOLEAN enable
)
787 return set_ntstatus( RtlWow64EnableFsRedirection( enable
));
791 /***********************************************************************
792 * wine_get_unix_file_name (KERNEL32.@) Not a Windows API
794 * Return the full Unix file name for a given path.
795 * Returned buffer must be freed by caller.
797 char * CDECL
wine_get_unix_file_name( LPCWSTR dosW
)
799 UNICODE_STRING nt_name
;
800 ANSI_STRING unix_name
;
803 if (!RtlDosPathNameToNtPathName_U( dosW
, &nt_name
, NULL
, NULL
)) return NULL
;
804 status
= wine_nt_to_unix_file_name( &nt_name
, &unix_name
, FILE_OPEN_IF
, FALSE
);
805 RtlFreeUnicodeString( &nt_name
);
806 if (status
&& status
!= STATUS_NO_SUCH_FILE
)
808 SetLastError( RtlNtStatusToDosError( status
) );
811 return unix_name
.Buffer
;
815 /***********************************************************************
816 * wine_get_dos_file_name (KERNEL32.@) Not a Windows API
818 * Return the full DOS file name for a given Unix path.
819 * Returned buffer must be freed by caller.
821 WCHAR
* CDECL
wine_get_dos_file_name( LPCSTR str
)
823 UNICODE_STRING nt_name
;
824 ANSI_STRING unix_name
;
827 RtlInitAnsiString( &unix_name
, str
);
828 if (!set_ntstatus( wine_unix_to_nt_file_name( &unix_name
, &nt_name
))) return NULL
;
829 if (nt_name
.Buffer
[5] == ':')
831 /* get rid of the \??\ prefix */
832 /* FIXME: should implement RtlNtPathNameToDosPathName and use that instead */
833 len
= nt_name
.Length
- 4 * sizeof(WCHAR
);
834 memmove( nt_name
.Buffer
, nt_name
.Buffer
+ 4, len
);
835 nt_name
.Buffer
[len
/ sizeof(WCHAR
)] = 0;
838 nt_name
.Buffer
[1] = '\\';
839 return nt_name
.Buffer
;
842 /*************************************************************************
843 * CreateSymbolicLinkW (KERNEL32.@)
845 BOOLEAN WINAPI
CreateSymbolicLinkW(LPCWSTR link
, LPCWSTR target
, DWORD flags
)
847 FIXME("(%s %s %d): stub\n", debugstr_w(link
), debugstr_w(target
), flags
);
851 /*************************************************************************
852 * CreateSymbolicLinkA (KERNEL32.@)
854 BOOLEAN WINAPI
CreateSymbolicLinkA(LPCSTR link
, LPCSTR target
, DWORD flags
)
856 FIXME("(%s %s %d): stub\n", debugstr_a(link
), debugstr_a(target
), flags
);
860 /*************************************************************************
861 * CreateHardLinkTransactedA (KERNEL32.@)
863 BOOL WINAPI
CreateHardLinkTransactedA(LPCSTR link
, LPCSTR target
, LPSECURITY_ATTRIBUTES sa
, HANDLE transaction
)
865 FIXME("(%s %s %p %p): stub\n", debugstr_a(link
), debugstr_a(target
), sa
, transaction
);
866 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
870 /*************************************************************************
871 * CreateHardLinkTransactedW (KERNEL32.@)
873 BOOL WINAPI
CreateHardLinkTransactedW(LPCWSTR link
, LPCWSTR target
, LPSECURITY_ATTRIBUTES sa
, HANDLE transaction
)
875 FIXME("(%s %s %p %p): stub\n", debugstr_w(link
), debugstr_w(target
), sa
, transaction
);
876 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
880 /*************************************************************************
881 * CheckNameLegalDOS8Dot3A (KERNEL32.@)
883 BOOL WINAPI
CheckNameLegalDOS8Dot3A(const char *name
, char *oemname
, DWORD oemname_len
,
884 BOOL
*contains_spaces
, BOOL
*is_legal
)
888 TRACE("(%s %p %u %p %p)\n", name
, oemname
,
889 oemname_len
, contains_spaces
, is_legal
);
891 if (!name
|| !is_legal
)
894 if (!(nameW
= FILE_name_AtoW( name
, FALSE
))) return FALSE
;
896 return CheckNameLegalDOS8Dot3W( nameW
, oemname
, oemname_len
, contains_spaces
, is_legal
);
899 /*************************************************************************
900 * CheckNameLegalDOS8Dot3W (KERNEL32.@)
902 BOOL WINAPI
CheckNameLegalDOS8Dot3W(const WCHAR
*name
, char *oemname
, DWORD oemname_len
,
903 BOOL
*contains_spaces_ret
, BOOL
*is_legal
)
906 UNICODE_STRING nameW
;
907 BOOLEAN contains_spaces
;
909 TRACE("(%s %p %u %p %p)\n", wine_dbgstr_w(name
), oemname
,
910 oemname_len
, contains_spaces_ret
, is_legal
);
912 if (!name
|| !is_legal
)
915 RtlInitUnicodeString( &nameW
, name
);
918 oem_str
.Length
= oemname_len
;
919 oem_str
.MaximumLength
= oemname_len
;
920 oem_str
.Buffer
= oemname
;
923 *is_legal
= RtlIsNameLegalDOS8Dot3( &nameW
, oemname
? &oem_str
: NULL
, &contains_spaces
);
924 if (contains_spaces_ret
) *contains_spaces_ret
= contains_spaces
;
929 /*************************************************************************
930 * SetSearchPathMode (KERNEL32.@)
932 BOOL WINAPI
SetSearchPathMode( DWORD flags
)
934 return set_ntstatus( RtlSetSearchPathMode( flags
));