roken: add rk_getpwuid_r()

TODO: implement non-POSIX getpwnam_r()/getpwuid_r() wrappers
This commit is contained in:
Luke Howard
2018-12-22 16:30:34 +11:00
parent a6ce554c7a
commit dd7eb8f665
2 changed files with 35 additions and 0 deletions

View File

@@ -40,6 +40,9 @@
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
rk_getpwnam_r(const char *, struct passwd *, char *, size_t, struct passwd **);
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
rk_getpwuid_r(uid_t, struct passwd *, char *, size_t, struct passwd **);
#endif
#if !defined(POSIX_GETPWNAM_R) || defined(TEST_GETXXYYY)
@@ -87,6 +90,35 @@ do { \
return 0;
}
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
rk_getpwuid_r(uid_t uid, struct passwd *pwd, char *buffer,
size_t bufsize, struct passwd **result)
{
struct passwd *p;
size_t slen, n = 0;
*result = NULL;
p = getpwuid(uid);
if(p == NULL)
return (errno = ENOENT);
memset(pwd, 0, sizeof(*pwd));
APPEND(pw_name);
if (p->pw_passwd)
APPEND(pw_name);
pwd->pw_uid = p->pw_uid;
pwd->pw_gid = p->pw_gid;
APPEND(pw_gecos);
APPEND(pw_dir);
APPEND(pw_shell);
*result = pwd;
return 0;
}
#endif /* POSIX_GETPWNAM_R */
#ifdef TEST_GETXXYYY

View File

@@ -648,9 +648,12 @@ ROKEN_LIB_FUNCTION struct passwd * ROKEN_LIB_CALL k_getpwuid (uid_t);
#ifdef POSIX_GETPWNAM_R
#define rk_getpwnam_r(_n, _pw, _b, _sz, _pwd) getpwnam_r(_n, _pw, _b, _sz, _pwd)
#define rk_getpwuid_r(_u, _pw, _b, _sz, _pwd) getpwuid_r(_u, _pw, _b, _sz, _pwd)
#else
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
rk_getpwnam_r(const char *, struct passwd *, char *, size_t, struct passwd **);
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
rk_getpwuid_r(uid_t, struct passwd *, char *, size_t, struct passwd **);
#endif
#endif