summaryrefslogtreecommitdiffstats
path: root/libc/sysdeps/linux/common/getcwd.c
diff options
context:
space:
mode:
author"Steven J. Hill" <sjhill@realitydiluted.com>2005-08-17 14:48:11 +0000
committer"Steven J. Hill" <sjhill@realitydiluted.com>2005-08-17 14:48:11 +0000
commit54a7d559374ef72fa59bbe3a56d27ff5ec34d3aa (patch)
tree1fe7209313f2728c550d3eb75929b4af051fb349 /libc/sysdeps/linux/common/getcwd.c
parentb46868ff8b3d2fb592e3fca4a516695533eae9e5 (diff)
downloaduClibc-alpine-54a7d559374ef72fa59bbe3a56d27ff5ec34d3aa.tar.bz2
uClibc-alpine-54a7d559374ef72fa59bbe3a56d27ff5ec34d3aa.tar.xz
Merge/sync with trunk.
Diffstat (limited to 'libc/sysdeps/linux/common/getcwd.c')
-rw-r--r--libc/sysdeps/linux/common/getcwd.c11
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);