home *** CD-ROM | disk | FTP | other *** search
/ Magazyn Amiga 13 / MA_Cover_13.bin / source / c / stefanb_src / dospath / src / find.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-25  |  1.4 KB  |  64 lines

  1. /*
  2.  * find.c  V1.0
  3.  *
  4.  * Find a file in a path list
  5.  *
  6.  * (c) 1996 Stefan Becker
  7.  */
  8.  
  9. #include "dospath.h"
  10.  
  11. __geta4 BPTR FindFileInPathList(__A0 struct PathListEntry **anchor,
  12.                                 __A1 const char *file,
  13.                                 __A6 struct DOSPathBase *dpb)
  14. {
  15.  struct Library *DOSBase = dpb->dpb_DOSBase;
  16.  BPTR            olddir  = CurrentDir(NULL);
  17.  BPTR            rc      = NULL;
  18.  
  19.  DEBUGLOG(kprintf("Find: List 0x%08lx File '%s' 0x%08lx Base 0x%08lx\n",
  20.                   path, file, file, dpb);)
  21.  
  22.  /* File name and anchor pointer valid? */
  23.  if (file && anchor) {
  24.   struct PathListEntry *path = *anchor;
  25.  
  26.   /* Scan path list */
  27.   while (path) {
  28.    BPTR filelock;
  29.  
  30.    DEBUGLOG(kprintf("Find: Lock 0x%08lx\n", path->ple_Lock);)
  31.  
  32.    /* Go to directory */
  33.    CurrentDir(path->ple_Lock);
  34.  
  35.    /* Program in this directory? */
  36.    if (filelock = Lock(file, SHARED_LOCK)) {
  37.  
  38.     /* Yes, unlock it */
  39.     UnLock(filelock);
  40.  
  41.     /* Set return code */
  42.     rc = path->ple_Lock;
  43.  
  44.     /* Leave loop */
  45.     break;
  46.    }
  47.  
  48.    /* Next entry */
  49.    path = BADDR(path->ple_Next);
  50.   }
  51.  
  52.   /* Store pointer to next entry for next call */
  53.   *anchor = path ? (struct PathListEntry *) BADDR(path->ple_Next) : NULL;
  54.  }
  55.  
  56.  /* Go back to old directory */
  57.  CurrentDir(olddir);
  58.  
  59.  DEBUGLOG(kprintf("Find: Result 0x%08lx\n", rc);)
  60.  
  61.  /* Return lock to directory where the file was found */
  62.  return(rc);
  63. }
  64.