Changeset 64 for trunk/src/helpers/dosh2.c
- Timestamp:
- Apr 26, 2001, 10:21:31 PM (24 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/helpers/dosh2.c
r59 r64 2359 2359 free(paResources); 2360 2360 return (NO_ERROR); 2361 } 2362 2363 /* 2364 * FindFile: 2365 * helper for doshFindExecutable. 2366 * 2367 *added V0.9.11 (2001-04-25) [umoeller] 2368 */ 2369 2370 APIRET FindFile(const char *pcszCommand, // in: command (e.g. "lvm") 2371 PSZ pszExecutable, // out: full path (e.g. "F:\os2\lvm.exe") 2372 ULONG cbExecutable) // in: sizeof (*pszExecutable) 2373 { 2374 APIRET arc = NO_ERROR; 2375 FILESTATUS3 fs3; 2376 2377 if ( (strchr(pcszCommand, '\\')) 2378 || (strchr(pcszCommand, ':')) 2379 ) 2380 { 2381 // looks like this is qualified: 2382 arc = DosQueryPathInfo((PSZ)pcszCommand, 2383 FIL_STANDARD, 2384 &fs3, 2385 sizeof(fs3)); 2386 if (!arc) 2387 if (!(fs3.attrFile & FILE_DIRECTORY)) 2388 strhncpy0(pszExecutable, 2389 pcszCommand, 2390 cbExecutable); 2391 else 2392 // directory: 2393 arc = ERROR_INVALID_EXE_SIGNATURE; 2394 } 2395 else 2396 // non-qualified: 2397 arc = DosSearchPath(SEARCH_IGNORENETERRS | SEARCH_ENVIRONMENT | SEARCH_CUR_DIRECTORY, 2398 "PATH", 2399 (PSZ)pcszCommand, 2400 pszExecutable, 2401 cbExecutable); 2402 2403 return (arc); 2404 } 2405 2406 /* 2407 *@@ doshFindExecutable: 2408 * this attempts to find an executable by doing the 2409 * following: 2410 * 2411 * 1) If pcszCommand appears to be qualified (i.e. contains 2412 * a backslash), this checks for whether the file exists. 2413 * 2414 * 2) If pcszCommand contains no backslash, this calls 2415 * DosSearchPath in order to find the full path of the 2416 * executable. 2417 * 2418 * papcszExtensions determines if additional searches are to be 2419 * performed if the file doesn't exist (case 1) or DosSearchPath 2420 * returned ERROR_FILE_NOT_FOUND (case 2). 2421 * This must point to an array of strings specifying the extra 2422 * extensions to search for. 2423 * 2424 * If both papcszExtensions and cExtensions are null, no 2425 * extra searches are performed. 2426 * 2427 * If this returns NO_ERROR, pszExecutable receives 2428 * the full path of the executable found by DosSearchPath. 2429 * Otherwise ERROR_FILE_NOT_FOUND is returned. 2430 * 2431 * Example: 2432 * 2433 + const char *aExtensions[] = { "EXE", 2434 + "COM", 2435 + "CMD" 2436 + }; 2437 + CHAR szExecutable[CCHMAXPATH]; 2438 + APIRET arc = doshFindExecutable("lvm", 2439 + szExecutable, 2440 + sizeof(szExecutable), 2441 + aExtensions, 2442 + 3); 2443 * 2444 *@@added V0.9.9 (2001-03-07) [umoeller] 2445 *@@changed V0.9.11 (2001-04-25) [umoeller]: this never worked for qualified pcszCommand's, fixed 2446 */ 2447 2448 APIRET doshFindExecutable(const char *pcszCommand, // in: command (e.g. "lvm") 2449 PSZ pszExecutable, // out: full path (e.g. "F:\os2\lvm.exe") 2450 ULONG cbExecutable, // in: sizeof (*pszExecutable) 2451 const char **papcszExtensions, // in: array of extensions (without dots) 2452 ULONG cExtensions) // in: array item count 2453 { 2454 APIRET arc = FindFile(pcszCommand, 2455 pszExecutable, 2456 cbExecutable); 2457 2458 if ( (arc == ERROR_FILE_NOT_FOUND) // not found? 2459 && (cExtensions) // any extra searches wanted? 2460 ) 2461 { 2462 // try additional things then 2463 PSZ psz2 = (PSZ)malloc(strlen(pcszCommand) + 20); 2464 if (psz2) 2465 { 2466 ULONG ul; 2467 for (ul = 0; 2468 ul < cExtensions; 2469 ul++) 2470 { 2471 const char *pcszExtThis = papcszExtensions[ul]; 2472 sprintf(psz2, "%s.%s", pcszCommand, pcszExtThis); 2473 arc = FindFile(psz2, 2474 pszExecutable, 2475 cbExecutable); 2476 if (arc != ERROR_FILE_NOT_FOUND) 2477 break; 2478 } 2479 2480 free(psz2); 2481 } 2482 else 2483 arc = ERROR_NOT_ENOUGH_MEMORY; 2484 } 2485 2486 return (arc); 2361 2487 } 2362 2488
Note:
See TracChangeset
for help on using the changeset viewer.