31 lines
517 B
C
31 lines
517 B
C
|
#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;
|
||
|
}
|