summaryrefslogtreecommitdiff
path: root/libc/sysdeps/linux/common
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2002-12-04 02:34:26 +0000
committerEric Andersen <andersen@codepoet.org>2002-12-04 02:34:26 +0000
commit37e8a493e38421b46967338ee1ec2c534f0d05c3 (patch)
tree6f779d51c6d15c4310d2b7eba573f5b98cf2f347 /libc/sysdeps/linux/common
parentd6cb9955d12e5c28ba7ae03bb01b47df4dabd44c (diff)
Fix the other instance of getcwd
Diffstat (limited to 'libc/sysdeps/linux/common')
-rw-r--r--libc/sysdeps/linux/common/getcwd.c39
1 files changed, 21 insertions, 18 deletions
diff --git a/libc/sysdeps/linux/common/getcwd.c b/libc/sysdeps/linux/common/getcwd.c
index 9e64a3dd8..d1740fa31 100644
--- a/libc/sysdeps/linux/common/getcwd.c
+++ b/libc/sysdeps/linux/common/getcwd.c
@@ -151,29 +151,32 @@ static char *recurser(char *path_buf, int path_size, dev_t root_dev, ino_t root_
char *getcwd(char *buf, int size)
{
- struct stat st;
+ struct stat st;
- if (size == 0) {
- __set_errno(EINVAL);
- return NULL;
- }
- if (size < 3) {
- __set_errno(ERANGE);
- return NULL;
+ if (size == 0) {
+ if (buf != NULL) {
+ __set_errno(EINVAL);
+ return NULL;
}
+ size = PATH_MAX;
+ }
+ if (size < 3) {
+ __set_errno(ERANGE);
+ return NULL;
+ }
- if (buf == NULL) {
- buf = malloc (size);
- if (buf == NULL)
- return NULL;
- }
+ if (buf == NULL) {
+ buf = malloc (size);
+ if (buf == NULL)
+ return NULL;
+ }
- strcpy(buf, ".");
- if (stat("/", &st) < 0) {
- return NULL;
- }
+ strcpy(buf, ".");
+ if (stat("/", &st) < 0) {
+ return NULL;
+ }
- return recurser(buf, size, st.st_dev, st.st_ino);
+ return recurser(buf, size, st.st_dev, st.st_ino);
}
#endif