diff options
author | Rich Felker <dalias@aerifal.cx> | 2018-12-28 16:50:07 -0500 |
---|---|---|
committer | Rich Felker <dalias@aerifal.cx> | 2018-12-28 16:50:07 -0500 |
commit | 9db81b862d95326d43af7c7fae9078ad9ff5bd6f (patch) | |
tree | 24f06e1891f50ea60eaedef456a16fa6eabb58d5 /src | |
parent | 21a172dd36cae7a08492fd3a7500d7bf0daee13e (diff) | |
download | musl-9db81b862d95326d43af7c7fae9078ad9ff5bd6f.tar.gz musl-9db81b862d95326d43af7c7fae9078ad9ff5bd6f.tar.bz2 musl-9db81b862d95326d43af7c7fae9078ad9ff5bd6f.tar.xz musl-9db81b862d95326d43af7c7fae9078ad9ff5bd6f.zip |
don't set errno or return an error when getspnam[_r] finds no entry
this case is specified as success with a null result, rather than an
error, and errno is not to be set on success.
Diffstat (limited to 'src')
-rw-r--r-- | src/passwd/getspnam.c | 3 | ||||
-rw-r--r-- | src/passwd/getspnam_r.c | 9 |
2 files changed, 9 insertions, 3 deletions
diff --git a/src/passwd/getspnam.c b/src/passwd/getspnam.c index 041f8965..709b526d 100644 --- a/src/passwd/getspnam.c +++ b/src/passwd/getspnam.c @@ -8,10 +8,11 @@ struct spwd *getspnam(const char *name) static char *line; struct spwd *res; int e; + int orig_errno = errno; if (!line) line = malloc(LINE_LIM); if (!line) return 0; e = getspnam_r(name, &sp, line, LINE_LIM, &res); - if (e) errno = e; + errno = e ? e : orig_errno; return res; } diff --git a/src/passwd/getspnam_r.c b/src/passwd/getspnam_r.c index 541206fa..1b95dbb6 100644 --- a/src/passwd/getspnam_r.c +++ b/src/passwd/getspnam_r.c @@ -67,6 +67,7 @@ int getspnam_r(const char *name, struct spwd *sp, char *buf, size_t size, struct size_t k, l = strlen(name); int skip = 0; int cs; + int orig_errno = errno; *res = 0; @@ -94,7 +95,11 @@ int getspnam_r(const char *name, struct spwd *sp, char *buf, size_t size, struct } } else { f = fopen("/etc/shadow", "rbe"); - if (!f) return errno; + if (!f) { + if (errno != ENOENT && errno != ENOTDIR) + return errno; + return 0; + } } pthread_cleanup_push(cleanup, f); @@ -113,6 +118,6 @@ int getspnam_r(const char *name, struct spwd *sp, char *buf, size_t size, struct break; } pthread_cleanup_pop(1); - if (rv) errno = rv; + errno = rv ? rv : orig_errno; return rv; } |