diff options
author | Rich Felker <dalias@aerifal.cx> | 2013-10-08 19:49:10 -0400 |
---|---|---|
committer | Rich Felker <dalias@aerifal.cx> | 2013-10-08 19:49:10 -0400 |
commit | 4fb7df12f52982412e60afeaf9c4463f78b396fc (patch) | |
tree | 8e32da083c9881ced7a9fdb709289a7d28ce0e35 /src/unistd | |
parent | 8f438115f2c12b40fa7b1884f87db72857af67f6 (diff) | |
download | musl-4fb7df12f52982412e60afeaf9c4463f78b396fc.tar.gz musl-4fb7df12f52982412e60afeaf9c4463f78b396fc.tar.bz2 musl-4fb7df12f52982412e60afeaf9c4463f78b396fc.tar.xz musl-4fb7df12f52982412e60afeaf9c4463f78b396fc.zip |
fix errno value for getcwd when size argument is zero
based on patch by Michael Forney. at the same time, I've changed the
if branch to be more clear, avoiding the comma operator.
the underlying issue is that Linux always returns ERANGE when size is
too short, even when it's zero, rather than returning EINVAL for the
special case of zero as required by POSIX.
Diffstat (limited to 'src/unistd')
-rw-r--r-- | src/unistd/getcwd.c | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/src/unistd/getcwd.c b/src/unistd/getcwd.c index 2e540cd4..a7b925d2 100644 --- a/src/unistd/getcwd.c +++ b/src/unistd/getcwd.c @@ -7,7 +7,13 @@ char *getcwd(char *buf, size_t size) { char tmp[PATH_MAX]; - if (!buf) buf = tmp, size = PATH_MAX; + if (!buf) { + buf = tmp; + size = PATH_MAX; + } else if (!size) { + errno = EINVAL; + return 0; + } if (syscall(SYS_getcwd, buf, size) < 0) return 0; return buf == tmp ? strdup(buf) : buf; } |