1 /* Copyright 1993 Erik Bos
2 * Copyright 1996, 2004 Alexandre Julliard
3 * Copyright 2003 Eric Pouech
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.
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.
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
25 #include <wine/winternl.h>
27 #include <wine/debug.h>
28 WINE_DEFAULT_DEBUG_CHANNEL(path
);
30 static inline BOOL
set_ntstatus( NTSTATUS status
)
32 if (status
) SetLastError( RtlNtStatusToDosError( status
));
36 /***********************************************************************
37 * wine_get_dos_file_name (KERNEL32.@) Not a Windows API
39 * Return the full DOS file name for a given Unix path.
40 * Returned buffer must be freed by caller.
42 WCHAR
* CDECL
wine_get_dos_file_name( LPCSTR str
)
44 UNICODE_STRING nt_name
;
47 SIZE_T len
= strlen(str
) + 1;
49 if (str
[0] != '/') /* relative path name */
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;
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
);
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
)))
69 HeapFree( GetProcessHeap(), 0, buffer
);
76 /* get rid of the \??\ prefix */
77 /* FIXME: should implement RtlNtPathNameToDosPathName and use that instead */
78 memmove( buffer
, buffer
+ 4, (len
- 4) * sizeof(WCHAR
) );
80 else buffer
[1] = '\\';