2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS system libraries
4 * FILE: lib/kernel32/file/curdir.c
5 * PURPOSE: Current directory functions
6 * PROGRAMMER: David Welch (welch@mcmail.com)
12 /* INCLUDES ******************************************************************/
17 #include <kernel32/kernel32.h>
19 /* GLOBALS *******************************************************************/
22 static WCHAR CurrentDirectoryW
[MAX_PATH
] = {0,};
23 static WCHAR SystemDirectoryW
[MAX_PATH
];
24 static WCHAR WindowsDirectoryW
[MAX_PATH
];
26 /* FUNCTIONS *****************************************************************/
28 DWORD STDCALL
GetCurrentDirectoryA(DWORD nBufferLength
, LPSTR lpBuffer
)
31 if ( lpBuffer
== NULL
)
33 uSize
= lstrlenW(CurrentDirectoryW
);
34 if ( nBufferLength
> uSize
) {
36 while ((CurrentDirectoryW
[i
])!=0 && i
< MAX_PATH
)
38 lpBuffer
[i
] = (unsigned char)CurrentDirectoryW
[i
];
46 DWORD STDCALL
GetCurrentDirectoryW(DWORD nBufferLength
, LPWSTR lpBuffer
)
50 DPRINT("CurrentDirectoryW %w\n",CurrentDirectoryW
);
52 if ( lpBuffer
== NULL
)
54 uSize
= lstrlenW(CurrentDirectoryW
);
55 if ( nBufferLength
> uSize
)
56 lstrcpynW(lpBuffer
,CurrentDirectoryW
,uSize
);
58 DPRINT("GetCurrentDirectoryW() = %w\n",lpBuffer
);
63 BOOL STDCALL
SetCurrentDirectoryA(LPCSTR lpPathName
)
67 DPRINT("SetCurrentDirectoryA(lpPathName %s)\n",lpPathName
);
69 if ( lpPathName
== NULL
)
71 if ( lstrlenA(lpPathName
) > MAX_PATH
)
74 while ((lpPathName
[i
])!=0 && i
< MAX_PATH
)
76 CurrentDirectoryW
[i
] = (unsigned short)lpPathName
[i
];
79 CurrentDirectoryW
[i
] = 0;
81 DPRINT("CurrentDirectoryW = '%w'\n",CurrentDirectoryW
);
87 WINBOOL STDCALL
SetCurrentDirectoryW(LPCWSTR lpPathName
)
89 if ( lpPathName
== NULL
)
91 if ( lstrlenW(lpPathName
) > MAX_PATH
)
93 lstrcpyW(CurrentDirectoryW
,lpPathName
);
97 DWORD STDCALL
GetTempPathA(DWORD nBufferLength
, LPSTR lpBuffer
)
99 WCHAR BufferW
[MAX_PATH
];
102 retCode
= GetTempPathW(nBufferLength
,BufferW
);
104 while ((BufferW
[i
])!=0 && i
< MAX_PATH
)
106 lpBuffer
[i
] = (unsigned char)BufferW
[i
];
114 DWORD STDCALL
GetTempPathW(DWORD nBufferLength
, LPWSTR lpBuffer
)
116 WCHAR EnvironmentBufferW
[MAX_PATH
];
119 EnvironmentBufferW
[0] = 0;
120 i
= GetEnvironmentVariableW(L
"TMP",EnvironmentBufferW
,MAX_PATH
);
122 i
= GetEnvironmentVariableW(L
"TEMP",EnvironmentBufferW
,MAX_PATH
);
124 i
= GetCurrentDirectoryW(MAX_PATH
,EnvironmentBufferW
);
129 UINT STDCALL
GetSystemDirectoryA(LPSTR lpBuffer
, UINT uSize
)
132 if ( lpBuffer
== NULL
)
134 uPathSize
= lstrlenW(SystemDirectoryW
);
135 if ( uSize
> uPathSize
) {
137 while ((SystemDirectoryW
[i
])!=0 && i
< uSize
)
139 lpBuffer
[i
] = (unsigned char)SystemDirectoryW
[i
];
148 UINT STDCALL
GetWindowsDirectoryA(LPSTR lpBuffer
, UINT uSize
)
151 if ( lpBuffer
== NULL
)
153 uPathSize
= lstrlenW(WindowsDirectoryW
);
154 if ( uSize
> uPathSize
) {
156 while ((WindowsDirectoryW
[i
])!=0 && i
< uSize
)
158 lpBuffer
[i
] = (unsigned char)WindowsDirectoryW
[i
];
166 UINT STDCALL
GetSystemDirectoryW(LPWSTR lpBuffer
, UINT uSize
)
169 if ( lpBuffer
== NULL
)
171 uPathSize
= lstrlenW(SystemDirectoryW
);
172 if ( uSize
> uPathSize
)
173 lstrcpynW(lpBuffer
,SystemDirectoryW
,uPathSize
);
179 UINT STDCALL
GetWindowsDirectoryW(LPWSTR lpBuffer
, UINT uSize
)
182 if ( lpBuffer
== NULL
)
184 uPathSize
= lstrlenW(WindowsDirectoryW
);
185 if ( uSize
> uPathSize
);
186 lstrcpynW(lpBuffer
,WindowsDirectoryW
,uPathSize
);