Implement -g and -u for id(1)

This commit is contained in:
sin 2014-06-11 15:42:33 +01:00
parent d3e332c72d
commit db0ea785f0
2 changed files with 14 additions and 2 deletions

8
id.1
View File

@ -2,13 +2,19 @@
.SH NAME
\fBid\fR - Print real and effective user and group IDs
.SH SYNOPSIS
\fBid\fR [\fB-G\fR] \fR[\fIuser\fR|\fIuid\fR]
\fBid\fR [\fB-g\fR] [\fB-u\fR] [\fB-G\fR] \fR[\fIuser\fR|\fIuid\fR]
.SH DESCRIPTION
\fBid\fR prints user and group information of the calling process to standard output.
If a login name or uid is specified, the user and group information of that
user is displayed.
.SH OPTIONS
.TP
\fB-g\fR
Print only the effective group ID.
.TP
\fB-u\fR
Print only the effective user ID.
.TP
\fB-G\fR
Display group information as whitespace separated numbers, in no particular order.
.SH SEE ALSO

8
id.c
View File

@ -18,7 +18,7 @@ static void usernam(const char *nam);
static void
usage(void)
{
eprintf("usage: %s [-G] [user | uid]\n", argv0);
eprintf("usage: %s [-g] [-u] [-G] [user | uid]\n", argv0);
}
static int Gflag = 0;
@ -27,6 +27,12 @@ int
main(int argc, char *argv[])
{
ARGBEGIN {
case 'g':
printf("%d\n", getegid());
return EXIT_SUCCESS;
case 'u':
printf("%d\n", geteuid());
return EXIT_SUCCESS;
case 'G':
Gflag = 1;
break;