2014-11-28 07:08:38 +01:00
|
|
|
/* 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 <sys/types.h>
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#ifndef errno
|
|
|
|
extern int errno;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_STDLIB_H
|
|
|
|
#include <stdlib.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_SYS_PARAM_H
|
|
|
|
#include <sys/param.h>
|
|
|
|
#endif
|
|
|
|
#if HAVE_SYS_STAT_H
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#endif
|
|
|
|
#if HAVE_LIMITS_H
|
|
|
|
#include <limits.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "libiberty.h"
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef MAXPATHLEN
|
|
|
|
#define GUESSPATHLEN (MAXPATHLEN + 1)
|
|
|
|
#else
|
|
|
|
#define GUESSPATHLEN 100
|
|
|
|
#endif
|
|
|
|
|
2014-11-29 07:17:35 +01:00
|
|
|
#ifndef MAXPATHLEN
|
|
|
|
#define MAXPATHLEN 255
|
|
|
|
#endif
|
2014-11-28 07:08:38 +01:00
|
|
|
|
|
|
|
|
2014-11-29 07:17:35 +01:00
|
|
|
static char *getccwd(char *buf, size_t size)
|
2014-11-28 07:08:38 +01:00
|
|
|
{
|
2014-11-29 07:17:35 +01:00
|
|
|
int bsize;
|
|
|
|
__asm__ __volatile__(
|
|
|
|
"int $0x40"
|
|
|
|
:"=a"(bsize)
|
|
|
|
:"a"(30),"b"(2),"c"(buf), "d"(size)
|
|
|
|
:"memory");
|
2014-11-28 07:08:38 +01:00
|
|
|
|
2014-11-29 07:17:35 +01:00
|
|
|
return buf;
|
|
|
|
};
|
2014-11-28 07:08:38 +01:00
|
|
|
|
|
|
|
char *
|
|
|
|
getpwd (void)
|
|
|
|
{
|
|
|
|
static char *pwd = 0;
|
|
|
|
|
|
|
|
if (!pwd)
|
2014-11-29 07:17:35 +01:00
|
|
|
pwd = getccwd (XNEWVEC (char, MAXPATHLEN + 1), MAXPATHLEN + 1);
|
|
|
|
|
2014-11-28 07:08:38 +01:00
|
|
|
return pwd;
|
|
|
|
}
|
|
|
|
|
2014-11-29 07:17:35 +01:00
|
|
|
|