home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 278.lha / Patch_v0.91 / chdir.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-08-06  |  998 b   |  41 lines

  1. /* File to implement the "chdir" command of Unix under AmigaDOS: */
  2.  
  3. #include <libraries/dos.h>
  4. #include <libraries/dosextens.h>
  5.  
  6. extern struct FileLock *Lock();
  7. extern void UnLock();
  8. extern struct FileLock *CurrentDir();
  9.  
  10. int chdir(newpath)
  11.   char *newpath;
  12. {
  13.    register struct FileLock *newdir;
  14.    register struct FileLock *olddir;
  15.  
  16.    static struct FileInfoBlock fib;
  17.  
  18.  
  19.    newdir=Lock(newpath);
  20.    if (newdir==0) {
  21.       puts("Chdir error: Couldn't get the lock!");
  22.       return -1;  /* error: we didn't get a lock on the newpath. */
  23.    }
  24.  
  25.    Examine(newdir,&fib);        /* see if it's a directory we can cd to... */
  26.    if (fib.fib_DirEntryType<0) {
  27.        UnLock(newdir);            /* it's a file, not a directory. */
  28.        puts("Chdir error: It's a file, dummy!");
  29.        return -1;
  30.     }
  31.  
  32.     /* eventually we'll have to check protect bits, but not now: */
  33.     olddir=CurrentDir(newdir);
  34.     if (olddir==0)
  35.        return -1;
  36.     UnLock(olddir);  /* no longer needed? */
  37.  
  38.     return 0;
  39. }
  40.  
  41.