source: trunk/src/kernel32/directory.cpp@ 1570

Last change on this file since 1570 was 1490, checked in by sandervl, 26 years ago

misc changes

File size: 8.6 KB
Line 
1/* $Id: directory.cpp,v 1.8 1999-10-28 12:01:12 sandervl Exp $ */
2
3/*
4 * Win32 Directory functions for OS/2
5 *
6 * Copyright 1998 Sander van Leeuwen
7 *
8 *
9 * Project Odin Software License can be found in LICENSE.TXT
10 *
11 */
12
13
14/*****************************************************************************
15 * Includes *
16 *****************************************************************************/
17
18#include <odin.h>
19#include <odinwrap.h>
20#include <os2win.h>
21#include <stdlib.h>
22#include <unicode.h>
23#include <heapstring.h>
24#include <options.h>
25#include "initterm.h"
26
27ODINDEBUGCHANNEL(KERNEL32-DIRECTORY)
28
29
30/*****************************************************************************
31 * Name : GetCurrentDirectoryA
32 * Purpose : query the current directory
33 * Parameters:
34 * Variables :
35 * Result :
36 * Remark :
37 * Status :
38 *
39 * Author : Patrick Haller [Wed, 1999/09/28 20:44]
40 *****************************************************************************/
41
42ODINFUNCTION2(UINT, GetCurrentDirectoryA, UINT, nBufferLength,
43 LPSTR, lpBuffer)
44{
45 return O32_GetCurrentDirectory(nBufferLength, lpBuffer);
46}
47
48
49/*****************************************************************************
50 * Name : GetCurrentDirectoryW
51 * Purpose : query the current directory
52 * Parameters:
53 * Variables :
54 * Result :
55 * Remark :
56 * Status :
57 *
58 * Author : Patrick Haller [Wed, 1999/09/28 20:44]
59 *****************************************************************************/
60
61ODINFUNCTION2(UINT, GetCurrentDirectoryW, UINT, nBufferLength,
62 LPWSTR, lpBuffer)
63{
64 char *asciidir = (char *)malloc(nBufferLength+1);
65 int rc;
66
67 rc = O32_GetCurrentDirectory(nBufferLength, asciidir);
68 if(rc != 0)
69 AsciiToUnicode(asciidir, lpBuffer);
70 free(asciidir);
71 return(rc);
72}
73
74
75/*****************************************************************************
76 * Name : SetCurrentDirectoryA
77 * Purpose :
78 * Parameters:
79 * Variables :
80 * Result :
81 * Remark :
82 * Status :
83 *
84 * Author : Patrick Haller [Wed, 1999/09/28 20:44]
85 *****************************************************************************/
86
87ODINFUNCTION1(BOOL,SetCurrentDirectoryA,LPCSTR,lpPathName)
88{
89 return O32_SetCurrentDirectory((LPSTR)lpPathName);
90}
91
92
93/*****************************************************************************
94 * Name : SetCurrentDirectoryW
95 * Purpose :
96 * Parameters:
97 * Variables :
98 * Result :
99 * Remark :
100 * Status :
101 *
102 * Author : Patrick Haller [Wed, 1999/09/28 20:44]
103 *****************************************************************************/
104
105ODINFUNCTION1(BOOL,SetCurrentDirectoryW,LPCWSTR,lpPathName)
106{
107 char *asciipath;
108 BOOL rc;
109
110 asciipath = UnicodeToAsciiString((LPWSTR)lpPathName);
111 rc = SetCurrentDirectoryA(asciipath);
112 FreeAsciiString(asciipath);
113 return(rc);
114}
115
116
117/*****************************************************************************
118 * Name : CreateDirectoryA
119 * Purpose :
120 * Parameters:
121 * Variables :
122 * Result :
123 * Remark :
124 * Status :
125 *
126 * Author : Patrick Haller [Wed, 1999/09/28 20:44]
127 *****************************************************************************/
128
129ODINFUNCTION2(BOOL,CreateDirectoryA,LPCSTR, arg1,
130 PSECURITY_ATTRIBUTES,arg2)
131{
132 return O32_CreateDirectory(arg1, arg2);
133}
134
135
136/*****************************************************************************
137 * Name : CreateDirectoryW
138 * Purpose :
139 * Parameters:
140 * Variables :
141 * Result :
142 * Remark :
143 * Status :
144 *
145 * Author : Patrick Haller [Wed, 1999/09/28 20:44]
146 *****************************************************************************/
147
148ODINFUNCTION2(BOOL,CreateDirectoryW,LPCWSTR, arg1,
149 PSECURITY_ATTRIBUTES,arg2)
150{
151 BOOL rc;
152 char *astring;
153
154 astring = UnicodeToAsciiString((LPWSTR)arg1);
155 rc = CreateDirectoryA(astring, arg2);
156 FreeAsciiString(astring);
157 return(rc);
158}
159
160
161/*****************************************************************************
162 * Name : GetSystemDirectoryA
163 * Purpose :
164 * Parameters:
165 * Variables :
166 * Result :
167 * Remark :
168 * Status :
169 *
170 * Author : Patrick Haller [Wed, 1999/09/28 20:44]
171 *****************************************************************************/
172
173ODINFUNCTION2(UINT,GetSystemDirectoryA,LPSTR,lpBuffer,
174 UINT,uSize)
175{
176 LPSTR lpstrEnv = getenv("WIN32.DIR.SYSTEM"); /* query environment */
177
178 if (lpstrEnv != NULL)
179 {
180 lstrcpynA(lpBuffer, /* copy environment variable to buffer */
181 lpstrEnv,
182 uSize);
183 return (lstrlenA(lpBuffer)); /* return number of copies bytes */
184 }
185 else
186 {
187 int len;
188
189 len = PROFILE_GetOdinIniString(ODINDIRECTORIES,"SYSTEM","",lpBuffer,uSize);
190 if (len > 2) {
191 if(lpBuffer[len-1] == '\\') {
192 lpBuffer[len-1] = 0;
193 len--;
194 }
195 return len;
196 }
197 else {//SvL: Use path of kernel32.dll instead of calling Open32 api (which returns \OS2\SYSTEM)
198 lstrcpynA(lpBuffer, kernel32Path, uSize);
199 len = lstrlenA(lpBuffer);;
200 if(lpBuffer[len-1] == '\\') {
201 lpBuffer[len-1] = 0;
202 len--;
203 }
204 return len;
205 }
206 }
207}
208
209
210/*****************************************************************************
211 * Name : GetSystemDirectoryW
212 * Purpose :
213 * Parameters:
214 * Variables :
215 * Result :
216 * Remark :
217 * Status :
218 *
219 * Author : Patrick Haller [Wed, 1999/09/28 20:44]
220 *****************************************************************************/
221
222ODINFUNCTION2(UINT,GetSystemDirectoryW,LPWSTR,lpBuffer,
223 UINT, uSize)
224{
225 char *asciibuffer = (char *)malloc(uSize+1);
226 UINT rc;
227
228 rc = GetSystemDirectoryA(asciibuffer, uSize);
229 if(rc) AsciiToUnicode(asciibuffer, lpBuffer);
230 free(asciibuffer);
231 return(rc);
232}
233
234
235/*****************************************************************************
236 * Name : GetWindowsDirectoryA
237 * Purpose :
238 * Parameters:
239 * Variables :
240 * Result :
241 * Remark :
242 * Status :
243 *
244 * Author : Patrick Haller [Wed, 1999/09/28 20:44]
245 *****************************************************************************/
246
247ODINFUNCTION2(UINT,GetWindowsDirectoryA,LPSTR,lpBuffer,
248 UINT,uSize)
249{
250 LPSTR lpstrEnv = getenv("WIN32.DIR.WINDOWS"); /* query environment */
251
252 if (lpstrEnv != NULL)
253 {
254 lstrcpynA(lpBuffer, /* copy environment variable to buffer */
255 lpstrEnv,
256 uSize);
257 return (lstrlenA(lpBuffer)); /* return number of copies bytes */
258 }
259 else
260 {
261 int len;
262
263 len = PROFILE_GetOdinIniString(ODINDIRECTORIES,"WINDOWS","",lpBuffer,uSize);
264 if (len > 2) {
265 if(lpBuffer[len-1] == '\\') {
266 lpBuffer[len-1] = 0;
267 len--;
268 }
269 return len;
270 }
271 else
272 /* if no override by environment is available */
273 return O32_GetWindowsDirectory(lpBuffer,uSize);
274 }
275}
276
277
278/*****************************************************************************
279 * Name : GetWindowsDirectoryW
280 * Purpose :
281 * Parameters:
282 * Variables :
283 * Result :
284 * Remark :
285 * Status :
286 *
287 * Author : Patrick Haller [Wed, 1999/09/28 20:44]
288 *****************************************************************************/
289
290ODINFUNCTION2(UINT,GetWindowsDirectoryW,LPWSTR,lpBuffer,
291 UINT, uSize)
292{
293 char *asciibuffer = (char *)malloc(uSize+1);
294 UINT rc;
295
296 rc = GetWindowsDirectoryA(asciibuffer, uSize);
297 AsciiToUnicode(asciibuffer, lpBuffer);
298 free(asciibuffer);
299 return(rc);
300}
301
302
303/*****************************************************************************
304 * Name : RemoveDirectoryA
305 * Purpose :
306 * Parameters:
307 * Variables :
308 * Result :
309 * Remark :
310 * Status :
311 *
312 * Author : Patrick Haller [Wed, 1999/09/28 20:44]
313 *****************************************************************************/
314
315ODINFUNCTION1(BOOL,RemoveDirectoryA,LPCSTR,arg1)
316{
317 return O32_RemoveDirectory(arg1);
318}
319
320
321/*****************************************************************************
322 * Name : RemoveDirectoryW
323 * Purpose :
324 * Parameters:
325 * Variables :
326 * Result :
327 * Remark :
328 * Status :
329 *
330 * Author : Patrick Haller [Wed, 1999/09/28 20:44]
331 *****************************************************************************/
332
333ODINFUNCTION1(BOOL,RemoveDirectoryW,LPCWSTR,lpPathName)
334{
335 char *asciipath;
336 BOOL rc;
337
338 asciipath = UnicodeToAsciiString((LPWSTR)lpPathName);
339 rc = RemoveDirectoryA(asciipath);
340 FreeAsciiString(asciipath);
341 return(rc);
342}
343
Note: See TracBrowser for help on using the repository browser.