Remove ENOUSER and ENOGROUP.

The <pwd.h> and <grp.h> family of functions are supposed to return
nothing with no error set if there is no matching entry.
This commit is contained in:
Jonas 'Sortie' Termansen 2021-05-05 23:57:32 +02:00
parent 7f9a62d916
commit 11be0007b8
11 changed files with 23 additions and 17 deletions

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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";

View File

@ -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) )