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 DEBUG_CHANNEL(kernel32file
);
27 /* GLOBAL VARIABLES **********************************************************/
29 UNICODE_STRING SystemDirectory
;
30 UNICODE_STRING WindowsDirectory
;
31 UNICODE_STRING BaseDefaultPathAppend
;
32 UNICODE_STRING BaseDefaultPath
;
35 /* FUNCTIONS *****************************************************************/
45 GetCurrentDirectoryA (
50 WCHAR BufferW
[MAX_PATH
];
53 ret
= GetCurrentDirectoryW(MAX_PATH
, BufferW
);
58 SetLastError(ERROR_FILENAME_EXCED_RANGE
);
62 return FilenameW2A_FitOrFail(lpBuffer
, nBufferLength
, BufferW
, ret
+1);
71 GetCurrentDirectoryW (
78 Length
= RtlGetCurrentDirectory_U (nBufferLength
* sizeof(WCHAR
),
81 return (Length
/ sizeof (WCHAR
));
91 SetCurrentDirectoryA (
97 TRACE("setcurrdir: %s\n",lpPathName
);
99 if (!(PathNameW
= FilenameA2W(lpPathName
, FALSE
)))
102 return SetCurrentDirectoryW(PathNameW
);
111 SetCurrentDirectoryW (
115 UNICODE_STRING UnicodeString
;
118 RtlInitUnicodeString (&UnicodeString
,
121 Status
= RtlSetCurrentDirectory_U (&UnicodeString
);
122 if (!NT_SUCCESS(Status
))
124 SetLastErrorByStatus (Status
);
135 * NOTE: Windows returns a dos/short (8.3) path
144 WCHAR BufferW
[MAX_PATH
];
147 ret
= GetTempPathW(MAX_PATH
, BufferW
);
154 SetLastError(ERROR_FILENAME_EXCED_RANGE
);
158 return FilenameW2A_FitOrFail(lpBuffer
, nBufferLength
, BufferW
, ret
+1);
174 static const WCHAR tmp
[] = { 'T', 'M', 'P', 0 };
175 static const WCHAR temp
[] = { 'T', 'E', 'M', 'P', 0 };
176 static const WCHAR userprofile
[] = { 'U','S','E','R','P','R','O','F','I','L','E',0 };
177 WCHAR tmp_path
[MAX_PATH
];
180 TRACE("%u,%p\n", count
, path
);
182 if (!(ret
= GetEnvironmentVariableW( tmp
, tmp_path
, MAX_PATH
)) &&
183 !(ret
= GetEnvironmentVariableW( temp
, tmp_path
, MAX_PATH
)) &&
184 !(ret
= GetEnvironmentVariableW( userprofile
, tmp_path
, MAX_PATH
)) &&
185 !(ret
= GetWindowsDirectoryW( tmp_path
, MAX_PATH
)))
190 SetLastError(ERROR_FILENAME_EXCED_RANGE
);
194 ret
= GetFullPathNameW(tmp_path
, MAX_PATH
, tmp_path
, NULL
);
197 if (ret
> MAX_PATH
- 2)
199 SetLastError(ERROR_FILENAME_EXCED_RANGE
);
203 if (tmp_path
[ret
-1] != '\\')
205 tmp_path
[ret
++] = '\\';
206 tmp_path
[ret
] = '\0';
209 ret
++; /* add space for terminating 0 */
213 lstrcpynW(path
, tmp_path
, count
);
215 ret
--; /* return length without 0 */
217 path
[0] = 0; /* avoid returning ambiguous "X:" */
220 TRACE("GetTempPathW returning %u, %S\n", ret
, path
);
231 GetSystemDirectoryA (
236 return FilenameU2A_FitOrFail(lpBuffer
, uSize
, &SystemDirectory
);
245 GetSystemDirectoryW (
252 Length
= SystemDirectory
.Length
/ sizeof (WCHAR
);
254 if (lpBuffer
== NULL
)
257 if (uSize
> Length
) {
259 SystemDirectory
.Buffer
,
260 SystemDirectory
.Length
);
261 lpBuffer
[Length
] = 0;
263 return Length
; //good: ret chars excl. nullchar
266 return Length
+1; //bad: ret space needed incl. nullchar
274 GetWindowsDirectoryA (
279 return FilenameU2A_FitOrFail(lpBuffer
, uSize
, &WindowsDirectory
);
288 GetWindowsDirectoryW (
295 Length
= WindowsDirectory
.Length
/ sizeof (WCHAR
);
297 if (lpBuffer
== NULL
)
303 WindowsDirectory
.Buffer
,
304 WindowsDirectory
.Length
);
305 lpBuffer
[Length
] = 0;
307 return Length
; //good: ret chars excl. nullchar
310 return Length
+1; //bad: ret space needed incl. nullchar
318 GetSystemWindowsDirectoryA(
323 return GetWindowsDirectoryA( lpBuffer
, uSize
);
331 GetSystemWindowsDirectoryW(
336 return GetWindowsDirectoryW( lpBuffer
, uSize
);
344 GetSystemWow64DirectoryW(
350 ERR("GetSystemWow64DirectoryW is UNIMPLEMENTED!\n");
353 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
363 GetSystemWow64DirectoryA(
369 WCHAR BufferW
[MAX_PATH
];
372 ret
= GetSystemWow64DirectoryW(BufferW
, MAX_PATH
);
377 SetLastError(ERROR_FILENAME_EXCED_RANGE
);
381 return FilenameW2A_FitOrFail(lpBuffer
, uSize
, BufferW
, ret
+1);
383 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);