k9core

Coreutils for *nix operating systems [fork]
git clone git://bvnf.space/k9core.git
Log | Files | Refs | LICENSE

whoami.c (359B)


      1
      2
      3
      4
      5
      6
      7
      8
      9
     10
     11
     12
     13
     14
     15
     16
     17
     18
     19
     20
#include <errno.h>
#include <pwd.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>

int
main(void)
{
	errno = 0;
	struct passwd *user_data = getpwuid(getuid());
	if(user_data == NULL) {
		fprintf(stderr,
			   "whoami: %s\n",
			   errno == 0 ? "user not found" : strerror(errno));
		return 1;
	}
	printf("%s\n", user_data->pw_name);
	return 0;
}