summaryrefslogtreecommitdiff
path: root/libc/sysdeps/linux/common/getcwd.c
diff options
context:
space:
mode:
Diffstat (limited to 'libc/sysdeps/linux/common/getcwd.c')
-rw-r--r--libc/sysdeps/linux/common/getcwd.c24
1 files changed, 13 insertions, 11 deletions
diff --git a/libc/sysdeps/linux/common/getcwd.c b/libc/sysdeps/linux/common/getcwd.c
index 63b195ec2..a9042c76b 100644
--- a/libc/sysdeps/linux/common/getcwd.c
+++ b/libc/sysdeps/linux/common/getcwd.c
@@ -11,8 +11,11 @@
#include <sys/stat.h>
#include <dirent.h>
#include <string.h>
+#include <unistd.h>
#include <sys/syscall.h>
+libc_hidden_proto(getcwd)
+
libc_hidden_proto(strcat)
libc_hidden_proto(strcpy)
libc_hidden_proto(strncpy)
@@ -24,7 +27,7 @@ libc_hidden_proto(stat)
#ifdef __NR_getcwd
-#define __NR___syscall_getcwd __NR_getcwd
+# define __NR___syscall_getcwd __NR_getcwd
static inline
_syscall2(int, __syscall_getcwd, char *, buf, unsigned long, size);
@@ -49,18 +52,18 @@ static char *search_dir(dev_t this_dev, ino_t this_ino, char *path_buf, int path
int slen;
struct stat st;
-#ifdef FAST_DIR_SEARCH_POSSIBLE
+# ifdef FAST_DIR_SEARCH_POSSIBLE
/* The test is for ELKS lib 0.0.9, this should be fixed in the real kernel */
int slow_search = (sizeof(ino_t) != sizeof(d->d_ino));
-#endif
+# endif
if (stat(path_buf, &st) < 0) {
goto oops;
}
-#ifdef FAST_DIR_SEARCH_POSSIBLE
+# ifdef FAST_DIR_SEARCH_POSSIBLE
if (this_dev != st.st_dev)
slow_search = 1;
-#endif
+# endif
slen = strlen(path_buf);
ptr = path_buf + slen - 1;
@@ -79,9 +82,9 @@ static char *search_dir(dev_t this_dev, ino_t this_ino, char *path_buf, int path
}
while ((d = readdir(dp)) != 0) {
-#ifdef FAST_DIR_SEARCH_POSSIBLE
+# ifdef FAST_DIR_SEARCH_POSSIBLE
if (slow_search || this_ino == d->d_ino) {
-#endif
+# endif
if (slen + strlen(d->d_name) > path_size) {
goto oops;
}
@@ -92,9 +95,9 @@ static char *search_dir(dev_t this_dev, ino_t this_ino, char *path_buf, int path
closedir(dp);
return path_buf;
}
-#ifdef FAST_DIR_SEARCH_POSSIBLE
+# ifdef FAST_DIR_SEARCH_POSSIBLE
}
-#endif
+# endif
}
closedir(dp);
@@ -166,7 +169,7 @@ int __syscall_getcwd(char * buf, unsigned long size)
return len;
}
-#endif
+#endif /* __NR_getcwd */
char *getcwd(char *buf, size_t size)
{
@@ -200,5 +203,4 @@ char *getcwd(char *buf, size_t size)
free (path);
return NULL;
}
-libc_hidden_proto(getcwd)
libc_hidden_def(getcwd)