docker-hello/alpine/hello.c

31 lines
517 B
C
Raw Normal View History

2017-08-31 07:53:47 +00:00
#define _GNU_SOURCE
#include <stdlib.h>
#include <unistd.h>
#include <pwd.h>
#include <stdio.h>
#include <errno.h>
extern char *program_invocation_name;
extern char *program_invocation_short_name;
int main() {
register struct passwd *pw;
register uid_t uid;
printf("This is %s speaking.\n", program_invocation_name);
uid = geteuid();
pw = getpwuid(uid);
if (pw)
{
printf("Hello, %s!\n", pw->pw_name);
}
else
{
printf("I don't know your name but your ID is %d!\n", (unsigned) uid);
}
return 0;
}