Skip to content

Commit e343e8e

Browse files
committed
Clean up GetUserFromPid
1 parent 14e2389 commit e343e8e

2 files changed

Lines changed: 2 additions & 19 deletions

File tree

src/libpsl-native/src/getpwuid.cpp

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,6 @@
2020
//! The user identifier to lookup.
2121
//! @endparblock
2222
//!
23-
//! @exception errno Passes these errors via errno to GetLastError:
24-
//! - ERROR_NO_SUCH_USER: user lookup unsuccessful
25-
//! - ERROR_OUTOFMEMORY insufficient kernel memory
26-
//! - ERROR_GEN_FAILURE: anything else
27-
//!
2823
//! @retval username as UTF-8 string, or NULL if unsuccessful
2924
//!
3025
char* GetPwUid(uid_t uid)
@@ -43,27 +38,16 @@ char* GetPwUid(uid_t uid)
4338
allocate:
4439
buf = (char*)calloc(buflen, sizeof(char));
4540

41+
errno = 0;
4642
ret = getpwuid_r(uid, &pwd, buf, buflen, &result);
4743

4844
if (ret != 0)
4945
{
50-
switch(errno)
46+
if (errno == ERANGE)
5147
{
52-
case ERANGE:
5348
free(buf);
5449
buflen *= 2;
5550
goto allocate;
56-
case ENOENT:
57-
case ESRCH:
58-
case EBADF:
59-
case EPERM:
60-
errno = ERROR_NO_SUCH_USER;
61-
break;
62-
case ENOMEM:
63-
errno = ERROR_OUTOFMEMORY;
64-
break;
65-
default:
66-
errno = ERROR_GEN_FAILURE;
6751
}
6852
return NULL;
6953
}

src/libpsl-native/src/getuserfrompid.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ char* GetUserFromPid(pid_t pid)
3333
int ret = sysctl(name, namelen, &oldp, &oldlenp, NULL, 0);
3434
if (ret != 0 || oldlenp == 0)
3535
{
36-
errno = ERROR_GEN_FAILURE;
3736
return NULL;
3837
}
3938

0 commit comments

Comments
 (0)