xref: /plan9-contrib/sys/src/ape/lib/ap/plan9/getlogin.c (revision 2d069fea74dfcc83c6858e715bf74862cb64720a)
1 #include <sys/types.h>
2 #include <sys/stat.h>
3 #include <fcntl.h>
4 #include <unistd.h>
5 #include <sys/limits.h>
6 
7 char *
getlogin_r(char * buf,int len)8 getlogin_r(char *buf, int len)
9 {
10 	int f, n;
11 
12 	f = open("/dev/user", O_RDONLY);
13 	if(f < 0)
14 		return 0;
15 	n = read(f, buf, len);
16 	buf[len-1] = 0;
17 	close(f);
18 	return (n>=0)? buf : 0;
19 }
20 
21 char *
getlogin(void)22 getlogin(void)
23 {
24 	static char buf[NAME_MAX+1];
25 
26 	return getlogin_r(buf, sizeof buf);
27 }
28