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
12 /* INCLUDES ******************************************************************/
17 #include "../include/debug.h"
20 /* GLOBAL VARIABLES **********************************************************/
22 UNICODE_STRING SystemDirectory
;
23 UNICODE_STRING WindowsDirectory
;
26 /* FUNCTIONS *****************************************************************/
36 GetCurrentDirectoryA (
41 WCHAR BufferW
[MAX_PATH
];
44 ret
= GetCurrentDirectoryW(MAX_PATH
, BufferW
);
49 SetLastError(ERROR_FILENAME_EXCED_RANGE
);
53 return FilenameW2A_FitOrFail(lpBuffer
, nBufferLength
, BufferW
, ret
+1);
62 GetCurrentDirectoryW (
69 Length
= RtlGetCurrentDirectory_U (nBufferLength
* sizeof(WCHAR
),
72 return (Length
/ sizeof (WCHAR
));
82 SetCurrentDirectoryA (
88 DPRINT("setcurrdir: %s\n",lpPathName
);
90 if (!(PathNameW
= FilenameA2W(lpPathName
, FALSE
)))
93 return SetCurrentDirectoryW(PathNameW
);
102 SetCurrentDirectoryW (
106 UNICODE_STRING UnicodeString
;
109 RtlInitUnicodeString (&UnicodeString
,
112 Status
= RtlSetCurrentDirectory_U (&UnicodeString
);
113 if (!NT_SUCCESS(Status
))
115 SetLastErrorByStatus (Status
);
126 * NOTE: Windows returns a dos/short (8.3) path
135 WCHAR BufferW
[MAX_PATH
];
138 ret
= GetTempPathW(MAX_PATH
, BufferW
);
145 SetLastError(ERROR_FILENAME_EXCED_RANGE
);
149 return FilenameW2A_FitOrFail(lpBuffer
, nBufferLength
, BufferW
, ret
+1);
165 WCHAR tmp_path
[MAX_PATH
];
166 WCHAR tmp_full_path
[MAX_PATH
];
169 DPRINT("GetTempPathW(%lu,%p)\n", count
, path
);
171 if (!(ret
= GetEnvironmentVariableW( L
"TMP", tmp_path
, MAX_PATH
)))
172 if (!(ret
= GetEnvironmentVariableW( L
"TEMP", tmp_path
, MAX_PATH
)))
173 if (!(ret
= GetCurrentDirectoryW( MAX_PATH
, tmp_path
)))
178 SetLastError(ERROR_FILENAME_EXCED_RANGE
);
182 ret
= GetFullPathNameW(tmp_path
, MAX_PATH
, tmp_full_path
, NULL
);
185 if (ret
> MAX_PATH
- 2)
187 SetLastError(ERROR_FILENAME_EXCED_RANGE
);
191 if (tmp_full_path
[ret
-1] != '\\')
193 tmp_full_path
[ret
++] = '\\';
194 tmp_full_path
[ret
] = '\0';
197 ret
++; /* add space for terminating 0 */
201 lstrcpynW(path
, tmp_full_path
, count
);
203 ret
--; /* return length without 0 */
205 path
[0] = 0; /* avoid returning ambiguous "X:" */
208 DPRINT("GetTempPathW returning %u, %s\n", ret
, path
);
219 GetSystemDirectoryA (
224 return FilenameU2A_FitOrFail(lpBuffer
, uSize
, &SystemDirectory
);
233 GetSystemDirectoryW (
240 Length
= SystemDirectory
.Length
/ sizeof (WCHAR
);
242 if (lpBuffer
== NULL
)
245 if (uSize
> Length
) {
247 SystemDirectory
.Buffer
,
248 SystemDirectory
.Length
);
249 lpBuffer
[Length
] = 0;
251 return Length
; //good: ret chars excl. nullchar
254 return Length
+1; //bad: ret space needed incl. nullchar
262 GetWindowsDirectoryA (
267 return FilenameU2A_FitOrFail(lpBuffer
, uSize
, &WindowsDirectory
);
276 GetWindowsDirectoryW (
283 Length
= WindowsDirectory
.Length
/ sizeof (WCHAR
);
285 if (lpBuffer
== NULL
)
291 WindowsDirectory
.Buffer
,
292 WindowsDirectory
.Length
);
293 lpBuffer
[Length
] = 0;
295 return Length
; //good: ret chars excl. nullchar
298 return Length
+1; //bad: ret space needed incl. nullchar
306 GetSystemWindowsDirectoryA(
311 return GetWindowsDirectoryA( lpBuffer
, uSize
);
319 GetSystemWindowsDirectoryW(
324 return GetWindowsDirectoryW( lpBuffer
, uSize
);
332 GetSystemWow64DirectoryW(
338 DPRINT1("GetSystemWow64DirectoryW is UNIMPLEMENTED!\n");
341 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
351 GetSystemWow64DirectoryA(
357 WCHAR BufferW
[MAX_PATH
];
360 ret
= GetSystemWow64DirectoryW(BufferW
, MAX_PATH
);
365 SetLastError(ERROR_FILENAME_EXCED_RANGE
);
369 return FilenameW2A_FitOrFail(lpBuffer
, uSize
, BufferW
, ret
+1);
371 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);