mirror of
git://git.musl-libc.org/musl
synced 2025-03-06 20:48:29 +01:00
cuserid: support invocation with a null pointer argument
this function was removed from the standard in 2001 but appeared in SUSv2 with an obligation to support calls with a null pointer argument, using a static buffer.
This commit is contained in:
parent
e5d2823631
commit
ef137da642
1 changed files with 2 additions and 0 deletions
|
@ -5,10 +5,12 @@
|
|||
|
||||
char *cuserid(char *buf)
|
||||
{
|
||||
static char usridbuf[L_cuserid];
|
||||
struct passwd pw, *ppw;
|
||||
long pwb[256];
|
||||
if (getpwuid_r(geteuid(), &pw, (void *)pwb, sizeof pwb, &ppw))
|
||||
return 0;
|
||||
if (!buf) buf = usridbuf;
|
||||
snprintf(buf, L_cuserid, "%s", pw.pw_name);
|
||||
return buf;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue