Back to index

cell-binutils  2.17cvs20070401
Defines | Functions | Variables
getpwd.c File Reference
#include <sys/types.h>
#include <errno.h>
#include "libiberty.h"

Go to the source code of this file.

Defines

#define GUESSPATHLEN   100

Functions

char * getpwd (void)

Variables

int errno

Define Documentation

#define GUESSPATHLEN   100

Definition at line 57 of file getpwd.c.


Function Documentation

char* getpwd ( void  )

Definition at line 68 of file getpwd.c.

{
  static char *pwd;
  static int failure_errno;

  char *p = pwd;
  size_t s;
  struct stat dotstat, pwdstat;

  if (!p && !(errno = failure_errno))
    {
      if (! ((p = getenv ("PWD")) != 0
            && *p == '/'
            && stat (p, &pwdstat) == 0
            && stat (".", &dotstat) == 0
            && dotstat.st_ino == pwdstat.st_ino
            && dotstat.st_dev == pwdstat.st_dev))

       /* The shortcut didn't work.  Try the slow, ``sure'' way.  */
       for (s = GUESSPATHLEN;  !getcwd (p = XNEWVEC (char, s), s);  s *= 2)
         {
           int e = errno;
           free (p);
#ifdef ERANGE
           if (e != ERANGE)
#endif
             {
              errno = failure_errno = e;
              p = 0;
              break;
             }
         }

      /* Cache the result.  This assumes that the program does
        not invoke chdir between calls to getpwd.  */
      pwd = p;
    }
  return p;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation