]> git.proxmox.com Git - wasi-libc.git/blame - libc-top-half/musl/src/legacy/cuserid.c
Update to musl 1.2.3.
[wasi-libc.git] / libc-top-half / musl / src / legacy / cuserid.c
CommitLineData
320054e8
DG
1#define _GNU_SOURCE
2#include <pwd.h>
3#include <stdio.h>
4#include <unistd.h>
5d8a1409 5#include <string.h>
320054e8
DG
6
7char *cuserid(char *buf)
8{
5d8a1409 9 static char usridbuf[L_cuserid];
320054e8
DG
10 struct passwd pw, *ppw;
11 long pwb[256];
5d8a1409
DG
12 if (buf) *buf = 0;
13 getpwuid_r(geteuid(), &pw, (void *)pwb, sizeof pwb, &ppw);
14 if (!ppw)
15 return buf;
16 size_t len = strnlen(pw.pw_name, L_cuserid);
17 if (len == L_cuserid)
18 return buf;
19 if (!buf) buf = usridbuf;
20 memcpy(buf, pw.pw_name, len+1);
320054e8
DG
21 return buf;
22}