From 11be0007b8621f5869824ea168dd818131bb7f98 Mon Sep 17 00:00:00 2001 From: Jonas 'Sortie' Termansen Date: Wed, 5 May 2021 23:57:32 +0200 Subject: [PATCH] Remove ENOUSER and ENOGROUP. The and family of functions are supposed to return nothing with no error set if there is no matching entry. --- libc/grp/getgrgid.c | 4 +++- libc/grp/getgrgid_r.c | 4 ++-- libc/grp/getgrnam.c | 4 +++- libc/grp/getgrnam_r.c | 4 ++-- libc/include/errno.h | 2 -- libc/pwd/getpwnam.c | 4 +++- libc/pwd/getpwnam_r.c | 4 ++-- libc/pwd/getpwuid.c | 4 +++- libc/pwd/getpwuid_r.c | 4 ++-- libc/string/strerror.c | 2 -- libc/unistd/getlogin_r.c | 4 +++- 11 files changed, 23 insertions(+), 17 deletions(-) diff --git a/libc/grp/getgrgid.c b/libc/grp/getgrgid.c index 2326766c..8498af18 100644 --- a/libc/grp/getgrgid.c +++ b/libc/grp/getgrgid.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013 Jonas 'Sortie' Termansen. + * Copyright (c) 2013, 2021 Jonas 'Sortie' Termansen. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -24,6 +24,7 @@ struct group* getgrgid(gid_t gid) { + int old_errno = errno; static struct group result_object; static char* buf = NULL; static size_t buflen = 0; @@ -50,5 +51,6 @@ retry: } if ( errnum < 0 ) return errno = errnum, (struct group*) NULL; + errno = old_errno; return result; } diff --git a/libc/grp/getgrgid_r.c b/libc/grp/getgrgid_r.c index a50afa95..6c6bf611 100644 --- a/libc/grp/getgrgid_r.c +++ b/libc/grp/getgrgid_r.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2014 Jonas 'Sortie' Termansen. + * Copyright (c) 2013, 2014, 2021 Jonas 'Sortie' Termansen. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -44,5 +44,5 @@ int getgrgid_r(gid_t gid, return *ret_ptr = *ret_ptr, 0; } fclose(fgroup); - return *ret_ptr = NULL, errnum ? errnum : (errno = ENOGROUP); + return *ret_ptr = NULL, errnum ? errnum : 0; } diff --git a/libc/grp/getgrnam.c b/libc/grp/getgrnam.c index d9b09a01..3ff0e4d2 100644 --- a/libc/grp/getgrnam.c +++ b/libc/grp/getgrnam.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013 Jonas 'Sortie' Termansen. + * Copyright (c) 201, 20213 Jonas 'Sortie' Termansen. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -24,6 +24,7 @@ struct group* getgrnam(const char* groupname) { + int old_errno = errno; static struct group result_object; static char* buf = NULL; static size_t buflen = 0; @@ -50,5 +51,6 @@ retry: } if ( errnum < 0 ) return errno = errnum, (struct group*) NULL; + errno = old_errno; return result; } diff --git a/libc/grp/getgrnam_r.c b/libc/grp/getgrnam_r.c index 80ba4092..cc2b4973 100644 --- a/libc/grp/getgrnam_r.c +++ b/libc/grp/getgrnam_r.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2014 Jonas 'Sortie' Termansen. + * Copyright (c) 2013, 2014, 2021 Jonas 'Sortie' Termansen. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -45,5 +45,5 @@ int getgrnam_r(const char* restrict groupname, return *ret_ptr = *ret_ptr, 0; } fclose(fgroup); - return *ret_ptr = NULL, errnum ? errnum : (errno = ENOGROUP); + return *ret_ptr = NULL, errnum ? errnum : 0; } diff --git a/libc/include/errno.h b/libc/include/errno.h index f6e79aa2..7cfd61ec 100644 --- a/libc/include/errno.h +++ b/libc/include/errno.h @@ -94,8 +94,6 @@ #define ENFILE 82 #define EPROTOTYPE 83 #define ENOLCK 84 -#define ENOUSER 85 -#define ENOGROUP 86 #define ESIGPENDING 87 #define ESTALE 88 #define EBADMSG 89 diff --git a/libc/pwd/getpwnam.c b/libc/pwd/getpwnam.c index 5db4a1a1..cea35410 100644 --- a/libc/pwd/getpwnam.c +++ b/libc/pwd/getpwnam.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013 Jonas 'Sortie' Termansen. + * Copyright (c) 2013, 2021 Jonas 'Sortie' Termansen. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -24,6 +24,7 @@ struct passwd* getpwnam(const char* username) { + int old_errno = errno; static struct passwd result_object; static char* buf = NULL; static size_t buflen = 0; @@ -50,5 +51,6 @@ retry: } if ( errnum < 0 ) return errno = errnum, (struct passwd*) NULL; + errno = old_errno; return result; } diff --git a/libc/pwd/getpwnam_r.c b/libc/pwd/getpwnam_r.c index c7c5bff9..eac4654c 100644 --- a/libc/pwd/getpwnam_r.c +++ b/libc/pwd/getpwnam_r.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2014 Jonas 'Sortie' Termansen. + * Copyright (c) 2013, 2014, 2021 Jonas 'Sortie' Termansen. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -45,5 +45,5 @@ int getpwnam_r(const char* restrict username, return *ret_ptr = *ret_ptr, 0; } fclose(fpasswd); - return *ret_ptr = NULL, errnum ? errnum : (errno = ENOUSER); + return *ret_ptr = NULL, errnum ? errnum : 0; } diff --git a/libc/pwd/getpwuid.c b/libc/pwd/getpwuid.c index 9ae5496c..7ebb90cb 100644 --- a/libc/pwd/getpwuid.c +++ b/libc/pwd/getpwuid.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013 Jonas 'Sortie' Termansen. + * Copyright (c) 2013, 2021 Jonas 'Sortie' Termansen. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -24,6 +24,7 @@ struct passwd* getpwuid(uid_t uid) { + int old_errno = errno; static struct passwd result_object; static char* buf = NULL; static size_t buflen = 0; @@ -50,5 +51,6 @@ retry: } if ( errnum < 0 ) return errno = errnum, (struct passwd*) NULL; + errno = old_errno; return result; } diff --git a/libc/pwd/getpwuid_r.c b/libc/pwd/getpwuid_r.c index f5ceba5c..adffac2d 100644 --- a/libc/pwd/getpwuid_r.c +++ b/libc/pwd/getpwuid_r.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2014 Jonas 'Sortie' Termansen. + * Copyright (c) 2013, 2014, 2021 Jonas 'Sortie' Termansen. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -44,5 +44,5 @@ int getpwuid_r(uid_t uid, return *ret_ptr = *ret_ptr, 0; } fclose(fpasswd); - return *ret_ptr = NULL, errnum ? errnum : (errno = ENOUSER); + return *ret_ptr = NULL, errnum ? errnum : 0; } diff --git a/libc/string/strerror.c b/libc/string/strerror.c index affb27a4..fa4729dd 100644 --- a/libc/string/strerror.c +++ b/libc/string/strerror.c @@ -97,8 +97,6 @@ const char* sortix_strerror(int errnum) case ENFILE: return "Too many open files in system"; case EPROTOTYPE: return "Wrong protocol type for socket"; case ENOLCK: return "No locks available"; - case ENOUSER: return "No such user"; - case ENOGROUP: return "No such group"; case ESIGPENDING: return "Signal is already pending"; case ESTALE: return "Stale file handle"; case EBADMSG: return "Bad message"; diff --git a/libc/unistd/getlogin_r.c b/libc/unistd/getlogin_r.c index 01b8b1b5..50a10b53 100644 --- a/libc/unistd/getlogin_r.c +++ b/libc/unistd/getlogin_r.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013 Jonas 'Sortie' Termansen. + * Copyright (c) 2013, 2021 Jonas 'Sortie' Termansen. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -44,6 +44,8 @@ int getlogin_r(char* buf, size_t size) &passwd)) == ERANGE ); if ( errnum ) return free(pwdbuf), errno = errnum, -1; + if ( !passwd ) + return free(pwdbuf), errno = ENOENT, -1; const char* username = passwd->pw_name; if ( size <= strlcpy(buf, username, size) )