diff --git a/libc/include/limits.h b/libc/include/limits.h index 4df636d524..05a634ab5d 100644 --- a/libc/include/limits.h +++ b/libc/include/limits.h @@ -59,6 +59,7 @@ __BEGIN_DECLS #define OPEN_MAX 64 #define NAME_MAX 255 +#define LOGIN_NAME_MAX 256 __END_DECLS diff --git a/libc/unistd.cpp b/libc/unistd.cpp index bec5435ee0..689a19c0d0 100644 --- a/libc/unistd.cpp +++ b/libc/unistd.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include @@ -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; +}