1 | /* $Id: directory.cpp,v 1.47 2003-01-03 16:34:33 sandervl Exp $ */
|
---|
2 |
|
---|
3 | /*
|
---|
4 | * Win32 Directory functions for OS/2
|
---|
5 | *
|
---|
6 | * Copyright 1998 Sander van Leeuwen
|
---|
7 | *
|
---|
8 | * NOTE: Directory creation has to be done in install program (odin\win)
|
---|
9 | *
|
---|
10 | * Parts based on Wine code (991031) (files\directory.c)
|
---|
11 | *
|
---|
12 | * DOS directories functions
|
---|
13 | *
|
---|
14 | * Copyright 1995 Alexandre Julliard
|
---|
15 | *
|
---|
16 | * TODO:
|
---|
17 | * - System/window directories should be created by install program!
|
---|
18 | *
|
---|
19 | * Project Odin Software License can be found in LICENSE.TXT
|
---|
20 | *
|
---|
21 | */
|
---|
22 |
|
---|
23 |
|
---|
24 | /*****************************************************************************
|
---|
25 | * Includes *
|
---|
26 | *****************************************************************************/
|
---|
27 |
|
---|
28 | #include <odin.h>
|
---|
29 | #include <odinwrap.h>
|
---|
30 | #include <os2win.h>
|
---|
31 | #include <stdlib.h>
|
---|
32 | #include <unicode.h>
|
---|
33 | #include <heapstring.h>
|
---|
34 | #include <options.h>
|
---|
35 | #include "initterm.h"
|
---|
36 | #include <win\file.h>
|
---|
37 | #include <string.h>
|
---|
38 | #include "oslibdos.h"
|
---|
39 | #include "profile.h"
|
---|
40 | #include "fileio.h"
|
---|
41 |
|
---|
42 | #define DBG_LOCALLOG DBG_directory
|
---|
43 | #include "dbglocal.h"
|
---|
44 |
|
---|
45 | ODINDEBUGCHANNEL(KERNEL32-DIRECTORY)
|
---|
46 |
|
---|
47 |
|
---|
48 | /*****************************************************************************
|
---|
49 | * Local Prototypes *
|
---|
50 | *****************************************************************************/
|
---|
51 |
|
---|
52 |
|
---|
53 | static char DIR_Windows[MAX_PATHNAME_LEN];
|
---|
54 | static char DIR_System[MAX_PATHNAME_LEN];
|
---|
55 | static BOOL fDirInit = FALSE;
|
---|
56 |
|
---|
57 | //******************************************************************************
|
---|
58 | //******************************************************************************
|
---|
59 | char *InternalGetWindowsDirectoryA()
|
---|
60 | {
|
---|
61 | return DIR_Windows;
|
---|
62 | }
|
---|
63 | //******************************************************************************
|
---|
64 | //******************************************************************************
|
---|
65 | char *InternalGetSystemDirectoryA()
|
---|
66 | {
|
---|
67 | return DIR_System;
|
---|
68 | }
|
---|
69 | //******************************************************************************
|
---|
70 | //******************************************************************************
|
---|
71 | void InitDirectories()
|
---|
72 | {
|
---|
73 | char *endofwinpath, *tmp;
|
---|
74 | int len;
|
---|
75 |
|
---|
76 | if(fDirInit == TRUE) return;
|
---|
77 |
|
---|
78 | fDirInit = TRUE;
|
---|
79 | strcpy(DIR_System, kernel32Path);
|
---|
80 | len = strlen(DIR_System);
|
---|
81 | if(DIR_System[len-1] == '\\') {
|
---|
82 | DIR_System[len-1] = 0;
|
---|
83 | }
|
---|
84 | len = PROFILE_GetOdinIniString(ODINDIRECTORIES,"WINDOWS","",DIR_Windows,sizeof(DIR_Windows));
|
---|
85 | if (len > 2) {
|
---|
86 | if(DIR_Windows[len-1] == '\\') {
|
---|
87 | DIR_Windows[len-1] = 0;
|
---|
88 | }
|
---|
89 | }
|
---|
90 | else {
|
---|
91 | strcpy(DIR_Windows, DIR_System);
|
---|
92 | endofwinpath = tmp = strchr(DIR_Windows, '\\');
|
---|
93 | while(tmp) {
|
---|
94 | tmp = strchr(endofwinpath+1, '\\');
|
---|
95 | if(tmp)
|
---|
96 | endofwinpath = tmp;
|
---|
97 | }
|
---|
98 | if(endofwinpath) {
|
---|
99 | *endofwinpath = 0; //remove \SYSTEM32
|
---|
100 | }
|
---|
101 | else DebugInt3();
|
---|
102 | }
|
---|
103 | dprintf(("Windows dir: %s", DIR_Windows));
|
---|
104 | dprintf(("System32 dir: %s", DIR_System));
|
---|
105 | }
|
---|
106 | //*****************************************************************************
|
---|
107 | //*****************************************************************************
|
---|
108 | void WIN32API InitDirectoriesCustom(char *szSystemDir, char *szWindowsDir)
|
---|
109 | {
|
---|
110 | int len;
|
---|
111 |
|
---|
112 | if(fDirInit == TRUE) return;
|
---|
113 | fDirInit = TRUE;
|
---|
114 |
|
---|
115 | strcpy(DIR_System, szSystemDir);
|
---|
116 | len = strlen(DIR_System);
|
---|
117 | if(DIR_System[len-1] == '\\') {
|
---|
118 | DIR_System[len-1] = 0;
|
---|
119 | }
|
---|
120 | strcpy(DIR_Windows, szWindowsDir);
|
---|
121 | len = strlen(DIR_Windows);
|
---|
122 | if(DIR_Windows[len-1] == '\\') {
|
---|
123 | DIR_Windows[len-1] = 0;
|
---|
124 | }
|
---|
125 |
|
---|
126 | dprintf(("Windows dir: %s", DIR_Windows));
|
---|
127 | dprintf(("System32 dir: %s", DIR_System));
|
---|
128 | }
|
---|
129 | /*****************************************************************************
|
---|
130 | * Name : GetCurrentDirectoryA
|
---|
131 | * Purpose : query the current directory
|
---|
132 | * Parameters:
|
---|
133 | * Variables :
|
---|
134 | * Result :
|
---|
135 | * Remark : returned length is number of characters required or used for current dir
|
---|
136 | * *excluding* terminator
|
---|
137 | * Status :
|
---|
138 | *
|
---|
139 | * Author : Patrick Haller [Wed, 1999/09/28 20:44]
|
---|
140 | *****************************************************************************/
|
---|
141 |
|
---|
142 | UINT WIN32API GetCurrentDirectoryA(UINT nBufferLength, LPSTR lpBuffer)
|
---|
143 | {
|
---|
144 | UINT rc;
|
---|
145 |
|
---|
146 | rc = OSLibDosQueryDir(nBufferLength, lpBuffer);
|
---|
147 | if(rc && rc < nBufferLength) {
|
---|
148 | dprintf(("CurrentDirectory = %s (%d)", lpBuffer, rc));
|
---|
149 | }
|
---|
150 | else dprintf(("CurrentDirectory returned %d", rc));
|
---|
151 | return rc;
|
---|
152 | }
|
---|
153 |
|
---|
154 |
|
---|
155 | /*****************************************************************************
|
---|
156 | * Name : GetCurrentDirectoryW
|
---|
157 | * Purpose : query the current directory
|
---|
158 | * Parameters:
|
---|
159 | * Variables :
|
---|
160 | * Result :
|
---|
161 | * Remark :
|
---|
162 | * Status :
|
---|
163 | *
|
---|
164 | * Author : Patrick Haller [Wed, 1999/09/28 20:44]
|
---|
165 | *****************************************************************************/
|
---|
166 |
|
---|
167 | UINT WIN32API GetCurrentDirectoryW(UINT nBufferLength, LPWSTR lpBuffer)
|
---|
168 | {
|
---|
169 | char *asciidir = (char *)malloc(nBufferLength+1);
|
---|
170 | int rc;
|
---|
171 |
|
---|
172 | rc = GetCurrentDirectoryA(nBufferLength, asciidir);
|
---|
173 | if(rc != 0)
|
---|
174 | AsciiToUnicode(asciidir, lpBuffer);
|
---|
175 | free(asciidir);
|
---|
176 | return(rc);
|
---|
177 | }
|
---|
178 |
|
---|
179 |
|
---|
180 | /*****************************************************************************
|
---|
181 | * Name : SetCurrentDirectoryA
|
---|
182 | * Purpose :
|
---|
183 | * Parameters:
|
---|
184 | * Variables :
|
---|
185 | * Result :
|
---|
186 | * Remark :
|
---|
187 | * Status :
|
---|
188 | *
|
---|
189 | * Author : Patrick Haller [Wed, 1999/09/28 20:44]
|
---|
190 | *****************************************************************************/
|
---|
191 | BOOL WIN32API SetCurrentDirectoryA(LPCSTR lpstrDirectory)
|
---|
192 | {
|
---|
193 | if(HIWORD(lpstrDirectory) == 0)
|
---|
194 | {
|
---|
195 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
196 | return FALSE;
|
---|
197 | }
|
---|
198 |
|
---|
199 | // cut off trailing backslashes
|
---|
200 | // not if a process wants to change to the root directory
|
---|
201 | int len = lstrlenA(lpstrDirectory);
|
---|
202 | if ( ( (lpstrDirectory[len - 1] == '\\') ||
|
---|
203 | (lpstrDirectory[len - 1] == '/') ) &&
|
---|
204 | (len != 1) )
|
---|
205 | {
|
---|
206 | LPSTR lpTemp = (LPSTR)_alloca(len);
|
---|
207 | lstrcpynA(lpTemp,
|
---|
208 | lpstrDirectory,
|
---|
209 | len); // len is including trailing NULL!!
|
---|
210 | lpstrDirectory = lpTemp;
|
---|
211 | }
|
---|
212 |
|
---|
213 | dprintf(("SetCurrentDirectoryA %s", lpstrDirectory));
|
---|
214 | return O32_SetCurrentDirectory((LPSTR)lpstrDirectory);
|
---|
215 | }
|
---|
216 |
|
---|
217 |
|
---|
218 | /*****************************************************************************
|
---|
219 | * Name : SetCurrentDirectoryW
|
---|
220 | * Purpose :
|
---|
221 | * Parameters:
|
---|
222 | * Variables :
|
---|
223 | * Result :
|
---|
224 | * Remark :
|
---|
225 | * Status :
|
---|
226 | *
|
---|
227 | * Author : Patrick Haller [Wed, 1999/09/28 20:44]
|
---|
228 | *****************************************************************************/
|
---|
229 |
|
---|
230 | BOOL WIN32API SetCurrentDirectoryW(LPCWSTR lpPathName)
|
---|
231 | {
|
---|
232 | char *asciipath;
|
---|
233 | BOOL rc;
|
---|
234 |
|
---|
235 | asciipath = UnicodeToAsciiString((LPWSTR)lpPathName);
|
---|
236 | rc = SetCurrentDirectoryA(asciipath);
|
---|
237 | FreeAsciiString(asciipath);
|
---|
238 | return(rc);
|
---|
239 | }
|
---|
240 |
|
---|
241 |
|
---|
242 | /*****************************************************************************
|
---|
243 | * Name : CreateDirectoryA
|
---|
244 | * Purpose :
|
---|
245 | * Parameters:
|
---|
246 | * Variables :
|
---|
247 | * Result :
|
---|
248 | * Remark :
|
---|
249 | * Status :
|
---|
250 | *
|
---|
251 | * Author : Patrick Haller [Wed, 1999/09/28 20:44]
|
---|
252 | *****************************************************************************/
|
---|
253 |
|
---|
254 | BOOL WIN32API CreateDirectoryA(LPCSTR lpstrDirectory, PSECURITY_ATTRIBUTES arg2)
|
---|
255 | {
|
---|
256 | // 2001-05-28 PH
|
---|
257 | // verify filename first (NT4SP6)
|
---|
258 | // @@@PH: if (IsBadStringPtr( (LPVOID)lpstrDirectory, 0xFFFF))
|
---|
259 | if (lpstrDirectory == NULL)
|
---|
260 | {
|
---|
261 | SetLastError(ERROR_PATH_NOT_FOUND);
|
---|
262 | return FALSE;
|
---|
263 | }
|
---|
264 |
|
---|
265 | int len = strlen(lpstrDirectory);
|
---|
266 |
|
---|
267 | // cut off trailing backslashes
|
---|
268 | if ( (lpstrDirectory[len - 1] == '\\') ||
|
---|
269 | (lpstrDirectory[len - 1] == '/') )
|
---|
270 | {
|
---|
271 | LPSTR lpTemp = (LPSTR)_alloca(len);
|
---|
272 | lstrcpynA(lpTemp,
|
---|
273 | lpstrDirectory,
|
---|
274 | len ); // len is including trailing NULL!!
|
---|
275 | lpstrDirectory = lpTemp;
|
---|
276 | }
|
---|
277 |
|
---|
278 | dprintf(("CreateDirectoryA %s", lpstrDirectory));
|
---|
279 |
|
---|
280 | // Creation of an existing directory will fail (verified in NT4 & XP)
|
---|
281 | DWORD dwAttr = GetFileAttributesA(lpstrDirectory);
|
---|
282 | if(dwAttr != -1)
|
---|
283 | {
|
---|
284 | if (dwAttr & FILE_ATTRIBUTE_DIRECTORY)
|
---|
285 | {
|
---|
286 | SetLastError(ERROR_ALREADY_EXISTS);
|
---|
287 | return FALSE;
|
---|
288 | }
|
---|
289 | }
|
---|
290 | return(OSLibDosCreateDirectory(lpstrDirectory));
|
---|
291 | }
|
---|
292 |
|
---|
293 | /*****************************************************************************
|
---|
294 | * Name : CreateDirectoryW
|
---|
295 | * Purpose :
|
---|
296 | * Parameters:
|
---|
297 | * Variables :
|
---|
298 | * Result :
|
---|
299 | * Remark :
|
---|
300 | * Status :
|
---|
301 | *
|
---|
302 | * Author : Patrick Haller [Wed, 1999/09/28 20:44]
|
---|
303 | *****************************************************************************/
|
---|
304 |
|
---|
305 | BOOL WIN32API CreateDirectoryW(LPCWSTR arg1, PSECURITY_ATTRIBUTES arg2)
|
---|
306 | {
|
---|
307 | BOOL rc;
|
---|
308 | char *astring;
|
---|
309 |
|
---|
310 | astring = UnicodeToAsciiString((LPWSTR)arg1);
|
---|
311 | rc = CreateDirectoryA(astring, arg2);
|
---|
312 | FreeAsciiString(astring);
|
---|
313 | return(rc);
|
---|
314 | }
|
---|
315 |
|
---|
316 | /*****************************************************************************
|
---|
317 | * Name : BOOL WIN32API CreateDirectoryExA
|
---|
318 | * Purpose : The CreateDirectoryExA function creates a new directory with a
|
---|
319 | * specified path that retains the attributes of a specified
|
---|
320 | * template directory. If the underlying file system supports
|
---|
321 | * security on files and directories, the function applies a
|
---|
322 | * specified security descriptor to the new directory.
|
---|
323 | * The new directory retains the other attributes of the specified
|
---|
324 | * template directory. Note that CreateDirectoryEx has a template
|
---|
325 | * parameter, while CreateDirectory does not.
|
---|
326 | * Parameters: LPCSTR lpTemplateDirectory pointer to path string of template
|
---|
327 | * directory
|
---|
328 | * LPCSTR lpNewDirectory pointer to path string of directory
|
---|
329 | * to create
|
---|
330 | * LPSECURITY_ATTRIBUTES lpSecurityAttributes pointer to security
|
---|
331 | * descriptor
|
---|
332 | *
|
---|
333 | * Variables :
|
---|
334 | * Result : If the function succeeds, the return value is nonzero.
|
---|
335 | * If the function fails, the return value is zero.
|
---|
336 | * To get extended error information, call GetLastError.
|
---|
337 | * Remark :
|
---|
338 | * Status : UNTESTED STUB
|
---|
339 | *
|
---|
340 | * Author : Markus Montkowski [Tha, 1998/05/21 17:46]
|
---|
341 | *****************************************************************************/
|
---|
342 |
|
---|
343 | BOOL WIN32API CreateDirectoryExA( LPCSTR lpTemplateDirectory,
|
---|
344 | LPCSTR lpNewDirectory,
|
---|
345 | LPSECURITY_ATTRIBUTES lpSecurityAttributes)
|
---|
346 | {
|
---|
347 |
|
---|
348 | dprintf(("KERNEL32:CreateDirectoryExA(%08x,%08x,%08x) not properly implemented\n",
|
---|
349 | lpTemplateDirectory,lpNewDirectory,lpSecurityAttributes
|
---|
350 | ));
|
---|
351 |
|
---|
352 | return CreateDirectoryA(lpNewDirectory, lpSecurityAttributes);
|
---|
353 | }
|
---|
354 |
|
---|
355 | /*****************************************************************************
|
---|
356 | * Name : BOOL WIN32API CreateDirectoryExW
|
---|
357 | * Purpose : The CreateDirectoryExW function creates a new directory with a
|
---|
358 | * specified path that retains the attributes of a specified
|
---|
359 | * template directory. If the underlying file system supports
|
---|
360 | * security on files and directories, the function applies a
|
---|
361 | * specified security descriptor to the new directory.
|
---|
362 | * The new directory retains the other attributes of the specified
|
---|
363 | * template directory. Note that CreateDirectoryEx has a template
|
---|
364 | * parameter, while CreateDirectory does not.
|
---|
365 | * Parameters: LPCWSTR lpTemplateDirectory pointer to path string of template
|
---|
366 | * directory
|
---|
367 | * LPCWSTR lpNewDirectory pointer to path string of directory
|
---|
368 | * to create
|
---|
369 | * LPSECURITY_ATTRIBUTES lpSecurityAttributes pointer to security
|
---|
370 | * descriptor
|
---|
371 | *
|
---|
372 | * Variables :
|
---|
373 | * Result : If the function succeeds, the return value is nonzero.
|
---|
374 | * If the function fails, the return value is zero.
|
---|
375 | * To get extended error information, call GetLastError.
|
---|
376 | * Remark :
|
---|
377 | * Status : UNTESTED STUB
|
---|
378 | *
|
---|
379 | * Author : Markus Montkowski [Tha, 1998/05/21 17:46]
|
---|
380 | *****************************************************************************/
|
---|
381 |
|
---|
382 | BOOL WIN32API CreateDirectoryExW( LPCWSTR lpTemplateDirectory,
|
---|
383 | LPCWSTR lpNewDirectory,
|
---|
384 | LPSECURITY_ATTRIBUTES lpSecurityAttributes)
|
---|
385 | {
|
---|
386 |
|
---|
387 | dprintf(("KERNEL32:CreateDirectoryExW(%08x,%08x,%08x) not properly implemented\n",
|
---|
388 | lpTemplateDirectory,lpNewDirectory,lpSecurityAttributes
|
---|
389 | ));
|
---|
390 |
|
---|
391 | return CreateDirectoryW(lpNewDirectory, lpSecurityAttributes);
|
---|
392 | }
|
---|
393 |
|
---|
394 | /*****************************************************************************
|
---|
395 | * Name : GetSystemDirectoryA
|
---|
396 | * Purpose :
|
---|
397 | * Parameters:
|
---|
398 | * Variables :
|
---|
399 | * Result :
|
---|
400 | * Remark : Should return length of system dir even if lpBuffer == NULL
|
---|
401 | * Status :
|
---|
402 | *
|
---|
403 | * Author : Patrick Haller [Wed, 1999/09/28 20:44]
|
---|
404 | *****************************************************************************/
|
---|
405 |
|
---|
406 | UINT WIN32API GetSystemDirectoryA(LPSTR lpBuffer, UINT uSize)
|
---|
407 | {
|
---|
408 | int len;
|
---|
409 | char *dir;
|
---|
410 |
|
---|
411 | dir = InternalGetSystemDirectoryA();
|
---|
412 | len = lstrlenA(dir);
|
---|
413 | if(lpBuffer)
|
---|
414 | lstrcpynA(lpBuffer, dir, uSize);
|
---|
415 | return len;
|
---|
416 | }
|
---|
417 |
|
---|
418 |
|
---|
419 | /*****************************************************************************
|
---|
420 | * Name : GetSystemDirectoryW
|
---|
421 | * Purpose :
|
---|
422 | * Parameters:
|
---|
423 | * Variables :
|
---|
424 | * Result :
|
---|
425 | * Remark : Should return length of system dir even if lpBuffer == NULL
|
---|
426 | * Status :
|
---|
427 | *
|
---|
428 | * Author : Patrick Haller [Wed, 1999/09/28 20:44]
|
---|
429 | *****************************************************************************/
|
---|
430 |
|
---|
431 | UINT WIN32API GetSystemDirectoryW(LPWSTR lpBuffer, UINT uSize)
|
---|
432 | {
|
---|
433 | char *asciibuffer = NULL;
|
---|
434 | UINT rc;
|
---|
435 |
|
---|
436 | if(lpBuffer)
|
---|
437 | asciibuffer = (char *)alloca(uSize+1);
|
---|
438 |
|
---|
439 | if(lpBuffer && asciibuffer == NULL)
|
---|
440 | {
|
---|
441 | DebugInt3();
|
---|
442 | }
|
---|
443 |
|
---|
444 | rc = GetSystemDirectoryA(asciibuffer, uSize);
|
---|
445 | if(rc && asciibuffer)
|
---|
446 | AsciiToUnicode(asciibuffer, lpBuffer);
|
---|
447 |
|
---|
448 | return(rc);
|
---|
449 | }
|
---|
450 |
|
---|
451 |
|
---|
452 | /*****************************************************************************
|
---|
453 | * Name : GetWindowsDirectoryA
|
---|
454 | * Purpose :
|
---|
455 | * Parameters:
|
---|
456 | * Variables :
|
---|
457 | * Result :
|
---|
458 | * Remark : Should return length of system dir even if lpBuffer == NULL
|
---|
459 | * Status :
|
---|
460 | *
|
---|
461 | * Author : Patrick Haller [Wed, 1999/09/28 20:44]
|
---|
462 | *****************************************************************************/
|
---|
463 |
|
---|
464 | UINT WIN32API GetWindowsDirectoryA(LPSTR lpBuffer, UINT uSize)
|
---|
465 | {
|
---|
466 | char *dir;
|
---|
467 | int len;
|
---|
468 |
|
---|
469 | dir = InternalGetWindowsDirectoryA();
|
---|
470 | len = lstrlenA(dir);
|
---|
471 | if(lpBuffer)
|
---|
472 | lstrcpynA(lpBuffer, dir, uSize);
|
---|
473 | return len;
|
---|
474 | }
|
---|
475 |
|
---|
476 |
|
---|
477 | /*****************************************************************************
|
---|
478 | * Name : GetWindowsDirectoryW
|
---|
479 | * Purpose :
|
---|
480 | * Parameters:
|
---|
481 | * Variables :
|
---|
482 | * Result :
|
---|
483 | * Remark : Should return length of system dir even if lpBuffer == NULL
|
---|
484 | * Status :
|
---|
485 | *
|
---|
486 | * Author : Patrick Haller [Wed, 1999/09/28 20:44]
|
---|
487 | *****************************************************************************/
|
---|
488 |
|
---|
489 | UINT WIN32API GetWindowsDirectoryW(LPWSTR lpBuffer, UINT uSize)
|
---|
490 | {
|
---|
491 | char *asciibuffer = NULL;
|
---|
492 | UINT rc;
|
---|
493 |
|
---|
494 | if(lpBuffer)
|
---|
495 | asciibuffer = (char *)alloca(uSize+1);
|
---|
496 |
|
---|
497 | if(lpBuffer && asciibuffer == NULL)
|
---|
498 | {
|
---|
499 | DebugInt3();
|
---|
500 | }
|
---|
501 |
|
---|
502 | rc = GetWindowsDirectoryA(asciibuffer, uSize);
|
---|
503 | if(rc && asciibuffer)
|
---|
504 | AsciiToUnicode(asciibuffer, lpBuffer);
|
---|
505 |
|
---|
506 | return(rc);
|
---|
507 | }
|
---|
508 |
|
---|
509 |
|
---|
510 | /*****************************************************************************
|
---|
511 | * Name : RemoveDirectoryA
|
---|
512 | * Purpose :
|
---|
513 | * Parameters:
|
---|
514 | * Variables :
|
---|
515 | * Result :
|
---|
516 | * Remark :
|
---|
517 | * Status :
|
---|
518 | *
|
---|
519 | * Author : Patrick Haller [Wed, 1999/09/28 20:44]
|
---|
520 | *****************************************************************************/
|
---|
521 |
|
---|
522 |
|
---|
523 | BOOL WIN32API RemoveDirectoryA(LPCSTR lpstrDirectory)
|
---|
524 | {
|
---|
525 | int len = strlen(lpstrDirectory);
|
---|
526 |
|
---|
527 | if(lpstrDirectory == NULL) {
|
---|
528 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
529 | return FALSE;
|
---|
530 | }
|
---|
531 | // cut off trailing backslashes
|
---|
532 | if ( (lpstrDirectory[len - 1] == '\\') ||
|
---|
533 | (lpstrDirectory[len - 1] == '/') )
|
---|
534 | {
|
---|
535 | LPSTR lpTemp = (LPSTR)_alloca(len);
|
---|
536 | lstrcpynA(lpTemp,
|
---|
537 | lpstrDirectory,
|
---|
538 | len ); // len is including trailing NULL!!
|
---|
539 | lpstrDirectory = lpTemp;
|
---|
540 | }
|
---|
541 |
|
---|
542 | dprintf(("RemoveDirectory %s", lpstrDirectory));
|
---|
543 |
|
---|
544 | return OSLibDosRemoveDir(lpstrDirectory);
|
---|
545 | }
|
---|
546 |
|
---|
547 |
|
---|
548 | /*****************************************************************************
|
---|
549 | * Name : RemoveDirectoryW
|
---|
550 | * Purpose :
|
---|
551 | * Parameters:
|
---|
552 | * Variables :
|
---|
553 | * Result :
|
---|
554 | * Remark :
|
---|
555 | * Status :
|
---|
556 | *
|
---|
557 | * Author : Patrick Haller [Wed, 1999/09/28 20:44]
|
---|
558 | *****************************************************************************/
|
---|
559 |
|
---|
560 | BOOL WIN32API RemoveDirectoryW(LPCWSTR lpPathName)
|
---|
561 | {
|
---|
562 | char *asciipath;
|
---|
563 | BOOL rc;
|
---|
564 |
|
---|
565 | asciipath = UnicodeToAsciiString((LPWSTR)lpPathName);
|
---|
566 | rc = RemoveDirectoryA(asciipath);
|
---|
567 | FreeAsciiString(asciipath);
|
---|
568 | return(rc);
|
---|
569 | }
|
---|
570 |
|
---|
571 | /***********************************************************************
|
---|
572 | * DIR_TryModulePath
|
---|
573 | *
|
---|
574 | * Helper function for DIR_SearchPath.
|
---|
575 | */
|
---|
576 | static BOOL DIR_TryModulePath( LPCSTR name, char *full_name )
|
---|
577 | {
|
---|
578 | char buffer[OFS_MAXPATHNAME];
|
---|
579 | LPSTR p;
|
---|
580 |
|
---|
581 | if (!GetModuleFileNameA( 0, buffer, sizeof(buffer) ))
|
---|
582 | buffer[0]='\0';
|
---|
583 |
|
---|
584 | if (!(p = strrchr( buffer, '\\' ))) return FALSE;
|
---|
585 | if (sizeof(buffer) - (++p - buffer) <= strlen(name)) return FALSE;
|
---|
586 | strcpy( p, name );
|
---|
587 |
|
---|
588 | return OSLibDosSearchPath(OSLIB_SEARCHFILE, NULL, buffer, full_name, MAX_PATHNAME_LEN);
|
---|
589 | }
|
---|
590 |
|
---|
591 |
|
---|
592 | /***********************************************************************
|
---|
593 | * DIR_SearchPath
|
---|
594 | *
|
---|
595 | * Implementation of SearchPath32A. 'win32' specifies whether the search
|
---|
596 | * order is Win16 (module path last) or Win32 (module path first).
|
---|
597 | *
|
---|
598 | * FIXME: should return long path names.
|
---|
599 | */
|
---|
600 | DWORD DIR_SearchPath( LPCSTR path, LPCSTR name, LPCSTR ext,
|
---|
601 | char *full_name )
|
---|
602 | {
|
---|
603 | DWORD len;
|
---|
604 | LPCSTR p;
|
---|
605 | LPSTR tmp = NULL;
|
---|
606 | BOOL ret = TRUE;
|
---|
607 |
|
---|
608 | /* First check the supplied parameters */
|
---|
609 |
|
---|
610 | p = strrchr( name, '.' );
|
---|
611 | if (p && !strchr( p, '/' ) && !strchr( p, '\\' ))
|
---|
612 | ext = NULL; /* Ignore the specified extension */
|
---|
613 | if ((*name && (name[1] == ':')) ||
|
---|
614 | strchr( name, '/' ) || strchr( name, '\\' ))
|
---|
615 | path = NULL; /* Ignore path if name already contains a path */
|
---|
616 | if (path && !*path) path = NULL; /* Ignore empty path */
|
---|
617 |
|
---|
618 | /* See if path is a list of directories to search. If so, only search
|
---|
619 | those (according to SDK docs) */
|
---|
620 | if ((path != NULL) && strchr(path, ';')) {
|
---|
621 | ret = OSLibDosSearchPath(OSLIB_SEARCHDIR, (LPSTR)path, (LPSTR)name,
|
---|
622 | full_name, MAX_PATHNAME_LEN);
|
---|
623 | goto done;
|
---|
624 | }
|
---|
625 |
|
---|
626 | len = strlen(name);
|
---|
627 | if (ext) len += strlen(ext);
|
---|
628 | if (path) len += strlen(path) + 1;
|
---|
629 |
|
---|
630 | /* Allocate a buffer for the file name and extension */
|
---|
631 |
|
---|
632 | if (path || ext)
|
---|
633 | {
|
---|
634 | if (!(tmp = (LPSTR)HeapAlloc( GetProcessHeap(), 0, len + 1 )))
|
---|
635 | {
|
---|
636 | SetLastError( ERROR_OUTOFMEMORY );
|
---|
637 | return 0;
|
---|
638 | }
|
---|
639 | if (path)
|
---|
640 | {
|
---|
641 | strcpy( tmp, path );
|
---|
642 | strcat( tmp, "\\" );
|
---|
643 | strcat( tmp, name );
|
---|
644 | }
|
---|
645 | else strcpy( tmp, name );
|
---|
646 | if (ext) strcat( tmp, ext );
|
---|
647 | name = tmp;
|
---|
648 | }
|
---|
649 |
|
---|
650 | /* If we have an explicit path, everything's easy */
|
---|
651 |
|
---|
652 | if (path || (*name && (name[1] == ':')) ||
|
---|
653 | strchr( name, '/' ) || strchr( name, '\\' ))
|
---|
654 | {
|
---|
655 | ret = OSLibDosSearchPath(OSLIB_SEARCHFILE, NULL, (LPSTR)name, full_name, MAX_PATHNAME_LEN);
|
---|
656 | goto done;
|
---|
657 | }
|
---|
658 |
|
---|
659 | /* Try the path of the current executable (for Win32 search order) */
|
---|
660 | if (DIR_TryModulePath( name, full_name )) goto done;
|
---|
661 |
|
---|
662 | /* Try the current directory */
|
---|
663 | if (OSLibDosSearchPath(OSLIB_SEARCHCURDIR, NULL, (LPSTR)name, full_name, MAX_PATHNAME_LEN))
|
---|
664 | goto done;
|
---|
665 |
|
---|
666 | /* Try the Windows system directory */
|
---|
667 | if (OSLibDosSearchPath(OSLIB_SEARCHDIR, (LPSTR)&DIR_System, (LPSTR)name, full_name, MAX_PATHNAME_LEN))
|
---|
668 | goto done;
|
---|
669 |
|
---|
670 | /* Try the Windows directory */
|
---|
671 | if (OSLibDosSearchPath(OSLIB_SEARCHDIR, (LPSTR)&DIR_Windows, (LPSTR)name, full_name, MAX_PATHNAME_LEN))
|
---|
672 | goto done;
|
---|
673 |
|
---|
674 | /* Try all directories in path */
|
---|
675 | ret = OSLibDosSearchPath(OSLIB_SEARCHENV, "PATH", (LPSTR)name, full_name, MAX_PATHNAME_LEN);
|
---|
676 |
|
---|
677 | done:
|
---|
678 | if (tmp) HeapFree( GetProcessHeap(), 0, tmp );
|
---|
679 | return ret;
|
---|
680 | }
|
---|
681 |
|
---|
682 |
|
---|
683 | /***********************************************************************
|
---|
684 | * SearchPath32A [KERNEL32.447]
|
---|
685 | *
|
---|
686 | * Searches for a specified file in the search path.
|
---|
687 | *
|
---|
688 | * PARAMS
|
---|
689 | * path [I] Path to search
|
---|
690 | * name [I] Filename to search for.
|
---|
691 | * ext [I] File extension to append to file name. The first
|
---|
692 | * character must be a period. This parameter is
|
---|
693 | * specified only if the filename given does not
|
---|
694 | * contain an extension.
|
---|
695 | * buflen [I] size of buffer, in characters
|
---|
696 | * buffer [O] buffer for found filename
|
---|
697 | * lastpart [O] address of pointer to last used character in
|
---|
698 | * buffer (the final '\')
|
---|
699 | *
|
---|
700 | * RETURNS
|
---|
701 | * Success: length of string copied into buffer, not including
|
---|
702 | * terminating null character. If the filename found is
|
---|
703 | * longer than the length of the buffer, the length of the
|
---|
704 | * filename is returned.
|
---|
705 | * Failure: Zero
|
---|
706 | *
|
---|
707 | * NOTES
|
---|
708 | * Should call SetLastError(but currently doesn't).
|
---|
709 | */
|
---|
710 | DWORD WINAPI SearchPathA(LPCSTR path, LPCSTR name, LPCSTR ext, DWORD buflen,
|
---|
711 | LPSTR buffer, LPSTR *lastpart )
|
---|
712 | {
|
---|
713 | char full_name[MAX_PATHNAME_LEN];
|
---|
714 |
|
---|
715 | dprintf(("SearchPathA %s %s %s", path, name, ext));
|
---|
716 | if (!DIR_SearchPath( path, name, ext, (LPSTR)full_name )) return 0;
|
---|
717 | lstrcpynA( buffer, (LPSTR)full_name, buflen);
|
---|
718 | SetLastError(0);
|
---|
719 | return strlen(full_name);
|
---|
720 | }
|
---|
721 |
|
---|
722 |
|
---|
723 | /***********************************************************************
|
---|
724 | * SearchPath32W (KERNEL32.448)
|
---|
725 | */
|
---|
726 | DWORD WINAPI SearchPathW(LPCWSTR path, LPCWSTR name, LPCWSTR ext,
|
---|
727 | DWORD buflen, LPWSTR buffer, LPWSTR *lastpart )
|
---|
728 | {
|
---|
729 | char full_name[MAX_PATHNAME_LEN];
|
---|
730 |
|
---|
731 | LPSTR pathA = HEAP_strdupWtoA( GetProcessHeap(), 0, path );
|
---|
732 | LPSTR nameA = HEAP_strdupWtoA( GetProcessHeap(), 0, name );
|
---|
733 | LPSTR extA = HEAP_strdupWtoA( GetProcessHeap(), 0, ext );
|
---|
734 |
|
---|
735 | dprintf(("SearchPathA %s %s %s", pathA, nameA, extA));
|
---|
736 | DWORD ret = DIR_SearchPath( pathA, nameA, extA, (LPSTR)full_name );
|
---|
737 |
|
---|
738 | if (NULL != extA)
|
---|
739 | HeapFree( GetProcessHeap(), 0, extA );
|
---|
740 |
|
---|
741 | if (NULL != nameA)
|
---|
742 | HeapFree( GetProcessHeap(), 0, nameA );
|
---|
743 |
|
---|
744 | if (NULL != pathA)
|
---|
745 | HeapFree( GetProcessHeap(), 0, pathA );
|
---|
746 |
|
---|
747 | if (!ret) return 0;
|
---|
748 |
|
---|
749 | lstrcpynAtoW( buffer, full_name, buflen);
|
---|
750 | SetLastError(0);
|
---|
751 | return ret;
|
---|
752 | }
|
---|
753 | //******************************************************************************
|
---|
754 | //******************************************************************************
|
---|
755 | UINT WIN32API GetTempPathA(UINT count, LPSTR path)
|
---|
756 | {
|
---|
757 | UINT ret;
|
---|
758 | if (!(ret = GetEnvironmentVariableA( "TMP", path, count )))
|
---|
759 | if (!(ret = GetEnvironmentVariableA( "TEMP", path, count )))
|
---|
760 | if (!(ret = GetCurrentDirectoryA( count, path )))
|
---|
761 | return 0;
|
---|
762 | if (count && (ret < count - 1) && (path[ret-1] != '\\'))
|
---|
763 | {
|
---|
764 | path[ret++] = '\\';
|
---|
765 | path[ret] = '\0';
|
---|
766 | }
|
---|
767 | return ret;
|
---|
768 | }
|
---|
769 | //******************************************************************************
|
---|
770 | //******************************************************************************
|
---|
771 | UINT WIN32API GetTempPathW(UINT count, LPWSTR path)
|
---|
772 | {
|
---|
773 | static const WCHAR tmp[] = { 'T', 'M', 'P', 0 };
|
---|
774 | static const WCHAR temp[] = { 'T', 'E', 'M', 'P', 0 };
|
---|
775 | UINT ret;
|
---|
776 | if (!(ret = GetEnvironmentVariableW( tmp, path, count )))
|
---|
777 | if (!(ret = GetEnvironmentVariableW( temp, path, count )))
|
---|
778 | if (!(ret = GetCurrentDirectoryW( count, path )))
|
---|
779 | return 0;
|
---|
780 | if (count && (ret < count - 1) && (path[ret-1] != '\\'))
|
---|
781 | {
|
---|
782 | path[ret++] = '\\';
|
---|
783 | path[ret] = '\0';
|
---|
784 | }
|
---|
785 | return ret;
|
---|
786 | }
|
---|
787 | //******************************************************************************
|
---|
788 | //******************************************************************************
|
---|