shithub: purgatorio

ref: 015c3ecea040a3e2b7fdacc73e4cc7d289924ad6
dir: /lib9/getuser-posix.c/

View raw version
#include "lib9.h"
#include <pwd.h>

char*
getuser(void)
{
	struct passwd *p;

	static char *user = 0;

	if (!user) {
		p = getpwuid(getuid());
		if (p && p->pw_name) {
			user = malloc(strlen(p->pw_name)+1);
			if (user)
				strcpy(user, p->pw_name);
		}
	}
	if(!user)
		user = "unknown";
	return user;
}