diff options
author | Eric Andersen <andersen@codepoet.org> | 2005-08-15 22:18:26 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 2005-08-15 22:18:26 +0000 |
commit | 8b995a0e60df749e43af032cc9570ee55b918105 (patch) | |
tree | 1eb51a1c86118a4b6039d823f549f01afc56d5f2 /libc/sysdeps/linux/common | |
parent | 5833ba3946c09cf5af0ccf5bc61626f1f4a60825 (diff) |
For current kernels, we just use the getcwd() syscall. For old 2.0 linux
kernels, we need this bit to make the non-syscall version that recurses up the
directory path work properly. Thanks go to Harald Kuethe for sorting this out.
Diffstat (limited to 'libc/sysdeps/linux/common')
-rw-r--r-- | libc/sysdeps/linux/common/getcwd.c | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/libc/sysdeps/linux/common/getcwd.c b/libc/sysdeps/linux/common/getcwd.c index daf056e98..a1de4510c 100644 --- a/libc/sysdeps/linux/common/getcwd.c +++ b/libc/sysdeps/linux/common/getcwd.c @@ -10,7 +10,7 @@ #ifdef __NR_getcwd #define __NR___syscall_getcwd __NR_getcwd -static inline +static inline _syscall2(int, __syscall_getcwd, char *, buf, unsigned long, size); #else @@ -134,6 +134,15 @@ int __syscall_getcwd(char * buf, unsigned long size) olderrno = errno; len = -1; + + /* get stat for root to have a valid parameters for the terminating condition */ + if (stat("/", &st) < 0) { + /* root dir not found! */ + return -1; + } + /* start with actual dir */ + if (buf) strncpy(buf, ".", size); + cwd = recurser(buf, size, st.st_dev, st.st_ino); if (cwd) { len = strlen(buf); |