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"
31 #define NONAMELESSUNION
32 #define NONAMELESSSTRUCT
35 #define WIN32_NO_STATUS
40 #include "kernel_private.h"
41 #include "wine/unicode.h"
42 #include "wine/debug.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(file);
46 #define MAX_PATHNAME_LEN 1024
49 /* check if a file name is for an executable file (.exe or .com) */
50 static inline BOOL is_executable( const WCHAR *name )
52 static const WCHAR exeW[] = {'.','e','x','e',0};
53 static const WCHAR comW[] = {'.','c','o','m',0};
54 int len = strlenW(name);
56 if (len < 4) return FALSE;
57 return (!strcmpiW( name + len - 4, exeW ) || !strcmpiW( name + len - 4, comW ));
60 /***********************************************************************
63 * copy a file name back to OEM/Ansi, but only if the buffer is large enough
65 static DWORD copy_filename_WtoA( LPCWSTR nameW, LPSTR buffer, DWORD len )
69 BOOL is_ansi = AreFileApisANSI();
71 RtlInitUnicodeString( &strW, nameW );
73 ret = is_ansi ? RtlUnicodeStringToAnsiSize(&strW) : RtlUnicodeStringToOemSize(&strW);
74 if (buffer && ret <= len)
79 str.MaximumLength = len;
81 RtlUnicodeStringToAnsiString( &str, &strW, FALSE );
83 RtlUnicodeStringToOemString( &str, &strW, FALSE );
84 ret = str.Length; /* length without terminating 0 */
89 /***********************************************************************
90 * add_boot_rename_entry
92 * Adds an entry to the registry that is loaded when windows boots and
93 * checks if there are some files to be removed or renamed/moved.
94 * <fn1> has to be valid and <fn2> may be NULL. If both pointers are
95 * non-NULL then the file is moved, otherwise it is deleted. The
96 * entry of the registrykey is always appended with two zero
97 * terminated strings. If <fn2> is NULL then the second entry is
98 * simply a single 0-byte. Otherwise the second filename goes
99 * there. The entries are prepended with \??\ before the path and the
100 * second filename gets also a '!' as the first character if
101 * MOVEFILE_REPLACE_EXISTING is set. After the final string another
102 * 0-byte follows to indicate the end of the strings.
104 * \??\D:\test\file1[0]
105 * !\??\D:\test\file1_renamed[0]
106 * \??\D:\Test|delete[0]
107 * [0] <- file is to be deleted, second string empty
108 * \??\D:\test\file2[0]
109 * !\??\D:\test\file2_renamed[0]
110 * [0] <- indicates end of strings
113 * \??\D:\test\file1[0]
114 * !\??\D:\test\file1_renamed[0]
115 * \??\D:\Test|delete[0]
116 * [0] <- file is to be deleted, second string empty
117 * [0] <- indicates end of strings
120 static BOOL add_boot_rename_entry( LPCWSTR source, LPCWSTR dest, DWORD flags )
122 static const WCHAR ValueName[] = {'P','e','n','d','i','n','g',
123 'F','i','l','e','R','e','n','a','m','e',
124 'O','p','e','r','a','t','i','o','n','s',0};
125 static const WCHAR SessionW[] = {'M','a','c','h','i','n','e','\\',
126 'S','y','s','t','e','m','\\',
127 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
128 'C','o','n','t','r','o','l','\\',
129 'S','e','s','s','i','o','n',' ','M','a','n','a','g','e','r',0};
130 static const int info_size = FIELD_OFFSET( KEY_VALUE_PARTIAL_INFORMATION, Data );
132 OBJECT_ATTRIBUTES attr;
133 UNICODE_STRING nameW, source_name, dest_name;
134 KEY_VALUE_PARTIAL_INFORMATION *info;
142 if (!RtlDosPathNameToNtPathName_U( source, &source_name, NULL, NULL ))
144 SetLastError( ERROR_PATH_NOT_FOUND );
147 dest_name.Buffer = NULL;
148 if (dest && !RtlDosPathNameToNtPathName_U( dest, &dest_name, NULL, NULL ))
150 RtlFreeUnicodeString( &source_name );
151 SetLastError( ERROR_PATH_NOT_FOUND );
155 attr.Length = sizeof(attr);
156 attr.RootDirectory = 0;
157 attr.ObjectName = &nameW;
159 attr.SecurityDescriptor = NULL;
160 attr.SecurityQualityOfService = NULL;
161 RtlInitUnicodeString( &nameW, SessionW );
163 if (NtCreateKey( &Reboot, KEY_ALL_ACCESS, &attr, 0, NULL, 0, NULL ) != STATUS_SUCCESS)
165 WARN("Error creating key for reboot managment [%s]\n",
166 "SYSTEM\\CurrentControlSet\\Control\\Session Manager");
167 RtlFreeUnicodeString( &source_name );
168 RtlFreeUnicodeString( &dest_name );
172 len1 = source_name.Length + sizeof(WCHAR);
175 len2 = dest_name.Length + sizeof(WCHAR);
176 if (flags & MOVEFILE_REPLACE_EXISTING)
177 len2 += sizeof(WCHAR); /* Plus 1 because of the leading '!' */
179 else len2 = sizeof(WCHAR); /* minimum is the 0 characters for the empty second string */
181 RtlInitUnicodeString( &nameW, ValueName );
183 /* First we check if the key exists and if so how many bytes it already contains. */
184 if (NtQueryValueKey( Reboot, &nameW, KeyValuePartialInformation,
185 NULL, 0, &DataSize ) == STATUS_BUFFER_OVERFLOW)
187 if (!(Buffer = HeapAlloc( GetProcessHeap(), 0, DataSize + len1 + len2 + sizeof(WCHAR) )))
189 if (NtQueryValueKey( Reboot, &nameW, KeyValuePartialInformation,
190 Buffer, DataSize, &DataSize )) goto Quit;
191 info = (KEY_VALUE_PARTIAL_INFORMATION *)Buffer;
192 if (info->Type != REG_MULTI_SZ) goto Quit;
193 if (DataSize > sizeof(info)) DataSize -= sizeof(WCHAR); /* remove terminating null (will be added back later) */
197 DataSize = info_size;
198 if (!(Buffer = HeapAlloc( GetProcessHeap(), 0, DataSize + len1 + len2 + sizeof(WCHAR) )))
202 memcpy( Buffer + DataSize, source_name.Buffer, len1 );
204 p = (WCHAR *)(Buffer + DataSize);
207 if (flags & MOVEFILE_REPLACE_EXISTING)
209 memcpy( p, dest_name.Buffer, len2 );
215 DataSize += sizeof(WCHAR);
219 p = (WCHAR *)(Buffer + DataSize);
221 DataSize += sizeof(WCHAR);
223 rc = !NtSetValueKey(Reboot, &nameW, 0, REG_MULTI_SZ, Buffer + info_size, DataSize - info_size);
226 RtlFreeUnicodeString( &source_name );
227 RtlFreeUnicodeString( &dest_name );
228 if (Reboot) NtClose(Reboot);
229 HeapFree( GetProcessHeap(), 0, Buffer );
234 /***********************************************************************
235 * GetFullPathNameW (KERNEL32.@)
237 * if the path closed with '\', *lastpart is 0
239 DWORD WINAPI GetFullPathNameW( LPCWSTR name, DWORD len, LPWSTR buffer,
242 return RtlGetFullPathName_U(name, len * sizeof(WCHAR), buffer, lastpart) / sizeof(WCHAR);
245 /***********************************************************************
246 * GetFullPathNameA (KERNEL32.@)
248 * if the path closed with '\', *lastpart is 0
250 DWORD WINAPI GetFullPathNameA( LPCSTR name, DWORD len, LPSTR buffer,
254 WCHAR bufferW[MAX_PATH];
257 if (!(nameW = FILE_name_AtoW( name, FALSE ))) return 0;
259 ret = GetFullPathNameW( nameW, MAX_PATH, bufferW, NULL);
264 SetLastError(ERROR_FILENAME_EXCED_RANGE);
267 ret = copy_filename_WtoA( bufferW, buffer, len );
268 if (ret < len && lastpart)
270 LPSTR p = buffer + strlen(buffer) - 1;
274 while ((p > buffer + 2) && (*p != '\\')) p--;
277 else *lastpart = NULL;
283 /***********************************************************************
284 * GetLongPathNameW (KERNEL32.@)
287 * observed (Win2000):
288 * shortpath=NULL: LastError=ERROR_INVALID_PARAMETER, ret=0
289 * shortpath="": LastError=ERROR_PATH_NOT_FOUND, ret=0
291 DWORD WINAPI GetLongPathNameW( LPCWSTR shortpath, LPWSTR longpath, DWORD longlen )
293 WCHAR tmplongpath[MAX_PATHNAME_LEN];
295 DWORD sp = 0, lp = 0;
298 WIN32_FIND_DATAW wfd;
303 SetLastError(ERROR_INVALID_PARAMETER);
308 SetLastError(ERROR_PATH_NOT_FOUND);
312 TRACE("%s,%p,%d\n", debugstr_w(shortpath), longpath, longlen);
314 if (shortpath[0] == '\\' && shortpath[1] == '\\')
316 ERR("UNC pathname %s\n", debugstr_w(shortpath));
317 lstrcpynW( longpath, shortpath, longlen );
318 return strlenW(longpath);
321 unixabsolute = (shortpath[0] == '/');
323 /* check for drive letter */
324 if (!unixabsolute && shortpath[1] == ':' )
326 tmplongpath[0] = shortpath[0];
327 tmplongpath[1] = ':';
331 while (shortpath[sp])
333 /* check for path delimiters and reproduce them */
334 if (shortpath[sp] == '\\' || shortpath[sp] == '/')
336 if (!lp || tmplongpath[lp-1] != '\\')
338 /* strip double "\\" */
339 tmplongpath[lp++] = '\\';
341 tmplongpath[lp] = 0; /* terminate string */
347 if (sp == 0 && p[0] == '.' && (p[1] == '/' || p[1] == '\\'))
349 tmplongpath[lp++] = *p++;
350 tmplongpath[lp++] = *p++;
352 for (; *p && *p != '/' && *p != '\\'; p++);
353 tmplen = p - (shortpath + sp);
354 lstrcpynW(tmplongpath + lp, shortpath + sp, tmplen + 1);
355 /* Check if the file exists and use the existing file name */
356 goit = FindFirstFileW(tmplongpath, &wfd);
357 if (goit == INVALID_HANDLE_VALUE)
359 TRACE("not found %s!\n", debugstr_w(tmplongpath));
360 SetLastError ( ERROR_FILE_NOT_FOUND );
364 strcpyW(tmplongpath + lp, wfd.cFileName);
365 lp += strlenW(tmplongpath + lp);
368 tmplen = strlenW(shortpath) - 1;
369 if ((shortpath[tmplen] == '/' || shortpath[tmplen] == '\\') &&
370 (tmplongpath[lp - 1] != '/' && tmplongpath[lp - 1] != '\\'))
371 tmplongpath[lp++] = shortpath[tmplen];
374 tmplen = strlenW(tmplongpath) + 1;
375 if (tmplen <= longlen)
377 strcpyW(longpath, tmplongpath);
378 TRACE("returning %s\n", debugstr_w(longpath));
379 tmplen--; /* length without 0 */
385 /***********************************************************************
386 * GetLongPathNameA (KERNEL32.@)
388 DWORD WINAPI GetLongPathNameA( LPCSTR shortpath, LPSTR longpath, DWORD longlen )
391 WCHAR longpathW[MAX_PATH];
394 TRACE("%s\n", debugstr_a(shortpath));
396 if (!(shortpathW = FILE_name_AtoW( shortpath, FALSE ))) return 0;
398 ret = GetLongPathNameW(shortpathW, longpathW, MAX_PATH);
403 SetLastError(ERROR_FILENAME_EXCED_RANGE);
406 return copy_filename_WtoA( longpathW, longpath, longlen );
410 /***********************************************************************
411 * GetShortPathNameW (KERNEL32.@)
415 * longpath=NULL: LastError=ERROR_INVALID_PARAMETER, ret=0
416 * longpath="" or invalid: LastError=ERROR_BAD_PATHNAME, ret=0
418 * more observations ( with NT 3.51 (WinDD) ):
419 * longpath <= 8.3 -> just copy longpath to shortpath
421 * a) file does not exist -> return 0, LastError = ERROR_FILE_NOT_FOUND
422 * b) file does exist -> set the short filename.
423 * - trailing slashes are reproduced in the short name, even if the
424 * file is not a directory
425 * - the absolute/relative path of the short name is reproduced like found
427 * - longpath and shortpath may have the same address
430 DWORD WINAPI GetShortPathNameW( LPCWSTR longpath, LPWSTR shortpath, DWORD shortlen )
432 WCHAR tmpshortpath[MAX_PATHNAME_LEN];
434 DWORD sp = 0, lp = 0;
436 WIN32_FIND_DATAW wfd;
439 WCHAR ustr_buf[8+1+3+1];
441 TRACE("%s\n", debugstr_w(longpath));
445 SetLastError(ERROR_INVALID_PARAMETER);
450 SetLastError(ERROR_BAD_PATHNAME);
454 /* check for drive letter */
455 if (longpath[0] != '/' && longpath[1] == ':' )
457 tmpshortpath[0] = longpath[0];
458 tmpshortpath[1] = ':';
462 ustr.Buffer = ustr_buf;
464 ustr.MaximumLength = sizeof(ustr_buf);
468 /* check for path delimiters and reproduce them */
469 if (longpath[lp] == '\\' || longpath[lp] == '/')
471 if (!sp || tmpshortpath[sp-1] != '\\')
473 /* strip double "\\" */
474 tmpshortpath[sp] = '\\';
477 tmpshortpath[sp] = 0; /* terminate string */
482 for (p = longpath + lp; *p && *p != '/' && *p != '\\'; p++);
483 tmplen = p - (longpath + lp);
484 lstrcpynW(tmpshortpath + sp, longpath + lp, tmplen + 1);
485 /* Check, if the current element is a valid dos name */
489 memcpy(ustr_buf, longpath + lp, tmplen * sizeof(WCHAR));
490 ustr_buf[tmplen] = '\0';
491 ustr.Length = tmplen * sizeof(WCHAR);
492 if (RtlIsNameLegalDOS8Dot3(&ustr, NULL, &spaces) && !spaces)
500 /* Check if the file exists and use the existing short file name */
501 goit = FindFirstFileW(tmpshortpath, &wfd);
502 if (goit == INVALID_HANDLE_VALUE) goto notfound;
504 strcpyW(tmpshortpath + sp, wfd.cAlternateFileName);
505 sp += strlenW(tmpshortpath + sp);
508 tmpshortpath[sp] = 0;
510 tmplen = strlenW(tmpshortpath) + 1;
511 if (tmplen <= shortlen)
513 strcpyW(shortpath, tmpshortpath);
514 TRACE("returning %s\n", debugstr_w(shortpath));
515 tmplen--; /* length without 0 */
521 TRACE("not found!\n" );
522 SetLastError ( ERROR_FILE_NOT_FOUND );
526 /***********************************************************************
527 * GetShortPathNameA (KERNEL32.@)
529 DWORD WINAPI GetShortPathNameA( LPCSTR longpath, LPSTR shortpath, DWORD shortlen )
532 WCHAR shortpathW[MAX_PATH];
535 TRACE("%s\n", debugstr_a(longpath));
537 if (!(longpathW = FILE_name_AtoW( longpath, FALSE ))) return 0;
539 ret = GetShortPathNameW(longpathW, shortpathW, MAX_PATH);
544 SetLastError(ERROR_FILENAME_EXCED_RANGE);
547 return copy_filename_WtoA( shortpathW, shortpath, shortlen );
551 /***********************************************************************
552 * GetTempPathA (KERNEL32.@)
554 DWORD WINAPI GetTempPathA( DWORD count, LPSTR path )
556 WCHAR pathW[MAX_PATH];
559 ret = GetTempPathW(MAX_PATH, pathW);
566 SetLastError(ERROR_FILENAME_EXCED_RANGE);
569 return copy_filename_WtoA( pathW, path, count );
573 /***********************************************************************
574 * GetTempPathW (KERNEL32.@)
576 DWORD WINAPI GetTempPathW( DWORD count, LPWSTR path )
578 static const WCHAR tmp[] = { 'T', 'M', 'P', 0 };
579 static const WCHAR temp[] = { 'T', 'E', 'M', 'P', 0 };
580 static const WCHAR userprofile[] = { 'U','S','E','R','P','R','O','F','I','L','E',0 };
581 WCHAR tmp_path[MAX_PATH];
584 TRACE("%u,%p\n", count, path);
586 if (!(ret = GetEnvironmentVariableW( tmp, tmp_path, MAX_PATH )) &&
587 !(ret = GetEnvironmentVariableW( temp, tmp_path, MAX_PATH )) &&
588 !(ret = GetEnvironmentVariableW( userprofile, tmp_path, MAX_PATH )) &&
589 !(ret = GetWindowsDirectoryW( tmp_path, MAX_PATH )))
594 SetLastError(ERROR_FILENAME_EXCED_RANGE);
598 ret = GetFullPathNameW(tmp_path, MAX_PATH, tmp_path, NULL);
601 if (ret > MAX_PATH - 2)
603 SetLastError(ERROR_FILENAME_EXCED_RANGE);
607 if (tmp_path[ret-1] != '\\')
609 tmp_path[ret++] = '\\';
610 tmp_path[ret] = '\0';
613 ret++; /* add space for terminating 0 */
617 lstrcpynW(path, tmp_path, count);
619 ret--; /* return length without 0 */
621 path[0] = 0; /* avoid returning ambiguous "X:" */
624 TRACE("returning %u, %s\n", ret, debugstr_w(path));
629 /***********************************************************************
630 * GetTempFileNameA (KERNEL32.@)
632 UINT WINAPI GetTempFileNameA( LPCSTR path, LPCSTR prefix, UINT unique, LPSTR buffer)
634 WCHAR *pathW, *prefixW = NULL;
635 WCHAR bufferW[MAX_PATH];
638 if (!(pathW = FILE_name_AtoW( path, FALSE ))) return 0;
639 if (prefix && !(prefixW = FILE_name_AtoW( prefix, TRUE ))) return 0;
641 ret = GetTempFileNameW(pathW, prefixW, unique, bufferW);
642 if (ret) FILE_name_WtoA( bufferW, -1, buffer, MAX_PATH );
644 HeapFree( GetProcessHeap(), 0, prefixW );
648 /***********************************************************************
649 * GetTempFileNameW (KERNEL32.@)
651 UINT WINAPI GetTempFileNameW( LPCWSTR path, LPCWSTR prefix, UINT unique, LPWSTR buffer )
653 static const WCHAR formatW[] = {'%','x','.','t','m','p',0};
658 if ( !path || !buffer )
660 SetLastError( ERROR_INVALID_PARAMETER );
664 strcpyW( buffer, path );
665 p = buffer + strlenW(buffer);
667 /* add a \, if there isn't one */
668 if ((p == buffer) || (p[-1] != '\\')) *p++ = '\\';
671 for (i = 3; (i > 0) && (*prefix); i--) *p++ = *prefix++;
675 if (unique) sprintfW( p, formatW, unique );
678 /* get a "random" unique number and try to create the file */
680 UINT num = GetTickCount() & 0xffff;
686 sprintfW( p, formatW, unique );
687 handle = CreateFileW( buffer, GENERIC_WRITE, 0, NULL,
688 CREATE_NEW, FILE_ATTRIBUTE_NORMAL, 0 );
689 if (handle != INVALID_HANDLE_VALUE)
690 { /* We created it */
691 TRACE("created %s\n", debugstr_w(buffer) );
692 CloseHandle( handle );
695 if (GetLastError() != ERROR_FILE_EXISTS &&
696 GetLastError() != ERROR_SHARING_VIOLATION)
697 break; /* No need to go on */
698 if (!(++unique & 0xffff)) unique = 1;
699 } while (unique != num);
702 TRACE("returning %s\n", debugstr_w(buffer) );
707 /***********************************************************************
710 * Check if the file name contains a path; helper for SearchPathW.
711 * A relative path is not considered a path unless it starts with ./ or ../
713 static inline BOOL contains_pathW (LPCWSTR name)
715 if (RtlDetermineDosPathNameType_U( name ) != RELATIVE_PATH) return TRUE;
716 if (name[0] != '.') return FALSE;
717 if (name[1] == '/' || name[1] == '\\') return TRUE;
718 return (name[1] == '.' && (name[2] == '/' || name[2] == '\\'));
722 /***********************************************************************
723 * SearchPathW [KERNEL32.@]
725 * Searches for a specified file in the search path.
728 * path [I] Path to search (NULL means default)
729 * name [I] Filename to search for.
730 * ext [I] File extension to append to file name. The first
731 * character must be a period. This parameter is
732 * specified only if the filename given does not
733 * contain an extension.
734 * buflen [I] size of buffer, in characters
735 * buffer [O] buffer for found filename
736 * lastpart [O] address of pointer to last used character in
737 * buffer (the final '\')
740 * Success: length of string copied into buffer, not including
741 * terminating null character. If the filename found is
742 * longer than the length of the buffer, the length of the
743 * filename is returned.
747 * If the file is not found, calls SetLastError(ERROR_FILE_NOT_FOUND)
750 DWORD WINAPI SearchPathW( LPCWSTR path, LPCWSTR name, LPCWSTR ext, DWORD buflen,
751 LPWSTR buffer, LPWSTR *lastpart )
755 /* If the name contains an explicit path, ignore the path */
757 if (contains_pathW(name))
759 /* try first without extension */
760 if (RtlDoesFileExists_U( name ))
761 return GetFullPathNameW( name, buflen, buffer, lastpart );
765 LPCWSTR p = strrchrW( name, '.' );
766 if (p && !strchrW( p, '/' ) && !strchrW( p, '\\' ))
767 ext = NULL; /* Ignore the specified extension */
770 /* Allocate a buffer for the file name and extension */
774 DWORD len = strlenW(name) + strlenW(ext);
776 if (!(tmp = HeapAlloc( GetProcessHeap(), 0, (len + 1) * sizeof(WCHAR) )))
778 SetLastError( ERROR_OUTOFMEMORY );
781 strcpyW( tmp, name );
783 if (RtlDoesFileExists_U( tmp ))
784 ret = GetFullPathNameW( tmp, buflen, buffer, lastpart );
785 HeapFree( GetProcessHeap(), 0, tmp );
788 else if (path && path[0]) /* search in the specified path */
790 ret = RtlDosSearchPath_U( path, name, ext, buflen * sizeof(WCHAR),
791 buffer, lastpart ) / sizeof(WCHAR);
793 else /* search in the default path */
795 WCHAR *dll_path = MODULE_get_dll_load_path( NULL );
799 ret = RtlDosSearchPath_U( dll_path, name, ext, buflen * sizeof(WCHAR),
800 buffer, lastpart ) / sizeof(WCHAR);
801 HeapFree( GetProcessHeap(), 0, dll_path );
805 SetLastError( ERROR_OUTOFMEMORY );
810 if (!ret) SetLastError( ERROR_FILE_NOT_FOUND );
811 else TRACE( "found %s\n", debugstr_w(buffer) );
816 /***********************************************************************
817 * SearchPathA (KERNEL32.@)
821 DWORD WINAPI SearchPathA( LPCSTR path, LPCSTR name, LPCSTR ext,
822 DWORD buflen, LPSTR buffer, LPSTR *lastpart )
824 WCHAR *pathW = NULL, *nameW = NULL, *extW = NULL;
825 WCHAR bufferW[MAX_PATH];
828 if (!name || !(nameW = FILE_name_AtoW( name, FALSE ))) return 0;
829 if (path && !(pathW = FILE_name_AtoW( path, TRUE ))) return 0;
831 if (ext && !(extW = FILE_name_AtoW( ext, TRUE )))
833 HeapFree( GetProcessHeap(), 0, pathW );
837 ret = SearchPathW(pathW, nameW, extW, MAX_PATH, bufferW, NULL);
839 HeapFree( GetProcessHeap(), 0, pathW );
840 HeapFree( GetProcessHeap(), 0, extW );
845 SetLastError(ERROR_FILENAME_EXCED_RANGE);
848 ret = copy_filename_WtoA( bufferW, buffer, buflen );
849 if (buflen > ret && lastpart)
850 *lastpart = strrchr(buffer, '\\') + 1;
855 /**************************************************************************
856 * CopyFileW (KERNEL32.@)
858 BOOL WINAPI CopyFileW( LPCWSTR source, LPCWSTR dest, BOOL fail_if_exists )
860 static const int buffer_size = 65536;
862 BY_HANDLE_FILE_INFORMATION info;
867 if (!source || !dest)
869 SetLastError(ERROR_INVALID_PARAMETER);
872 if (!(buffer = HeapAlloc( GetProcessHeap(), 0, buffer_size )))
874 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
878 TRACE("%s -> %s\n", debugstr_w(source), debugstr_w(dest));
880 if ((h1 = CreateFileW(source, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE,
881 NULL, OPEN_EXISTING, 0, 0)) == INVALID_HANDLE_VALUE)
883 WARN("Unable to open source %s\n", debugstr_w(source));
884 HeapFree( GetProcessHeap(), 0, buffer );
888 if (!GetFileInformationByHandle( h1, &info ))
890 WARN("GetFileInformationByHandle returned error for %s\n", debugstr_w(source));
891 HeapFree( GetProcessHeap(), 0, buffer );
896 if ((h2 = CreateFileW( dest, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
897 fail_if_exists ? CREATE_NEW : CREATE_ALWAYS,
898 info.dwFileAttributes, h1 )) == INVALID_HANDLE_VALUE)
900 WARN("Unable to open dest %s\n", debugstr_w(dest));
901 HeapFree( GetProcessHeap(), 0, buffer );
906 while (ReadFile( h1, buffer, buffer_size, &count, NULL ) && count)
912 if (!WriteFile( h2, p, count, &res, NULL ) || !res) goto done;
919 /* Maintain the timestamp of source file to destination file */
920 SetFileTime(h2, NULL, NULL, &info.ftLastWriteTime);
921 HeapFree( GetProcessHeap(), 0, buffer );
928 /**************************************************************************
929 * CopyFileA (KERNEL32.@)
931 BOOL WINAPI CopyFileA( LPCSTR source, LPCSTR dest, BOOL fail_if_exists)
933 WCHAR *sourceW, *destW;
936 if (!(sourceW = FILE_name_AtoW( source, FALSE ))) return FALSE;
937 if (!(destW = FILE_name_AtoW( dest, TRUE ))) return FALSE;
939 ret = CopyFileW( sourceW, destW, fail_if_exists );
941 HeapFree( GetProcessHeap(), 0, destW );
946 /**************************************************************************
947 * CopyFileExW (KERNEL32.@)
949 * This implementation ignores most of the extra parameters passed-in into
950 * the "ex" version of the method and calls the CopyFile method.
951 * It will have to be fixed eventually.
953 BOOL WINAPI CopyFileExW(LPCWSTR sourceFilename, LPCWSTR destFilename,
954 LPPROGRESS_ROUTINE progressRoutine, LPVOID appData,
955 LPBOOL cancelFlagPointer, DWORD copyFlags)
958 * Interpret the only flag that CopyFile can interpret.
960 return CopyFileW(sourceFilename, destFilename, (copyFlags & COPY_FILE_FAIL_IF_EXISTS) != 0);
964 /**************************************************************************
965 * CopyFileExA (KERNEL32.@)
967 BOOL WINAPI CopyFileExA(LPCSTR sourceFilename, LPCSTR destFilename,
968 LPPROGRESS_ROUTINE progressRoutine, LPVOID appData,
969 LPBOOL cancelFlagPointer, DWORD copyFlags)
971 WCHAR *sourceW, *destW;
974 /* can't use the TEB buffer since we may have a callback routine */
975 if (!(sourceW = FILE_name_AtoW( sourceFilename, TRUE ))) return FALSE;
976 if (!(destW = FILE_name_AtoW( destFilename, TRUE )))
978 HeapFree( GetProcessHeap(), 0, sourceW );
981 ret = CopyFileExW(sourceW, destW, progressRoutine, appData,
982 cancelFlagPointer, copyFlags);
983 HeapFree( GetProcessHeap(), 0, sourceW );
984 HeapFree( GetProcessHeap(), 0, destW );
989 /**************************************************************************
990 * MoveFileWithProgressW (KERNEL32.@)
992 BOOL WINAPI MoveFileWithProgressW( LPCWSTR source, LPCWSTR dest,
993 LPPROGRESS_ROUTINE fnProgress,
994 LPVOID param, DWORD flag )
996 FILE_BASIC_INFORMATION info;
997 UNICODE_STRING nt_name;
998 OBJECT_ATTRIBUTES attr;
1001 HANDLE source_handle = 0, dest_handle;
1002 ANSI_STRING source_unix, dest_unix;
1004 TRACE("(%s,%s,%p,%p,%04x)\n",
1005 debugstr_w(source), debugstr_w(dest), fnProgress, param, flag );
1007 if (flag & MOVEFILE_DELAY_UNTIL_REBOOT)
1008 return add_boot_rename_entry( source, dest, flag );
1011 return DeleteFileW( source );
1013 if (flag & MOVEFILE_WRITE_THROUGH)
1014 FIXME("MOVEFILE_WRITE_THROUGH unimplemented\n");
1016 /* check if we are allowed to rename the source */
1018 if (!RtlDosPathNameToNtPathName_U( source, &nt_name, NULL, NULL ))
1020 SetLastError( ERROR_PATH_NOT_FOUND );
1023 source_unix.Buffer = NULL;
1024 dest_unix.Buffer = NULL;
1025 attr.Length = sizeof(attr);
1026 attr.RootDirectory = 0;
1027 attr.Attributes = OBJ_CASE_INSENSITIVE;
1028 attr.ObjectName = &nt_name;
1029 attr.SecurityDescriptor = NULL;
1030 attr.SecurityQualityOfService = NULL;
1032 status = NtOpenFile( &source_handle, 0, &attr, &io, 0, FILE_SYNCHRONOUS_IO_NONALERT );
1033 if (status == STATUS_SUCCESS)
1034 status = wine_nt_to_unix_file_name( &nt_name, &source_unix, FILE_OPEN, FALSE );
1035 RtlFreeUnicodeString( &nt_name );
1036 if (status != STATUS_SUCCESS)
1038 SetLastError( RtlNtStatusToDosError(status) );
1041 status = NtQueryInformationFile( source_handle, &io, &info, sizeof(info), FileBasicInformation );
1042 if (status != STATUS_SUCCESS)
1044 SetLastError( RtlNtStatusToDosError(status) );
1048 /* we must have write access to the destination, and it must */
1049 /* not exist except if MOVEFILE_REPLACE_EXISTING is set */
1051 if (!RtlDosPathNameToNtPathName_U( dest, &nt_name, NULL, NULL ))
1053 SetLastError( ERROR_PATH_NOT_FOUND );
1056 status = NtOpenFile( &dest_handle, GENERIC_READ | GENERIC_WRITE, &attr, &io, 0,
1057 FILE_NON_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT );
1058 if (status == STATUS_SUCCESS) /* destination exists */
1060 NtClose( dest_handle );
1061 if (!(flag & MOVEFILE_REPLACE_EXISTING))
1063 SetLastError( ERROR_ALREADY_EXISTS );
1064 RtlFreeUnicodeString( &nt_name );
1067 else if (info.FileAttributes & FILE_ATTRIBUTE_DIRECTORY) /* cannot replace directory */
1069 SetLastError( ERROR_ACCESS_DENIED );
1073 else if (status != STATUS_OBJECT_NAME_NOT_FOUND)
1075 SetLastError( RtlNtStatusToDosError(status) );
1076 RtlFreeUnicodeString( &nt_name );
1080 status = wine_nt_to_unix_file_name( &nt_name, &dest_unix, FILE_OPEN_IF, FALSE );
1081 RtlFreeUnicodeString( &nt_name );
1082 if (status != STATUS_SUCCESS && status != STATUS_NO_SUCH_FILE)
1084 SetLastError( RtlNtStatusToDosError(status) );
1088 /* now perform the rename */
1090 if (rename( source_unix.Buffer, dest_unix.Buffer ) == -1)
1092 if (errno == EXDEV && (flag & MOVEFILE_COPY_ALLOWED))
1094 NtClose( source_handle );
1095 RtlFreeAnsiString( &source_unix );
1096 RtlFreeAnsiString( &dest_unix );
1097 if (!CopyFileExW( source, dest, fnProgress,
1098 param, NULL, COPY_FILE_FAIL_IF_EXISTS ))
1100 return DeleteFileW( source );
1103 /* if we created the destination, remove it */
1104 if (io.Information == FILE_CREATED) unlink( dest_unix.Buffer );
1108 /* fixup executable permissions */
1110 if (is_executable( source ) != is_executable( dest ))
1113 if (stat( dest_unix.Buffer, &fstat ) != -1)
1115 if (is_executable( dest ))
1116 /* set executable bit where read bit is set */
1117 fstat.st_mode |= (fstat.st_mode & 0444) >> 2;
1119 fstat.st_mode &= ~0111;
1120 chmod( dest_unix.Buffer, fstat.st_mode );
1124 NtClose( source_handle );
1125 RtlFreeAnsiString( &source_unix );
1126 RtlFreeAnsiString( &dest_unix );
1130 if (source_handle) NtClose( source_handle );
1131 RtlFreeAnsiString( &source_unix );
1132 RtlFreeAnsiString( &dest_unix );
1136 /**************************************************************************
1137 * MoveFileWithProgressA (KERNEL32.@)
1139 BOOL WINAPI MoveFileWithProgressA( LPCSTR source, LPCSTR dest,
1140 LPPROGRESS_ROUTINE fnProgress,
1141 LPVOID param, DWORD flag )
1143 WCHAR *sourceW, *destW;
1146 if (!(sourceW = FILE_name_AtoW( source, FALSE ))) return FALSE;
1149 if (!(destW = FILE_name_AtoW( dest, TRUE ))) return FALSE;
1154 ret = MoveFileWithProgressW( sourceW, destW, fnProgress, param, flag );
1155 HeapFree( GetProcessHeap(), 0, destW );
1159 /**************************************************************************
1160 * MoveFileExW (KERNEL32.@)
1162 BOOL WINAPI MoveFileExW( LPCWSTR source, LPCWSTR dest, DWORD flag )
1164 return MoveFileWithProgressW( source, dest, NULL, NULL, flag );
1167 /**************************************************************************
1168 * MoveFileExA (KERNEL32.@)
1170 BOOL WINAPI MoveFileExA( LPCSTR source, LPCSTR dest, DWORD flag )
1172 return MoveFileWithProgressA( source, dest, NULL, NULL, flag );
1176 /**************************************************************************
1177 * MoveFileW (KERNEL32.@)
1179 * Move file or directory
1181 BOOL WINAPI MoveFileW( LPCWSTR source, LPCWSTR dest )
1183 return MoveFileExW( source, dest, MOVEFILE_COPY_ALLOWED );
1187 /**************************************************************************
1188 * MoveFileA (KERNEL32.@)
1190 BOOL WINAPI MoveFileA( LPCSTR source, LPCSTR dest )
1192 return MoveFileExA( source, dest, MOVEFILE_COPY_ALLOWED );
1196 /*************************************************************************
1197 * CreateHardLinkW (KERNEL32.@)
1199 BOOL WINAPI CreateHardLinkW(LPCWSTR lpFileName, LPCWSTR lpExistingFileName,
1200 LPSECURITY_ATTRIBUTES lpSecurityAttributes)
1202 FIXME("(%s, %s, %p): stub\n", debugstr_w(lpFileName),
1203 debugstr_w(lpExistingFileName), lpSecurityAttributes);
1204 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1209 /*************************************************************************
1210 * CreateHardLinkA (KERNEL32.@)
1212 BOOL WINAPI CreateHardLinkA(LPCSTR lpFileName, LPCSTR lpExistingFileName,
1213 LPSECURITY_ATTRIBUTES lpSecurityAttributes)
1215 FIXME("(%s, %s, %p): stub\n", debugstr_a(lpFileName),
1216 debugstr_a(lpExistingFileName), lpSecurityAttributes);
1217 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1222 /***********************************************************************
1223 * CreateDirectoryW (KERNEL32.@)
1227 * ERROR_DISK_FULL: on full disk
1228 * ERROR_ALREADY_EXISTS: if directory name exists (even as file)
1229 * ERROR_ACCESS_DENIED: on permission problems
1230 * ERROR_FILENAME_EXCED_RANGE: too long filename(s)
1232 BOOL WINAPI CreateDirectoryW( LPCWSTR path, LPSECURITY_ATTRIBUTES sa )
1234 OBJECT_ATTRIBUTES attr;
1235 UNICODE_STRING nt_name;
1241 TRACE( "%s\n", debugstr_w(path) );
1243 if (!RtlDosPathNameToNtPathName_U( path, &nt_name, NULL, NULL ))
1245 SetLastError( ERROR_PATH_NOT_FOUND );
1248 attr.Length = sizeof(attr);
1249 attr.RootDirectory = 0;
1250 attr.Attributes = OBJ_CASE_INSENSITIVE;
1251 attr.ObjectName = &nt_name;
1252 attr.SecurityDescriptor = sa ? sa->lpSecurityDescriptor : NULL;
1253 attr.SecurityQualityOfService = NULL;
1255 status = NtCreateFile( &handle, GENERIC_READ, &attr, &io, NULL,
1256 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ, FILE_CREATE,
1257 FILE_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT, NULL, 0 );
1259 if (status == STATUS_SUCCESS)
1264 else SetLastError( RtlNtStatusToDosError(status) );
1266 RtlFreeUnicodeString( &nt_name );
1271 /***********************************************************************
1272 * CreateDirectoryA (KERNEL32.@)
1274 BOOL WINAPI CreateDirectoryA( LPCSTR path, LPSECURITY_ATTRIBUTES sa )
1278 if (!(pathW = FILE_name_AtoW( path, FALSE ))) return FALSE;
1279 return CreateDirectoryW( pathW, sa );
1283 /***********************************************************************
1284 * CreateDirectoryExA (KERNEL32.@)
1286 BOOL WINAPI CreateDirectoryExA( LPCSTR template, LPCSTR path, LPSECURITY_ATTRIBUTES sa )
1288 WCHAR *pathW, *templateW = NULL;
1291 if (!(pathW = FILE_name_AtoW( path, FALSE ))) return FALSE;
1292 if (template && !(templateW = FILE_name_AtoW( template, TRUE ))) return FALSE;
1294 ret = CreateDirectoryExW( templateW, pathW, sa );
1295 HeapFree( GetProcessHeap(), 0, templateW );
1300 /***********************************************************************
1301 * CreateDirectoryExW (KERNEL32.@)
1303 BOOL WINAPI CreateDirectoryExW( LPCWSTR template, LPCWSTR path, LPSECURITY_ATTRIBUTES sa )
1305 return CreateDirectoryW( path, sa );
1309 /***********************************************************************
1310 * RemoveDirectoryW (KERNEL32.@)
1312 BOOL WINAPI RemoveDirectoryW( LPCWSTR path )
1314 OBJECT_ATTRIBUTES attr;
1315 UNICODE_STRING nt_name;
1316 ANSI_STRING unix_name;
1322 TRACE( "%s\n", debugstr_w(path) );
1324 if (!RtlDosPathNameToNtPathName_U( path, &nt_name, NULL, NULL ))
1326 SetLastError( ERROR_PATH_NOT_FOUND );
1329 attr.Length = sizeof(attr);
1330 attr.RootDirectory = 0;
1331 attr.Attributes = OBJ_CASE_INSENSITIVE;
1332 attr.ObjectName = &nt_name;
1333 attr.SecurityDescriptor = NULL;
1334 attr.SecurityQualityOfService = NULL;
1336 status = NtOpenFile( &handle, DELETE, &attr, &io,
1337 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
1338 FILE_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT );
1339 if (status == STATUS_SUCCESS)
1340 status = wine_nt_to_unix_file_name( &nt_name, &unix_name, FILE_OPEN, FALSE );
1341 RtlFreeUnicodeString( &nt_name );
1343 if (status != STATUS_SUCCESS)
1345 SetLastError( RtlNtStatusToDosError(status) );
1349 if (!(ret = (rmdir( unix_name.Buffer ) != -1))) FILE_SetDosError();
1350 RtlFreeAnsiString( &unix_name );
1356 /***********************************************************************
1357 * RemoveDirectoryA (KERNEL32.@)
1359 BOOL WINAPI RemoveDirectoryA( LPCSTR path )
1363 if (!(pathW = FILE_name_AtoW( path, FALSE ))) return FALSE;
1364 return RemoveDirectoryW( pathW );
1368 /***********************************************************************
1369 * GetCurrentDirectoryW (KERNEL32.@)
1371 UINT WINAPI GetCurrentDirectoryW( UINT buflen, LPWSTR buf )
1373 return RtlGetCurrentDirectory_U( buflen * sizeof(WCHAR), buf ) / sizeof(WCHAR);
1377 /***********************************************************************
1378 * GetCurrentDirectoryA (KERNEL32.@)
1380 UINT WINAPI GetCurrentDirectoryA( UINT buflen, LPSTR buf )
1382 WCHAR bufferW[MAX_PATH];
1385 if (buflen && buf && !HIWORD(buf))
1387 /* Win9x catches access violations here, returning zero.
1388 * This behaviour resulted in some people not noticing
1389 * that they got the argument order wrong. So let's be
1390 * nice and fail gracefully if buf is invalid and looks
1391 * more like a buflen (which is probably MAX_PATH). */
1392 SetLastError(ERROR_INVALID_PARAMETER);
1396 ret = GetCurrentDirectoryW(MAX_PATH, bufferW);
1401 SetLastError(ERROR_FILENAME_EXCED_RANGE);
1404 return copy_filename_WtoA( bufferW, buf, buflen );
1408 /***********************************************************************
1409 * SetCurrentDirectoryW (KERNEL32.@)
1411 BOOL WINAPI SetCurrentDirectoryW( LPCWSTR dir )
1413 UNICODE_STRING dirW;
1416 RtlInitUnicodeString( &dirW, dir );
1417 status = RtlSetCurrentDirectory_U( &dirW );
1418 if (status != STATUS_SUCCESS)
1420 SetLastError( RtlNtStatusToDosError(status) );
1427 /***********************************************************************
1428 * SetCurrentDirectoryA (KERNEL32.@)
1430 BOOL WINAPI SetCurrentDirectoryA( LPCSTR dir )
1434 if (!(dirW = FILE_name_AtoW( dir, FALSE ))) return FALSE;
1435 return SetCurrentDirectoryW( dirW );
1439 /***********************************************************************
1440 * GetWindowsDirectoryW (KERNEL32.@)
1442 * See comment for GetWindowsDirectoryA.
1444 UINT WINAPI GetWindowsDirectoryW( LPWSTR path, UINT count )
1446 UINT len = strlenW( DIR_Windows ) + 1;
1447 if (path && count >= len)
1449 strcpyW( path, DIR_Windows );
1456 /***********************************************************************
1457 * GetWindowsDirectoryA (KERNEL32.@)
1460 * If buffer is large enough to hold full path and terminating '\0' character
1461 * function copies path to buffer and returns length of the path without '\0'.
1462 * Otherwise function returns required size including '\0' character and
1463 * does not touch the buffer.
1465 UINT WINAPI GetWindowsDirectoryA( LPSTR path, UINT count )
1467 return copy_filename_WtoA( DIR_Windows, path, count );
1471 /***********************************************************************
1472 * GetSystemWindowsDirectoryA (KERNEL32.@) W2K, TS4.0SP4
1474 UINT WINAPI GetSystemWindowsDirectoryA( LPSTR path, UINT count )
1476 return GetWindowsDirectoryA( path, count );
1480 /***********************************************************************
1481 * GetSystemWindowsDirectoryW (KERNEL32.@) W2K, TS4.0SP4
1483 UINT WINAPI GetSystemWindowsDirectoryW( LPWSTR path, UINT count )
1485 return GetWindowsDirectoryW( path, count );
1489 /***********************************************************************
1490 * GetSystemDirectoryW (KERNEL32.@)
1492 * See comment for GetWindowsDirectoryA.
1494 UINT WINAPI GetSystemDirectoryW( LPWSTR path, UINT count )
1496 UINT len = strlenW( DIR_System ) + 1;
1497 if (path && count >= len)
1499 strcpyW( path, DIR_System );
1506 /***********************************************************************
1507 * GetSystemDirectoryA (KERNEL32.@)
1509 * See comment for GetWindowsDirectoryA.
1511 UINT WINAPI GetSystemDirectoryA( LPSTR path, UINT count )
1513 return copy_filename_WtoA( DIR_System, path, count );
1517 /***********************************************************************
1518 * GetSystemWow64DirectoryW (KERNEL32.@)
1521 * - On Win32 we should returns ERROR_CALL_NOT_IMPLEMENTED
1522 * - On Win64 we should returns the SysWow64 (system64) directory
1524 UINT WINAPI GetSystemWow64DirectoryW( LPWSTR path, UINT count )
1530 SetLastError( ERROR_CALL_NOT_IMPLEMENTED );
1533 len = strlenW( DIR_SysWow64 ) + 1;
1534 if (path && count >= len)
1536 strcpyW( path, DIR_SysWow64 );
1543 /***********************************************************************
1544 * GetSystemWow64DirectoryA (KERNEL32.@)
1546 * See comment for GetWindowsWow64DirectoryW.
1548 UINT WINAPI GetSystemWow64DirectoryA( LPSTR path, UINT count )
1552 SetLastError( ERROR_CALL_NOT_IMPLEMENTED );
1555 return copy_filename_WtoA( DIR_SysWow64, path, count );
1559 /***********************************************************************
1560 * Wow64EnableWow64FsRedirection (KERNEL32.@)
1562 BOOLEAN WINAPI Wow64EnableWow64FsRedirection( BOOLEAN enable )
1564 NTSTATUS status = RtlWow64EnableFsRedirection( enable );
1565 if (status) SetLastError( RtlNtStatusToDosError(status) );
1570 /***********************************************************************
1571 * Wow64DisableWow64FsRedirection (KERNEL32.@)
1573 BOOL WINAPI Wow64DisableWow64FsRedirection( PVOID *old_value )
1575 NTSTATUS status = RtlWow64EnableFsRedirectionEx( TRUE, (ULONG *)old_value );
1576 if (status) SetLastError( RtlNtStatusToDosError(status) );
1581 /***********************************************************************
1582 * Wow64RevertWow64FsRedirection (KERNEL32.@)
1584 BOOL WINAPI Wow64RevertWow64FsRedirection( PVOID old_value )
1586 NTSTATUS status = RtlWow64EnableFsRedirection( !old_value );
1587 if (status) SetLastError( RtlNtStatusToDosError(status) );
1592 /***********************************************************************
1593 * NeedCurrentDirectoryForExePathW (KERNEL32.@)
1595 BOOL WINAPI NeedCurrentDirectoryForExePathW( LPCWSTR name )
1597 static const WCHAR env_name[] = {'N','o','D','e','f','a','u','l','t',
1598 'C','u','r','r','e','n','t',
1599 'D','i','r','e','c','t','o','r','y',
1600 'I','n','E','x','e','P','a','t','h',0};
1603 /* MSDN mentions some 'registry location'. We do not use registry. */
1604 FIXME("(%s): partial stub\n", debugstr_w(name));
1606 if (strchrW(name, '\\'))
1609 /* Check the existence of the variable, not value */
1610 if (!GetEnvironmentVariableW( env_name, &env_val, 1 ))
1617 /***********************************************************************
1618 * NeedCurrentDirectoryForExePathA (KERNEL32.@)
1620 BOOL WINAPI NeedCurrentDirectoryForExePathA( LPCSTR name )
1624 if (!(nameW = FILE_name_AtoW( name, FALSE ))) return TRUE;
1625 return NeedCurrentDirectoryForExePathW( nameW );
1629 /***********************************************************************
1630 * wine_get_unix_file_name (KERNEL32.@) Not a Windows API
1632 * Return the full Unix file name for a given path.
1633 * Returned buffer must be freed by caller.
1635 char * CDECL wine_get_unix_file_name( LPCWSTR dosW )
1637 UNICODE_STRING nt_name;
1638 ANSI_STRING unix_name;
1641 if (!RtlDosPathNameToNtPathName_U( dosW, &nt_name, NULL, NULL )) return NULL;
1642 status = wine_nt_to_unix_file_name( &nt_name, &unix_name, FILE_OPEN_IF, FALSE );
1643 RtlFreeUnicodeString( &nt_name );
1644 if (status && status != STATUS_NO_SUCH_FILE)
1646 SetLastError( RtlNtStatusToDosError( status ) );
1649 return unix_name.Buffer;
1653 /***********************************************************************
1654 * wine_get_dos_file_name (KERNEL32.@) Not a Windows API
1656 * Return the full DOS file name for a given Unix path.
1657 * Returned buffer must be freed by caller.
1659 WCHAR * CDECL wine_get_dos_file_name( LPCSTR str )
1661 UNICODE_STRING nt_name;
1662 ANSI_STRING unix_name;
1666 RtlInitAnsiString( &unix_name, str );
1667 status = wine_unix_to_nt_file_name( &unix_name, &nt_name );
1670 SetLastError( RtlNtStatusToDosError( status ) );
1673 /* get rid of the \??\ prefix */
1674 /* FIXME: should implement RtlNtPathNameToDosPathName and use that instead */
1675 len = nt_name.Length - 4 * sizeof(WCHAR);
1676 memmove( nt_name.Buffer, nt_name.Buffer + 4, len );
1677 nt_name.Buffer[len / sizeof(WCHAR)] = 0;
1678 return nt_name.Buffer;