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 #else 65 len += 8; /* \??\unix prefix */ 66 if (!(buffer = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) ))) return NULL; 67 if (!set_ntstatus( wine_unix_to_nt_file_name( str, buffer, &len ))) 68 { 69 HeapFree( GetProcessHeap(), 0, buffer ); 70 return NULL; 71 } 72 #endif 73 } 74 if (buffer[5] == ':') 75 { 76 /* get rid of the \??\ prefix */ 77 /* FIXME: should implement RtlNtPathNameToDosPathName and use that instead */ 78 memmove( buffer, buffer + 4, (len - 4) * sizeof(WCHAR) ); 79 } 80 else buffer[1] = '\\'; 81 return buffer; 82 } 83