/* getpwd.c - get the working directory */ /* @deftypefn Supplemental char* getpwd (void) Returns the current working directory. This implementation caches the result on the assumption that the process will not call @code{chdir} between calls to @code{getpwd}. @end deftypefn */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include #include #ifndef errno extern int errno; #endif #ifdef HAVE_STDLIB_H #include #endif #ifdef HAVE_UNISTD_H #include #endif #ifdef HAVE_SYS_PARAM_H #include #endif #if HAVE_SYS_STAT_H #include #endif #if HAVE_LIMITS_H #include #endif #include "libiberty.h" #ifdef MAXPATHLEN #define GUESSPATHLEN (MAXPATHLEN + 1) #else #define GUESSPATHLEN 100 #endif #ifndef MAXPATHLEN #define MAXPATHLEN 255 #endif static char *getccwd(char *buf, size_t size) { int bsize; __asm__ __volatile__( "int $0x40" :"=a"(bsize) :"a"(30),"b"(2),"c"(buf), "d"(size) :"memory"); return buf; }; char * getpwd (void) { static char *pwd = 0; if (!pwd) pwd = getccwd (XNEWVEC (char, MAXPATHLEN + 1), MAXPATHLEN + 1); return pwd; }