Clean up GetUserFromPid

This commit is contained in:
Andrew Schwartzmeyer
2016-10-14 15:42:59 -07:00
parent 14e2389e71
commit e343e8ec60
2 changed files with 2 additions and 19 deletions
+2 -18
View File
@@ -20,11 +20,6 @@
//! The user identifier to lookup.
//! @endparblock
//!
//! @exception errno Passes these errors via errno to GetLastError:
//! - ERROR_NO_SUCH_USER: user lookup unsuccessful
//! - ERROR_OUTOFMEMORY insufficient kernel memory
//! - ERROR_GEN_FAILURE: anything else
//!
//! @retval username as UTF-8 string, or NULL if unsuccessful
//!
char* GetPwUid(uid_t uid)
@@ -43,27 +38,16 @@ char* GetPwUid(uid_t uid)
allocate:
buf = (char*)calloc(buflen, sizeof(char));
errno = 0;
ret = getpwuid_r(uid, &pwd, buf, buflen, &result);
if (ret != 0)
{
switch(errno)
if (errno == ERANGE)
{
case ERANGE:
free(buf);
buflen *= 2;
goto allocate;
case ENOENT:
case ESRCH:
case EBADF:
case EPERM:
errno = ERROR_NO_SUCH_USER;
break;
case ENOMEM:
errno = ERROR_OUTOFMEMORY;
break;
default:
errno = ERROR_GEN_FAILURE;
}
return NULL;
}
-1
View File
@@ -33,7 +33,6 @@ char* GetUserFromPid(pid_t pid)
int ret = sysctl(name, namelen, &oldp, &oldlenp, NULL, 0);
if (ret != 0 || oldlenp == 0)
{
errno = ERROR_GEN_FAILURE;
return NULL;
}