2021-06-29 11:19:44 +00:00
|
|
|
#include <getopt.h>
|
2020-07-08 09:28:21 +00:00
|
|
|
#include <pwd.h>
|
2021-06-29 11:19:44 +00:00
|
|
|
#include <stdio.h>
|
2020-07-08 09:28:21 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
int
|
2021-06-29 11:19:44 +00:00
|
|
|
main(int argc, char* argv[])
|
2020-07-08 09:28:21 +00:00
|
|
|
{
|
2021-06-29 11:19:44 +00:00
|
|
|
int c = getopt(argc, argv, "Ggnru");
|
|
|
|
struct passwd* user_data = getpwnam(getlogin());
|
|
|
|
switch (c) {
|
|
|
|
case 'g':
|
|
|
|
case 'u':
|
|
|
|
printf("%u\n", user_data->pw_gid);
|
|
|
|
break;
|
|
|
|
case 'n':
|
|
|
|
printf("%s\n", user_data->pw_name);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printf("%u %s\n",
|
|
|
|
user_data->pw_gid,
|
|
|
|
user_data->pw_name); /* I know
|
|
|
|
* it does not work
|
|
|
|
* like this */
|
|
|
|
}
|
2020-07-08 09:28:21 +00:00
|
|
|
|
2021-06-29 11:19:44 +00:00
|
|
|
return 0;
|
2020-07-08 09:28:21 +00:00
|
|
|
}
|