home *** CD-ROM | disk | FTP | other *** search
/ Atari FTP / ATARI_FTP_0693.zip / ATARI_FTP_0693 / Mint / mntlib25.zoo / getcwd.c < prev    next >
C/C++ Source or Header  |  1992-09-05  |  1KB  |  65 lines

  1. #include <compiler.h>
  2. #include <stddef.h>
  3. #include <stdlib.h>    /* both of these added for malloc() */
  4. #include <limits.h>
  5. #include <errno.h>
  6. #include <osbind.h>
  7. #include "lib.h"
  8.  
  9. /*******************************************************************
  10. getcwd: returns current working directory. By ERS.
  11. This routine is in the public domain.
  12. ********************************************************************/
  13.  
  14. extern int __mint;
  15. extern char _rootdir;    /* in main.c: user's preferred root directory */
  16.  
  17. char *getcwd __PROTO((char *, int));
  18.  
  19. char *getcwd(buf, size)
  20. char *buf; int size;
  21. {
  22.     char _path[PATH_MAX];
  23. #ifdef __GNUC__
  24. /* sometimes the GCC optimizer is too clever; it doesn't know that
  25.    Dgetpath(path, 0) can change the stuff path points to
  26.  */
  27.     volatile char *path;
  28. #else
  29.     char *path;
  30. #endif
  31.     char drv;
  32.  
  33.     if (!buf)
  34.         if ((buf = (char *) malloc((size_t)size)) == 0)
  35.             return NULL;
  36.  
  37.     drv = Dgetdrv() + 'a';
  38.     _path[0] = drv;
  39.     _path[1] = ':';
  40.     _path[2] = '\0';
  41.     path = _path + 2;
  42.     (void)Dgetpath(path, 0);
  43.  
  44.     if (_rootdir && drv == _rootdir) {
  45.         if (!*path) {
  46.             path[0] = '\\';
  47.             path[1] = '\0';
  48.         }
  49.         _dos2unx((char *)path, buf);
  50.         return buf;
  51.     }
  52.     _dos2unx(_path, buf);    /* convert DOS filename to unix */
  53.     return buf;
  54. }
  55.  
  56. /*
  57.  * char *getwd(char *buf)
  58.  *    return cwd in buf
  59.  */
  60. char *getwd(buf)
  61. char *buf;
  62. {
  63.     return getcwd(buf, PATH_MAX);
  64. }
  65.