Files
fastfetch/src/detection/users/users_linux.c
T
2023-06-18 12:51:58 +08:00

37 lines
745 B
C

#include "fastfetch.h"
#include "users.h"
#if FF_HAVE_UTMPX_H
#include <utmpx.h>
#else
//for Android compatibility
#include <utmp.h>
#define utmpx utmp
#define setutxent setutent
#define getutxent getutent
#endif
void ffDetectUsers(FFlist* users, FFstrbuf* error)
{
struct utmpx* n = NULL;
setutxent();
next:
while((n = getutxent()))
{
if(n->ut_type != USER_PROCESS)
continue;
FF_LIST_FOR_EACH(FFstrbuf, user, *users)
{
if(ffStrbufEqualS(user, n->ut_user))
goto next;
}
ffStrbufInitS((FFstrbuf*)ffListAdd(users), n->ut_user);
}
if(users->length == 0)
ffStrbufAppendS(error, "Unable to detect users");
}