From a0dd1ebaf7613657a39ca22882ac6eaafa4a932e Mon Sep 17 00:00:00 2001 From: Jakob Kaivo Date: Sat, 9 Feb 2019 15:42:20 -0500 Subject: merge XOPEN identifiers --- src/unistd/cuserid.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/unistd/cuserid.c (limited to 'src/unistd/cuserid.c') diff --git a/src/unistd/cuserid.c b/src/unistd/cuserid.c new file mode 100644 index 00000000..1fa65dbe --- /dev/null +++ b/src/unistd/cuserid.c @@ -0,0 +1,30 @@ +#include "stddef.h" +#include "sys/types.h" +#include +#include "stdio.h" +#include "string.h" +#include "pwd.h" + +char *cuserid(char *s) +{ + static char userid[L_cuserid]; + + struct passwd *pwd = getpwuid(geteuid()); + + if (s == NULL) { + s = userid; + } + + if (pwd == NULL) { + s[0] = '\0'; + } else { + strcpy(s, pwd->pw_name); + } + + return s; +} + +/* +TODO: verify +POSIX(1, 199506) +*/ -- cgit v1.2.1