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 ******************************************************************/
23 /* GLOBAL VARIABLES **********************************************************/
25 UNICODE_STRING SystemDirectory
;
26 UNICODE_STRING WindowsDirectory
;
29 /* FUNCTIONS *****************************************************************/
39 GetCurrentDirectoryA (
44 WCHAR BufferW
[MAX_PATH
];
47 ret
= GetCurrentDirectoryW(MAX_PATH
, BufferW
);
52 SetLastError(ERROR_FILENAME_EXCED_RANGE
);
56 return FilenameW2A_FitOrFail(lpBuffer
, nBufferLength
, BufferW
, ret
+1);
65 GetCurrentDirectoryW (
72 Length
= RtlGetCurrentDirectory_U (nBufferLength
* sizeof(WCHAR
),
75 return (Length
/ sizeof (WCHAR
));
85 SetCurrentDirectoryA (
91 TRACE("setcurrdir: %s\n",lpPathName
);
93 if (!(PathNameW
= FilenameA2W(lpPathName
, FALSE
)))
96 return SetCurrentDirectoryW(PathNameW
);
105 SetCurrentDirectoryW (
109 UNICODE_STRING UnicodeString
;
112 RtlInitUnicodeString (&UnicodeString
,
115 Status
= RtlSetCurrentDirectory_U (&UnicodeString
);
116 if (!NT_SUCCESS(Status
))
118 SetLastErrorByStatus (Status
);
129 * NOTE: Windows returns a dos/short (8.3) path
138 WCHAR BufferW
[MAX_PATH
];
141 ret
= GetTempPathW(MAX_PATH
, BufferW
);
148 SetLastError(ERROR_FILENAME_EXCED_RANGE
);
152 return FilenameW2A_FitOrFail(lpBuffer
, nBufferLength
, BufferW
, ret
+1);
168 static const WCHAR tmp
[] = { 'T', 'M', 'P', 0 };
169 static const WCHAR temp
[] = { 'T', 'E', 'M', 'P', 0 };
170 static const WCHAR userprofile
[] = { 'U','S','E','R','P','R','O','F','I','L','E',0 };
171 WCHAR tmp_path
[MAX_PATH
];
174 TRACE("%u,%p\n", count
, path
);
176 if (!(ret
= GetEnvironmentVariableW( tmp
, tmp_path
, MAX_PATH
)) &&
177 !(ret
= GetEnvironmentVariableW( temp
, tmp_path
, MAX_PATH
)) &&
178 !(ret
= GetEnvironmentVariableW( userprofile
, tmp_path
, MAX_PATH
)) &&
179 !(ret
= GetWindowsDirectoryW( tmp_path
, MAX_PATH
)))
184 SetLastError(ERROR_FILENAME_EXCED_RANGE
);
188 ret
= GetFullPathNameW(tmp_path
, MAX_PATH
, tmp_path
, NULL
);
191 if (ret
> MAX_PATH
- 2)
193 SetLastError(ERROR_FILENAME_EXCED_RANGE
);
197 if (tmp_path
[ret
-1] != '\\')
199 tmp_path
[ret
++] = '\\';
200 tmp_path
[ret
] = '\0';
203 ret
++; /* add space for terminating 0 */
207 lstrcpynW(path
, tmp_path
, count
);
209 ret
--; /* return length without 0 */
211 path
[0] = 0; /* avoid returning ambiguous "X:" */
214 TRACE("GetTempPathW returning %u, %S\n", ret
, path
);
225 GetSystemDirectoryA (
230 return FilenameU2A_FitOrFail(lpBuffer
, uSize
, &SystemDirectory
);
239 GetSystemDirectoryW (
246 Length
= SystemDirectory
.Length
/ sizeof (WCHAR
);
248 if (lpBuffer
== NULL
)
251 if (uSize
> Length
) {
253 SystemDirectory
.Buffer
,
254 SystemDirectory
.Length
);
255 lpBuffer
[Length
] = 0;
257 return Length
; //good: ret chars excl. nullchar
260 return Length
+1; //bad: ret space needed incl. nullchar
268 GetWindowsDirectoryA (
273 return FilenameU2A_FitOrFail(lpBuffer
, uSize
, &WindowsDirectory
);
282 GetWindowsDirectoryW (
289 Length
= WindowsDirectory
.Length
/ sizeof (WCHAR
);
291 if (lpBuffer
== NULL
)
297 WindowsDirectory
.Buffer
,
298 WindowsDirectory
.Length
);
299 lpBuffer
[Length
] = 0;
301 return Length
; //good: ret chars excl. nullchar
304 return Length
+1; //bad: ret space needed incl. nullchar
312 GetSystemWindowsDirectoryA(
317 return GetWindowsDirectoryA( lpBuffer
, uSize
);
325 GetSystemWindowsDirectoryW(
330 return GetWindowsDirectoryW( lpBuffer
, uSize
);
338 GetSystemWow64DirectoryW(
344 ERR("GetSystemWow64DirectoryW is UNIMPLEMENTED!\n");
347 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
357 GetSystemWow64DirectoryA(
363 WCHAR BufferW
[MAX_PATH
];
366 ret
= GetSystemWow64DirectoryW(BufferW
, MAX_PATH
);
371 SetLastError(ERROR_FILENAME_EXCED_RANGE
);
375 return FilenameW2A_FitOrFail(lpBuffer
, uSize
, BufferW
, ret
+1);
377 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);