| 394 | #define PATHSEP ';' |
| 395 | |
| 396 | FILE * |
| 397 | fopenp(const char *name, const char *mode) |
| 398 | { |
| 399 | char *bp, *pp, lastch = 0; |
| 400 | FILE *fp; |
| 401 | BPTR theLock; |
| 402 | char buf[BUFSIZ]; |
| 403 | |
| 404 | /* Try the default directory first. Then look along PATH. |
| 405 | */ |
| 406 | if (strlen(name) >= BUFSIZ) |
| 407 | return (NULL); |
| 408 | strcpy(buf, name); |
| 409 | if (theLock = Lock(buf, SHARED_LOCK)) { |
| 410 | UnLock(theLock); |
| 411 | if (fp = fopen(buf, mode)) |
| 412 | return fp; |
| 413 | } |
| 414 | pp = PATH; |
| 415 | while (pp && *pp) { |
| 416 | bp = buf; |
| 417 | while (*pp && *pp != PATHSEP) { |
| 418 | if (bp > buf + BUFSIZ - 1) |
| 419 | return (NULL); |
| 420 | lastch = *bp++ = *pp++; |
| 421 | } |
| 422 | if (lastch != ':' && lastch != '/' && bp != buf) |
| 423 | *bp++ = '/'; |
| 424 | if (bp + strlen(name) > buf + BUFSIZ - 1) |
| 425 | return (NULL); |
| 426 | strcpy(bp, name); |
| 427 | if (theLock = Lock(buf, SHARED_LOCK)) { |
| 428 | UnLock(theLock); |
| 429 | if (fp = fopen(buf, mode)) |
| 430 | return fp; |
| 431 | } |
| 432 | if (*pp) |
| 433 | pp++; |
| 434 | } |
| 435 | return NULL; |
| 436 | } |
| 437 | #endif /* MFLOPPY */ |
| 438 | |
| 439 | #ifdef CHDIR |