xref: /plan9-contrib/sys/src/ape/lib/ap/plan9/getpwnam.c (revision 781103c4074deb8af160e8a0da2742ba6b29dc2b)
1 #include "lib.h"
2 #include <stddef.h>
3 #include <pwd.h>
4 #include <string.h>
5 
6 static struct passwd holdpw;
7 static char dirbuf[40] = "/usr/";
8 static char *rc = "/bin/rc";
9 
10 struct passwd *
getpwnam(const char * name)11 getpwnam(const char *name)
12 {
13 	int num;
14 	char *nam, *mem;
15 
16 	num = 0;
17 	nam = (char *)name;
18 	mem = 0;
19 	if(_getpw(&num, &nam, &mem)){
20 		holdpw.pw_name = nam;
21 		holdpw.pw_uid = num;
22 		holdpw.pw_gid = num;
23 		strncpy(dirbuf+5, nam, sizeof(dirbuf)-6);
24 		holdpw.pw_dir = dirbuf;
25 		holdpw.pw_shell = rc;
26 		return &holdpw;
27 	}
28 	return NULL;
29 }
30