LibC: Implement getlogin()
This commit is contained in:
parent
14dd9294aa
commit
e22821799b
|
@ -59,6 +59,7 @@ __BEGIN_DECLS
|
|||
|
||||
#define OPEN_MAX 64
|
||||
#define NAME_MAX 255
|
||||
#define LOGIN_NAME_MAX 256
|
||||
|
||||
__END_DECLS
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include <BAN/Assert.h>
|
||||
#include <kernel/Syscall.h>
|
||||
#include <errno.h>
|
||||
#include <pwd.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
@ -465,3 +466,15 @@ int tcsetpgrp(int fildes, pid_t pgid_id)
|
|||
{
|
||||
return syscall(SYS_TCSETPGRP, fildes, pgid_id);
|
||||
}
|
||||
|
||||
char* getlogin(void)
|
||||
{
|
||||
static char buffer[LOGIN_NAME_MAX];
|
||||
auto* pw = getpwuid(geteuid());
|
||||
if (pw == nullptr)
|
||||
return nullptr;
|
||||
strncpy(buffer, pw->pw_name, LOGIN_NAME_MAX - 1);
|
||||
buffer[LOGIN_NAME_MAX - 1] = '\0';
|
||||
endpwent();
|
||||
return buffer;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue