summaryrefslogtreecommitdiff
path: root/src/unistd/cuserid.c
diff options
context:
space:
mode:
authorJakob Kaivo <jkk@ung.org>2019-02-09 15:42:20 -0500
committerJakob Kaivo <jkk@ung.org>2019-02-09 15:42:20 -0500
commita0dd1ebaf7613657a39ca22882ac6eaafa4a932e (patch)
treedc42ba738026d373fde4e6df7913e1bdd3b4ac30 /src/unistd/cuserid.c
parent452ac2f7d9d5ecd57e80d95e5752f8c8304ff0b0 (diff)
merge XOPEN identifiers
Diffstat (limited to 'src/unistd/cuserid.c')
-rw-r--r--src/unistd/cuserid.c30
1 files changed, 30 insertions, 0 deletions
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 <unistd.h>
+#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)
+*/