Rev 5191 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
5191 | serge | 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 |
||
20 | |||
21 | #include |
||
22 | #ifndef errno |
||
23 | extern int errno; |
||
24 | #endif |
||
25 | |||
26 | #ifdef HAVE_STDLIB_H |
||
27 | #include |
||
28 | #endif |
||
29 | #ifdef HAVE_UNISTD_H |
||
30 | #include |
||
31 | #endif |
||
32 | #ifdef HAVE_SYS_PARAM_H |
||
33 | #include |
||
34 | #endif |
||
35 | #if HAVE_SYS_STAT_H |
||
36 | #include |
||
37 | #endif |
||
38 | #if HAVE_LIMITS_H |
||
39 | #include |
||
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 | |||
5199 | serge | 51 | #ifndef MAXPATHLEN |
52 | #define MAXPATHLEN 255 |
||
53 | #endif |
||
5191 | serge | 54 | |
55 | |||
5199 | serge | 56 | static char *getccwd(char *buf, size_t size) |
5191 | serge | 57 | { |
5199 | serge | 58 | int bsize; |
59 | __asm__ __volatile__( |
||
60 | "int $0x40" |
||
61 | :"=a"(bsize) |
||
62 | :"a"(30),"b"(2),"c"(buf), "d"(size) |
||
63 | :"memory"); |
||
5191 | serge | 64 | |
5199 | serge | 65 | return buf; |
66 | }; |
||
5191 | serge | 67 | |
68 | char * |
||
69 | getpwd (void) |
||
70 | { |
||
71 | static char *pwd = 0; |
||
72 | |||
73 | if (!pwd) |
||
5199 | serge | 74 | pwd = getccwd (XNEWVEC (char, MAXPATHLEN + 1), MAXPATHLEN + 1); |
75 | |||
5191 | serge | 76 | return pwd; |
77 | } |
||
78 |