Subversion Repositories Kolibri OS

Rev

Rev 5191 | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. /* getpwd.c - get the working directory */
  2.  
  3. /*
  4.  
  5. @deftypefn Supplemental char* getpwd (void)
  6.  
  7. Returns the current working directory.  This implementation caches the
  8. result on the assumption that the process will not call @code{chdir}
  9. between calls to @code{getpwd}.
  10.  
  11. @end deftypefn
  12.  
  13. */
  14.  
  15. #ifdef HAVE_CONFIG_H
  16. #include "config.h"
  17. #endif
  18.  
  19. #include <sys/types.h>
  20.  
  21. #include <errno.h>
  22. #ifndef errno
  23. extern int errno;
  24. #endif
  25.  
  26. #ifdef HAVE_STDLIB_H
  27. #include <stdlib.h>
  28. #endif
  29. #ifdef HAVE_UNISTD_H
  30. #include <unistd.h>
  31. #endif
  32. #ifdef HAVE_SYS_PARAM_H
  33. #include <sys/param.h>
  34. #endif
  35. #if HAVE_SYS_STAT_H
  36. #include <sys/stat.h>
  37. #endif
  38. #if HAVE_LIMITS_H
  39. #include <limits.h>
  40. #endif
  41.  
  42. #include "libiberty.h"
  43.  
  44.  
  45. #ifdef MAXPATHLEN
  46. #define GUESSPATHLEN (MAXPATHLEN + 1)
  47. #else
  48. #define GUESSPATHLEN 100
  49. #endif
  50.  
  51. #ifndef MAXPATHLEN
  52. #define MAXPATHLEN 255
  53. #endif
  54.  
  55.  
  56. static char *getccwd(char *buf, size_t size)
  57. {
  58.     int bsize;
  59.     __asm__ __volatile__(
  60.     "int $0x40"
  61.     :"=a"(bsize)
  62.     :"a"(30),"b"(2),"c"(buf), "d"(size)
  63.     :"memory");
  64.  
  65.     return buf;
  66. };
  67.  
  68. char *
  69. getpwd (void)
  70. {
  71.   static char *pwd = 0;
  72.  
  73.   if (!pwd)
  74.     pwd = getccwd (XNEWVEC (char, MAXPATHLEN + 1), MAXPATHLEN + 1);
  75.  
  76.   return pwd;
  77. }
  78.  
  79.  
  80.