Mercurial > hg > toybox
comparison lib/lib.c @ 295:5a0faa267866
Fix which (the meaning of -a was reversed, and it was finding the _last_ hit).
author | Rob Landley <rob@landley.net> |
---|---|
date | Sat, 17 May 2008 17:52:51 -0500 |
parents | b4077be6c746 |
children | 52600eee8dd6 |
comparison
equal
deleted
inserted
replaced
294:3de1ea4d6b56 | 295:5a0faa267866 |
---|---|
362 // X_OK or R_OK). Returns a list of absolute paths to each file found, in | 362 // X_OK or R_OK). Returns a list of absolute paths to each file found, in |
363 // order. | 363 // order. |
364 | 364 |
365 struct string_list *find_in_path(char *path, char *filename) | 365 struct string_list *find_in_path(char *path, char *filename) |
366 { | 366 { |
367 struct string_list *rlist = NULL; | 367 struct string_list *rlist = NULL, **prlist=&rlist; |
368 char *cwd = xgetcwd(); | 368 char *cwd = xgetcwd(); |
369 | 369 |
370 for (;;) { | 370 for (;;) { |
371 char *next = path ? index(path, ':') : NULL; | 371 char *next = path ? index(path, ':') : NULL; |
372 int len = next ? next-path : strlen(path); | 372 int len = next ? next-path : strlen(path); |
384 strcpy(res, filename); | 384 strcpy(res, filename); |
385 } | 385 } |
386 | 386 |
387 // Confirm it's not a directory. | 387 // Confirm it's not a directory. |
388 if (!stat(rnext->str, &st) && S_ISREG(st.st_mode)) { | 388 if (!stat(rnext->str, &st) && S_ISREG(st.st_mode)) { |
389 rnext->next = rlist; | 389 *prlist = rnext; |
390 rlist = rnext; | 390 rnext->next = NULL; |
391 prlist = &(rnext->next); | |
391 } else free(rnext); | 392 } else free(rnext); |
392 | 393 |
393 if (!next) break; | 394 if (!next) break; |
394 path += len; | 395 path += len; |
395 path++; | 396 path++; |