3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS system libraries
5 * FILE: lib/kernel32/file/curdir.c
6 * PURPOSE: Current directory functions
7 * PROGRAMMER: Eric Kohl
10 * Thomas Weidenmueller
11 * Gunnar Andre' Dalsnes
17 /* INCLUDES ******************************************************************/
20 #include <wine/debug.h>
22 WINE_DEFAULT_DEBUG_CHANNEL(kernel32file
);
24 /* GLOBAL VARIABLES **********************************************************/
26 UNICODE_STRING SystemDirectory
;
27 UNICODE_STRING WindowsDirectory
;
30 /* FUNCTIONS *****************************************************************/
40 GetCurrentDirectoryA (
45 WCHAR BufferW
[MAX_PATH
];
48 ret
= GetCurrentDirectoryW(MAX_PATH
, BufferW
);
53 SetLastError(ERROR_FILENAME_EXCED_RANGE
);
57 return FilenameW2A_FitOrFail(lpBuffer
, nBufferLength
, BufferW
, ret
+1);
66 GetCurrentDirectoryW (
73 Length
= RtlGetCurrentDirectory_U (nBufferLength
* sizeof(WCHAR
),
76 return (Length
/ sizeof (WCHAR
));
86 SetCurrentDirectoryA (
92 TRACE("setcurrdir: %s\n",lpPathName
);
94 if (!(PathNameW
= FilenameA2W(lpPathName
, FALSE
)))
97 return SetCurrentDirectoryW(PathNameW
);
106 SetCurrentDirectoryW (
110 UNICODE_STRING UnicodeString
;
113 RtlInitUnicodeString (&UnicodeString
,
116 Status
= RtlSetCurrentDirectory_U (&UnicodeString
);
117 if (!NT_SUCCESS(Status
))
119 SetLastErrorByStatus (Status
);
130 * NOTE: Windows returns a dos/short (8.3) path
139 WCHAR BufferW
[MAX_PATH
];
142 ret
= GetTempPathW(MAX_PATH
, BufferW
);
149 SetLastError(ERROR_FILENAME_EXCED_RANGE
);
153 return FilenameW2A_FitOrFail(lpBuffer
, nBufferLength
, BufferW
, ret
+1);
169 static const WCHAR tmp
[] = { 'T', 'M', 'P', 0 };
170 static const WCHAR temp
[] = { 'T', 'E', 'M', 'P', 0 };
171 static const WCHAR userprofile
[] = { 'U','S','E','R','P','R','O','F','I','L','E',0 };
172 WCHAR tmp_path
[MAX_PATH
];
175 TRACE("%u,%p\n", count
, path
);
177 if (!(ret
= GetEnvironmentVariableW( tmp
, tmp_path
, MAX_PATH
)) &&
178 !(ret
= GetEnvironmentVariableW( temp
, tmp_path
, MAX_PATH
)) &&
179 !(ret
= GetEnvironmentVariableW( userprofile
, tmp_path
, MAX_PATH
)) &&
180 !(ret
= GetWindowsDirectoryW( tmp_path
, MAX_PATH
)))
185 SetLastError(ERROR_FILENAME_EXCED_RANGE
);
189 ret
= GetFullPathNameW(tmp_path
, MAX_PATH
, tmp_path
, NULL
);
192 if (ret
> MAX_PATH
- 2)
194 SetLastError(ERROR_FILENAME_EXCED_RANGE
);
198 if (tmp_path
[ret
-1] != '\\')
200 tmp_path
[ret
++] = '\\';
201 tmp_path
[ret
] = '\0';
204 ret
++; /* add space for terminating 0 */
208 lstrcpynW(path
, tmp_path
, count
);
210 ret
--; /* return length without 0 */
212 path
[0] = 0; /* avoid returning ambiguous "X:" */
215 TRACE("GetTempPathW returning %u, %S\n", ret
, path
);
226 GetSystemDirectoryA (
231 return FilenameU2A_FitOrFail(lpBuffer
, uSize
, &SystemDirectory
);
240 GetSystemDirectoryW (
247 Length
= SystemDirectory
.Length
/ sizeof (WCHAR
);
249 if (lpBuffer
== NULL
)
252 if (uSize
> Length
) {
254 SystemDirectory
.Buffer
,
255 SystemDirectory
.Length
);
256 lpBuffer
[Length
] = 0;
258 return Length
; //good: ret chars excl. nullchar
261 return Length
+1; //bad: ret space needed incl. nullchar
269 GetWindowsDirectoryA (
274 return FilenameU2A_FitOrFail(lpBuffer
, uSize
, &WindowsDirectory
);
283 GetWindowsDirectoryW (
290 Length
= WindowsDirectory
.Length
/ sizeof (WCHAR
);
292 if (lpBuffer
== NULL
)
298 WindowsDirectory
.Buffer
,
299 WindowsDirectory
.Length
);
300 lpBuffer
[Length
] = 0;
302 return Length
; //good: ret chars excl. nullchar
305 return Length
+1; //bad: ret space needed incl. nullchar
313 GetSystemWindowsDirectoryA(
318 return GetWindowsDirectoryA( lpBuffer
, uSize
);
326 GetSystemWindowsDirectoryW(
331 return GetWindowsDirectoryW( lpBuffer
, uSize
);
339 GetSystemWow64DirectoryW(
345 ERR("GetSystemWow64DirectoryW is UNIMPLEMENTED!\n");
348 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
358 GetSystemWow64DirectoryA(
364 WCHAR BufferW
[MAX_PATH
];
367 ret
= GetSystemWow64DirectoryW(BufferW
, MAX_PATH
);
372 SetLastError(ERROR_FILENAME_EXCED_RANGE
);
376 return FilenameW2A_FitOrFail(lpBuffer
, uSize
, BufferW
, ret
+1);
378 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);