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 ******************************************************************/
24 static ULONG gDebugChannel
= kernel32file
;
27 /* GLOBAL VARIABLES **********************************************************/
29 UNICODE_STRING SystemDirectory
;
30 UNICODE_STRING WindowsDirectory
;
33 /* FUNCTIONS *****************************************************************/
43 GetCurrentDirectoryA (
48 WCHAR BufferW
[MAX_PATH
];
51 ret
= GetCurrentDirectoryW(MAX_PATH
, BufferW
);
56 SetLastError(ERROR_FILENAME_EXCED_RANGE
);
60 return FilenameW2A_FitOrFail(lpBuffer
, nBufferLength
, BufferW
, ret
+1);
69 GetCurrentDirectoryW (
76 Length
= RtlGetCurrentDirectory_U (nBufferLength
* sizeof(WCHAR
),
79 return (Length
/ sizeof (WCHAR
));
89 SetCurrentDirectoryA (
95 TRACE("setcurrdir: %s\n",lpPathName
);
97 if (!(PathNameW
= FilenameA2W(lpPathName
, FALSE
)))
100 return SetCurrentDirectoryW(PathNameW
);
109 SetCurrentDirectoryW (
113 UNICODE_STRING UnicodeString
;
116 RtlInitUnicodeString (&UnicodeString
,
119 Status
= RtlSetCurrentDirectory_U (&UnicodeString
);
120 if (!NT_SUCCESS(Status
))
122 SetLastErrorByStatus (Status
);
133 * NOTE: Windows returns a dos/short (8.3) path
142 WCHAR BufferW
[MAX_PATH
];
145 ret
= GetTempPathW(MAX_PATH
, BufferW
);
152 SetLastError(ERROR_FILENAME_EXCED_RANGE
);
156 return FilenameW2A_FitOrFail(lpBuffer
, nBufferLength
, BufferW
, ret
+1);
172 static const WCHAR tmp
[] = { 'T', 'M', 'P', 0 };
173 static const WCHAR temp
[] = { 'T', 'E', 'M', 'P', 0 };
174 static const WCHAR userprofile
[] = { 'U','S','E','R','P','R','O','F','I','L','E',0 };
175 WCHAR tmp_path
[MAX_PATH
];
178 TRACE("%u,%p\n", count
, path
);
180 if (!(ret
= GetEnvironmentVariableW( tmp
, tmp_path
, MAX_PATH
)) &&
181 !(ret
= GetEnvironmentVariableW( temp
, tmp_path
, MAX_PATH
)) &&
182 !(ret
= GetEnvironmentVariableW( userprofile
, tmp_path
, MAX_PATH
)) &&
183 !(ret
= GetWindowsDirectoryW( tmp_path
, MAX_PATH
)))
188 SetLastError(ERROR_FILENAME_EXCED_RANGE
);
192 ret
= GetFullPathNameW(tmp_path
, MAX_PATH
, tmp_path
, NULL
);
195 if (ret
> MAX_PATH
- 2)
197 SetLastError(ERROR_FILENAME_EXCED_RANGE
);
201 if (tmp_path
[ret
-1] != '\\')
203 tmp_path
[ret
++] = '\\';
204 tmp_path
[ret
] = '\0';
207 ret
++; /* add space for terminating 0 */
211 lstrcpynW(path
, tmp_path
, count
);
213 ret
--; /* return length without 0 */
215 path
[0] = 0; /* avoid returning ambiguous "X:" */
218 TRACE("GetTempPathW returning %u, %S\n", ret
, path
);
229 GetSystemDirectoryA (
234 return FilenameU2A_FitOrFail(lpBuffer
, uSize
, &SystemDirectory
);
243 GetSystemDirectoryW (
250 Length
= SystemDirectory
.Length
/ sizeof (WCHAR
);
252 if (lpBuffer
== NULL
)
255 if (uSize
> Length
) {
257 SystemDirectory
.Buffer
,
258 SystemDirectory
.Length
);
259 lpBuffer
[Length
] = 0;
261 return Length
; //good: ret chars excl. nullchar
264 return Length
+1; //bad: ret space needed incl. nullchar
272 GetWindowsDirectoryA (
277 return FilenameU2A_FitOrFail(lpBuffer
, uSize
, &WindowsDirectory
);
286 GetWindowsDirectoryW (
293 Length
= WindowsDirectory
.Length
/ sizeof (WCHAR
);
295 if (lpBuffer
== NULL
)
301 WindowsDirectory
.Buffer
,
302 WindowsDirectory
.Length
);
303 lpBuffer
[Length
] = 0;
305 return Length
; //good: ret chars excl. nullchar
308 return Length
+1; //bad: ret space needed incl. nullchar
316 GetSystemWindowsDirectoryA(
321 return GetWindowsDirectoryA( lpBuffer
, uSize
);
329 GetSystemWindowsDirectoryW(
334 return GetWindowsDirectoryW( lpBuffer
, uSize
);
342 GetSystemWow64DirectoryW(
348 ERR("GetSystemWow64DirectoryW is UNIMPLEMENTED!\n");
351 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
361 GetSystemWow64DirectoryA(
367 WCHAR BufferW
[MAX_PATH
];
370 ret
= GetSystemWow64DirectoryW(BufferW
, MAX_PATH
);
375 SetLastError(ERROR_FILENAME_EXCED_RANGE
);
379 return FilenameW2A_FitOrFail(lpBuffer
, uSize
, BufferW
, ret
+1);
381 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);