diff options
Diffstat (limited to 'libc-top-half/musl/src/legacy/cuserid.c')
-rw-r--r-- | libc-top-half/musl/src/legacy/cuserid.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/libc-top-half/musl/src/legacy/cuserid.c b/libc-top-half/musl/src/legacy/cuserid.c new file mode 100644 index 0000000..dcaf73d --- /dev/null +++ b/libc-top-half/musl/src/legacy/cuserid.c @@ -0,0 +1,22 @@ +#define _GNU_SOURCE +#include <pwd.h> +#include <stdio.h> +#include <unistd.h> +#include <string.h> + +char *cuserid(char *buf) +{ + static char usridbuf[L_cuserid]; + struct passwd pw, *ppw; + long pwb[256]; + if (buf) *buf = 0; + getpwuid_r(geteuid(), &pw, (void *)pwb, sizeof pwb, &ppw); + if (!ppw) + return buf; + size_t len = strnlen(pw.pw_name, L_cuserid); + if (len == L_cuserid) + return buf; + if (!buf) buf = usridbuf; + memcpy(buf, pw.pw_name, len+1); + return buf; +} |