Changeset 1628 for trunk/src/kernel32/directory.cpp
- Timestamp:
- Nov 8, 1999, 2:43:13 PM (26 years ago)
- File:
-
- 1 edited
-
trunk/src/kernel32/directory.cpp (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kernel32/directory.cpp
r1490 r1628 1 /* $Id: directory.cpp,v 1. 8 1999-10-28 12:01:12 sandervl Exp $ */1 /* $Id: directory.cpp,v 1.9 1999-11-08 13:43:12 sandervl Exp $ */ 2 2 3 3 /* … … 6 6 * Copyright 1998 Sander van Leeuwen 7 7 * 8 * Parts based on Wine code (991031) (files\directory.c) 9 * 10 * DOS directories functions 11 * 12 * Copyright 1995 Alexandre Julliard 8 13 * 9 14 * Project Odin Software License can be found in LICENSE.TXT … … 24 29 #include <options.h> 25 30 #include "initterm.h" 31 #include <win\file.h> 32 #include <string.h> 33 #include "oslibdos.h" 26 34 27 35 ODINDEBUGCHANNEL(KERNEL32-DIRECTORY) 28 36 37 38 static char DIR_Windows[MAX_PATHNAME_LEN]; 39 static char DIR_System[MAX_PATHNAME_LEN]; 40 41 //****************************************************************************** 42 //****************************************************************************** 43 void InitDirectories() 44 { 45 GetWindowsDirectoryA((LPSTR)&DIR_Windows, sizeof(DIR_Windows)); 46 GetSystemDirectoryA((LPSTR)&DIR_System, sizeof(DIR_System)); 47 } 29 48 30 49 /***************************************************************************** … … 130 149 PSECURITY_ATTRIBUTES,arg2) 131 150 { 151 dprintf(("CreateDirectory %s", arg1)); 132 152 return O32_CreateDirectory(arg1, arg2); 133 153 } … … 342 362 } 343 363 364 /*********************************************************************** 365 * DIR_TryModulePath 366 * 367 * Helper function for DIR_SearchPath. 368 */ 369 static BOOL DIR_TryModulePath( LPCSTR name, char *full_name ) 370 { 371 char buffer[OFS_MAXPATHNAME]; 372 LPSTR p; 373 374 if (!GetModuleFileNameA( 0, buffer, sizeof(buffer) )) 375 buffer[0]='\0'; 376 377 if (!(p = strrchr( buffer, '\\' ))) return FALSE; 378 if (sizeof(buffer) - (++p - buffer) <= strlen(name)) return FALSE; 379 strcpy( p, name ); 380 381 return OSLibDosSearchPath(OSLIB_SEARCHFILE, NULL, buffer, full_name, MAX_PATHNAME_LEN); 382 } 383 384 385 /*********************************************************************** 386 * DIR_SearchPath 387 * 388 * Implementation of SearchPath32A. 'win32' specifies whether the search 389 * order is Win16 (module path last) or Win32 (module path first). 390 * 391 * FIXME: should return long path names. 392 */ 393 DWORD DIR_SearchPath( LPCSTR path, LPCSTR name, LPCSTR ext, 394 char *full_name ) 395 { 396 DWORD len; 397 LPCSTR p; 398 LPSTR tmp = NULL; 399 BOOL ret = TRUE; 400 401 /* First check the supplied parameters */ 402 403 p = strrchr( name, '.' ); 404 if (p && !strchr( p, '/' ) && !strchr( p, '\\' )) 405 ext = NULL; /* Ignore the specified extension */ 406 if ((*name && (name[1] == ':')) || 407 strchr( name, '/' ) || strchr( name, '\\' )) 408 path = NULL; /* Ignore path if name already contains a path */ 409 if (path && !*path) path = NULL; /* Ignore empty path */ 410 411 len = strlen(name); 412 if (ext) len += strlen(ext); 413 if (path) len += strlen(path) + 1; 414 415 /* Allocate a buffer for the file name and extension */ 416 417 if (path || ext) 418 { 419 if (!(tmp = (LPSTR)HeapAlloc( GetProcessHeap(), 0, len + 1 ))) 420 { 421 SetLastError( ERROR_OUTOFMEMORY ); 422 return 0; 423 } 424 if (path) 425 { 426 strcpy( tmp, path ); 427 strcat( tmp, "\\" ); 428 strcat( tmp, name ); 429 } 430 else strcpy( tmp, name ); 431 if (ext) strcat( tmp, ext ); 432 name = tmp; 433 } 434 435 /* If we have an explicit path, everything's easy */ 436 437 if (path || (*name && (name[1] == ':')) || 438 strchr( name, '/' ) || strchr( name, '\\' )) 439 { 440 ret = OSLibDosSearchPath(OSLIB_SEARCHFILE, NULL, (LPSTR)name, full_name, MAX_PATHNAME_LEN); 441 goto done; 442 } 443 444 /* Try the path of the current executable (for Win32 search order) */ 445 if (DIR_TryModulePath( name, full_name )) goto done; 446 447 /* Try the current directory */ 448 if (OSLibDosSearchPath(OSLIB_SEARCHCURDIR, NULL, (LPSTR)name, full_name, MAX_PATHNAME_LEN)) 449 goto done; 450 451 /* Try the Windows system directory */ 452 if (OSLibDosSearchPath(OSLIB_SEARCHDIR, (LPSTR)&DIR_System, (LPSTR)name, full_name, MAX_PATHNAME_LEN)) 453 goto done; 454 455 /* Try the Windows directory */ 456 if (OSLibDosSearchPath(OSLIB_SEARCHDIR, (LPSTR)&DIR_Windows, (LPSTR)name, full_name, MAX_PATHNAME_LEN)) 457 goto done; 458 459 /* Try all directories in path */ 460 ret = OSLibDosSearchPath(OSLIB_SEARCHENV, "PATH", (LPSTR)name, full_name, MAX_PATHNAME_LEN); 461 462 done: 463 if (tmp) HeapFree( GetProcessHeap(), 0, tmp ); 464 return ret; 465 } 466 467 468 /*********************************************************************** 469 * SearchPath32A [KERNEL32.447] 470 * 471 * Searches for a specified file in the search path. 472 * 473 * PARAMS 474 * path [I] Path to search 475 * name [I] Filename to search for. 476 * ext [I] File extension to append to file name. The first 477 * character must be a period. This parameter is 478 * specified only if the filename given does not 479 * contain an extension. 480 * buflen [I] size of buffer, in characters 481 * buffer [O] buffer for found filename 482 * lastpart [O] address of pointer to last used character in 483 * buffer (the final '\') 484 * 485 * RETURNS 486 * Success: length of string copied into buffer, not including 487 * terminating null character. If the filename found is 488 * longer than the length of the buffer, the length of the 489 * filename is returned. 490 * Failure: Zero 491 * 492 * NOTES 493 * Should call SetLastError(but currently doesn't). 494 */ 495 DWORD WINAPI SearchPathA(LPCSTR path, LPCSTR name, LPCSTR ext, DWORD buflen, 496 LPSTR buffer, LPSTR *lastpart ) 497 { 498 char full_name[MAX_PATHNAME_LEN]; 499 500 if (!DIR_SearchPath( path, name, ext, (LPSTR)full_name )) return 0; 501 lstrcpynA( buffer, (LPSTR)full_name, buflen-1); 502 buffer[buflen-2] = 0; 503 SetLastError(0); 504 return strlen(buffer); 505 } 506 507 508 /*********************************************************************** 509 * SearchPath32W (KERNEL32.448) 510 */ 511 DWORD WINAPI SearchPathW(LPCWSTR path, LPCWSTR name, LPCWSTR ext, 512 DWORD buflen, LPWSTR buffer, LPWSTR *lastpart ) 513 { 514 char full_name[MAX_PATHNAME_LEN]; 515 516 LPSTR pathA = HEAP_strdupWtoA( GetProcessHeap(), 0, path ); 517 LPSTR nameA = HEAP_strdupWtoA( GetProcessHeap(), 0, name ); 518 LPSTR extA = HEAP_strdupWtoA( GetProcessHeap(), 0, ext ); 519 DWORD ret = DIR_SearchPath( pathA, nameA, extA, (LPSTR)full_name ); 520 HeapFree( GetProcessHeap(), 0, extA ); 521 HeapFree( GetProcessHeap(), 0, nameA ); 522 HeapFree( GetProcessHeap(), 0, pathA ); 523 if (!ret) return 0; 524 525 lstrcpynAtoW( buffer, full_name, buflen-1 ); 526 buffer[buflen-2] = 0; 527 SetLastError(0); 528 return strlen(full_name); 529 }
Note:
See TracChangeset
for help on using the changeset viewer.
