diff --git a/libs/libc/pwd/Make.defs b/libs/libc/pwd/Make.defs index 996555be5a3..73b7cb51308 100644 --- a/libs/libc/pwd/Make.defs +++ b/libs/libc/pwd/Make.defs @@ -21,6 +21,7 @@ # Add the pwd C files to the build CSRCS += lib_getpwnam.c lib_getpwnamr.c lib_getpwuid.c lib_getpwuidr.c +CSRCS += lib_pwd_globals.c ifeq ($(CONFIG_LIBC_PASSWD_FILE),y) CSRCS += lib_find_pwdfile.c lib_pwd_globals.c diff --git a/libs/libc/pwd/lib_getpwbuf.c b/libs/libc/pwd/lib_getpwbuf.c index 5a3fe8f2928..7d85f91dd07 100644 --- a/libs/libc/pwd/lib_getpwbuf.c +++ b/libs/libc/pwd/lib_getpwbuf.c @@ -24,20 +24,9 @@ #include -#include -#include -#include #include #include "pwd/lib_pwd.h" -#include "libc.h" - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static FAR char *g_buf; -static FAR struct passwd *g_pwd; /**************************************************************************** * Public Functions @@ -68,51 +57,8 @@ FAR struct passwd *getpwbuf(uid_t uid, gid_t gid, FAR const char *name, FAR const char *gecos, FAR const char *dir, FAR const char *shell) { - FAR struct passwd *result; - FAR char *newbuf; - size_t buflen; - int err; - - buflen = strlen(name) + 1 + strlen(gecos) + 1 + strlen(dir) + 1 + - strlen(shell) + 1; - - newbuf = (FAR char *)lib_realloc(g_buf, buflen); - - if (!newbuf) - { - err = ENOMEM; - goto error; - } - - g_buf = newbuf; - - if (!g_pwd) - { - g_pwd = (FAR struct passwd *)lib_malloc(sizeof(struct passwd)); - } - - if (!g_pwd) - { - err = ENOMEM; - goto error; - } - - err = getpwbuf_r(uid, gid, name, gecos, dir, shell, - g_pwd, g_buf, buflen, &result); - - if (err) - { - goto error; - } - - return result; - -error: - lib_free(g_pwd); - lib_free(g_buf); - g_pwd = NULL; - g_buf = NULL; - set_errno(err); - - return NULL; + FAR struct passwd *pwd = NULL; + int ret = getpwbuf_r(uid, gid, name, gecos, dir, shell, &g_passwd, + g_passwd_buffer, sizeof(g_passwd_buffer), &pwd); + return ret == 0 ? pwd : NULL; } diff --git a/libs/libc/pwd/lib_pwd.h b/libs/libc/pwd/lib_pwd.h index 6df60732a61..7a6a0b843cc 100644 --- a/libs/libc/pwd/lib_pwd.h +++ b/libs/libc/pwd/lib_pwd.h @@ -51,12 +51,10 @@ extern "C" #define EXTERN extern #endif -#ifdef CONFIG_LIBC_PASSWD_FILE /* Data for non-reentrant group functions */ EXTERN struct passwd g_passwd; EXTERN char g_passwd_buffer[CONFIG_LIBC_PASSWD_LINESIZE]; -#endif /**************************************************************************** * Public Function Prototypes diff --git a/libs/libc/pwd/lib_pwd_globals.c b/libs/libc/pwd/lib_pwd_globals.c index dc64df1bec3..12deca175a0 100644 --- a/libs/libc/pwd/lib_pwd_globals.c +++ b/libs/libc/pwd/lib_pwd_globals.c @@ -26,8 +26,6 @@ #include "pwd/lib_pwd.h" -#ifdef CONFIG_LIBC_PASSWD_FILE - /**************************************************************************** * Public Data ****************************************************************************/ @@ -40,5 +38,3 @@ char g_passwd_buffer[CONFIG_LIBC_PASSWD_LINESIZE]; /**************************************************************************** * Public Functions ****************************************************************************/ - -#endif /* CONFIG_LIBC_GROUP_FILE */