Rev 5191 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 5191 | Rev 5199 | ||
---|---|---|---|
Line 39... | Line 39... | ||
39 | #include |
39 | #include |
40 | #endif |
40 | #endif |
Line 41... | Line 41... | ||
41 | 41 | ||
Line 42... | Line -... | ||
42 | #include "libiberty.h" |
- | |
43 | - | ||
44 | /* Virtually every UN*X system now in common use (except for pre-4.3-tahoe |
- | |
45 | BSD systems) now provides getcwd as called for by POSIX. Allow for |
- | |
46 | the few exceptions to the general rule here. */ |
- | |
47 | - | ||
48 | #if !defined(HAVE_GETCWD) && defined(HAVE_GETWD) |
- | |
49 | /* Prototype in case the system headers doesn't provide it. */ |
- | |
50 | extern char *getwd (); |
- | |
Line 51... | Line 42... | ||
51 | #define getcwd(buf,len) getwd(buf) |
42 | #include "libiberty.h" |
52 | #endif |
43 | |
53 | 44 | ||
54 | #ifdef MAXPATHLEN |
45 | #ifdef MAXPATHLEN |
55 | #define GUESSPATHLEN (MAXPATHLEN + 1) |
46 | #define GUESSPATHLEN (MAXPATHLEN + 1) |
Line 56... | Line -... | ||
56 | #else |
- | |
57 | #define GUESSPATHLEN 100 |
- | |
58 | #endif |
- | |
59 | - | ||
60 | #if !(defined (VMS) || (defined(_WIN32) && !defined(__CYGWIN__))) |
- | |
61 | - | ||
62 | /* Get the working directory. Use the PWD environment variable if it's |
- | |
63 | set correctly, since this is faster and gives more uniform answers |
- | |
64 | to the user. Yield the working directory if successful; otherwise, |
- | |
65 | yield 0 and set errno. */ |
- | |
66 | - | ||
67 | char * |
- | |
68 | getpwd (void) |
- | |
69 | { |
- | |
70 | static char *pwd; |
- | |
71 | static int failure_errno; |
- | |
72 | - | ||
73 | char *p = pwd; |
- | |
74 | size_t s; |
- | |
75 | struct stat dotstat, pwdstat; |
- | |
76 | - | ||
77 | if (!p && !(errno = failure_errno)) |
- | |
78 | { |
- | |
79 | if (! ((p = getenv ("PWD")) != 0 |
- | |
80 | && *p == '/' |
- | |
81 | && stat (p, &pwdstat) == 0 |
- | |
82 | && stat (".", &dotstat) == 0 |
- | |
83 | && dotstat.st_ino == pwdstat.st_ino |
- | |
84 | && dotstat.st_dev == pwdstat.st_dev)) |
- | |
85 | - | ||
86 | /* The shortcut didn't work. Try the slow, ``sure'' way. */ |
- | |
87 | for (s = GUESSPATHLEN; !getcwd (p = XNEWVEC (char, s), s); s *= 2) |
47 | #else |
88 | { |
48 | #define GUESSPATHLEN 100 |
89 | int e = errno; |
49 | #endif |
90 | free (p); |
- | |
91 | #ifdef ERANGE |
- | |
92 | if (e != ERANGE) |
- | |
93 | #endif |
- | |
94 | { |
- | |
95 | errno = failure_errno = e; |
- | |
Line 96... | Line -... | ||
96 | p = 0; |
- | |
97 | break; |
- | |
98 | } |
- | |
99 | } |
- | |
100 | - | ||
101 | /* Cache the result. This assumes that the program does |
- | |
Line 102... | Line 50... | ||
102 | not invoke chdir between calls to getpwd. */ |
50 | |
- | 51 | #ifndef MAXPATHLEN |
|
- | 52 | #define MAXPATHLEN 255 |
|
- | 53 | #endif |
|
- | 54 | ||
- | 55 | ||
- | 56 | static char *getccwd(char *buf, size_t size) |
|
- | 57 | { |
|
Line 103... | Line 58... | ||
103 | pwd = p; |
58 | int bsize; |
104 | } |
- | |
105 | return p; |
59 | __asm__ __volatile__( |
Line 106... | Line 60... | ||
106 | } |
60 | "int $0x40" |
107 | 61 | :"=a"(bsize) |
|
108 | #else /* VMS || _WIN32 && !__CYGWIN__ */ |
62 | :"a"(30),"b"(2),"c"(buf), "d"(size) |
109 | 63 | :"memory"); |
|
Line 110... | Line 64... | ||
110 | #ifndef MAXPATHLEN |
64 | |
111 | #define MAXPATHLEN 255 |
65 | return buf; |
112 | #endif |
- | |
113 | - | ||
114 | char * |
- | |
115 | getpwd (void) |
66 | }; |
116 | { |
67 | |
117 | static char *pwd = 0; |
68 | char * |
Line 118... | Line -... | ||
118 | - | ||
- | 69 | getpwd (void) |