summaryrefslogtreecommitdiff
path: root/src/unistd/cuserid.c
blob: 1fa65dbe3fb4fd3cb509218c0766488bb5670dc5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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)
*/