home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume1 / 8708 / 24 / getcwd.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-07-13  |  620 b   |  53 lines

  1.  
  2. #include <errno.h>
  3. #include <memory.h>
  4. #include <aztec/shell.h>
  5.  
  6. #ifdef TEST
  7. #include <stdio.h>
  8. #define _DEBUG
  9. #include <max/debug.h>
  10. #endif
  11.  
  12. #ifndef NULL
  13. #define NULL 0L
  14. #endif
  15.  
  16. char * malloc();
  17.  
  18. char * getcwd( path, size )
  19. char * path;
  20. int size;
  21. {
  22.  
  23.     register char * cp;
  24.  
  25.     cp = *Sp->curdir;
  26.     
  27.     if (path == NULL) {
  28.         if (size == 0)
  29.             size = strlen( cp ) + 2;
  30.         path = malloc( size );
  31.     }
  32.     if (size <= strlen( cp )) {
  33.         strcpy( path, "" );
  34.         errno = E2BIG;
  35.         return NULL;
  36.     }
  37.  
  38.     strcpy( path, "/" );
  39.     strcat( path, cp );
  40.     return( path );
  41.     
  42. }
  43.  
  44. #ifdef TEST
  45. main()
  46. {
  47.  
  48.     fprintf( stderr, "%s\n", getcwd( NULL, 0 ));
  49. }
  50.  
  51. #endif
  52.  
  53.