1 /* Copyright 1993 Erik Bos 2 * Copyright 1996, 2004 Alexandre Julliard 3 * Copyright 2003 Eric Pouech 4 * 5 * This library is free software; you can redistribute it and/or 6 * modify it under the terms of the GNU Lesser General Public 7 * License as published by the Free Software Foundation; either 8 * version 2.1 of the License, or (at your option) any later version. 9 * 10 * This library is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 * Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public 16 * License along with this library; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 18 * 19 */ 20 21 #include <windef.h> 22 #include <winbase.h> 23 #include <winnls.h> 24 25 #include <wine/winternl.h> 26 27 #include <wine/debug.h> 28 WINE_DEFAULT_DEBUG_CHANNEL(path); 29 30 static inline BOOL set_ntstatus( NTSTATUS status ) 31 { 32 if (status) SetLastError( RtlNtStatusToDosError( status )); 33 return !status; 34 } 35 36 /*********************************************************************** 37 * wine_get_dos_file_name (KERNEL32.@) Not a Windows API 38 * 39 * Return the full DOS file name for a given Unix path. 40 * Returned buffer must be freed by caller. 41 */ 42 WCHAR * CDECL wine_get_dos_file_name( LPCSTR str ) 43 { 44 UNICODE_STRING nt_name; 45 NTSTATUS status; 46 WCHAR *buffer; 47 SIZE_T len = strlen(str) + 1; 48 49 if (str[0] != '/') /* relative path name */ 50 { 51 if (!(buffer = RtlAllocateHeap( GetProcessHeap(), 0, len * sizeof(WCHAR) ))) return NULL; 52 MultiByteToWideChar( CP_UNIXCP, 0, str, len, buffer, len ); 53 status = RtlDosPathNameToNtPathName_U_WithStatus( buffer, &nt_name, NULL, NULL ); 54 RtlFreeHeap( GetProcessHeap(), 0, buffer ); 55 if (!set_ntstatus( status )) return NULL; 56 buffer = nt_name.Buffer; 57 len = nt_name.Length / sizeof(WCHAR) + 1; 58 } 59 else 60 { 61 #ifdef __REACTOS__ 62 ERR("Got absolute UNIX path name in function wine_get_dos_file_name. This is not UNIX. Please fix the caller!\n"); 63 ERR("File name: %s\n", str); 64 /* Return empty path */ 65 return RtlAllocateHeap(GetProcessHeap(), HEAP_ZERO_MEMORY, 1 * sizeof(UNICODE_NULL)); 66 #else 67 len += 8; /* \??\unix prefix */ 68 if (!(buffer = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) ))) return NULL; 69 if (!set_ntstatus( wine_unix_to_nt_file_name( str, buffer, &len ))) 70 { 71 HeapFree( GetProcessHeap(), 0, buffer ); 72 return NULL; 73 } 74 #endif 75 } 76 if (buffer[5] == ':') 77 { 78 /* get rid of the \??\ prefix */ 79 /* FIXME: should implement RtlNtPathNameToDosPathName and use that instead */ 80 memmove( buffer, buffer + 4, (len - 4) * sizeof(WCHAR) ); 81 } 82 else buffer[1] = '\\'; 83 return buffer; 84 } 85