home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume1 / 8708 / 24 / chdir.c next >
Encoding:
C/C++ Source or Header  |  1990-07-13  |  1.1 KB  |  80 lines

  1.  
  2. #include <errno.h>
  3. #include <memory.h>
  4. #include <pb.h>
  5. #include <aztec/shell.h>
  6.  
  7. #define _DEBUG
  8. #include <max/debug.h>
  9. #ifdef TEST
  10. #include <stdio.h>
  11. #endif
  12.  
  13. #ifndef NULL
  14. #define NULL 0L
  15. #endif
  16.  
  17. chdir( path )
  18. char * path;
  19. {
  20.  
  21.     char npath[255];
  22.     CInfoPBRec cpb;
  23.     int err;
  24.     register char * cp;
  25.  
  26.  
  27.     /* fix name, and get volume reference number */
  28.  
  29.  
  30.     cpb.ioVRefNum =  hfixnam( path, npath );
  31.  
  32. #ifdef TEST
  33.     fprintf( stderr, "opendir: %s\n", npath );
  34. #endif
  35.  
  36.     cpb.ioNamePtr = ctop( npath );
  37.     cpb.ioFDirIndex = 0;
  38.     cpb.u.di.ioDrDirID = 0L;
  39.     if ((err = PBGetCatInfo( &cpb, 0 )) != 0 ) {
  40. #ifdef TEST
  41.         fprintf( stderr, "setdir: PBGetCatInfo %d\n", err );
  42. #endif
  43.         return ENOENT;
  44.     }
  45.  
  46.     /* resize handle */
  47.  
  48.     ptoc( npath );
  49.     strcpy( npath, index( npath, ':' )+1 );
  50.  
  51.     while ((cp = index( npath, ':' )) != NULL )
  52.         *cp = '/';
  53.  
  54. #ifdef TEST
  55.     fprintf( stderr, "chdir: setting curdir to \"%s\"\n", npath );
  56. #endif
  57.  
  58.     SetHandleSize( Sp->curdir, (long)(strlen( npath )+2));
  59.  
  60.     if (MemError() != 0)
  61.         return ENOMEM;
  62.  
  63.     strcpy( *Sp->curdir, npath );
  64.  
  65.     return 0;
  66.  
  67. }
  68.  
  69. #ifdef TEST
  70. main()
  71. {
  72.     char command[100];
  73.  
  74.     gets( command );
  75.     fprintf( stderr, "%d\n", chdir( command ));
  76. }
  77.  
  78. #endif
  79.  
  80.