summaryrefslogtreecommitdiff
path: root/src/legacy
diff options
context:
space:
mode:
authorSören Tempel <soeren+git@soeren-tempel.net>2020-01-29 12:20:07 +0100
committerRich Felker <dalias@aerifal.cx>2021-02-13 13:40:22 -0500
commitef137da6428c342baabd3bcf9b5e91f75acefa64 (patch)
treea842757ed096938924aff74be9eaf50fcbc2ac2d /src/legacy
parente5d2823631bbfebacf48e1a34ed28f28d7cb2570 (diff)
downloadmusl-ef137da6428c342baabd3bcf9b5e91f75acefa64.tar.gz
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.
Diffstat (limited to 'src/legacy')
-rw-r--r--src/legacy/cuserid.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/src/legacy/cuserid.c b/src/legacy/cuserid.c
index 4e78798d..fd7832e4 100644
--- a/src/legacy/cuserid.c
+++ b/src/legacy/cuserid.c
@@ -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;
}