summaryrefslogtreecommitdiff
path: root/src/id.c
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>1993-09-08 18:23:12 +0000
committerJim Meyering <jim@meyering.net>1993-09-08 18:23:12 +0000
commitae0074289cd7d70cf8fb1d96f2625b2b9bb62b29 (patch)
treed5eab2eede21baf91b94efaf06e0df67cca78887 /src/id.c
parent219bbb0758350d94610e967f31b5f9fdb0728354 (diff)
downloadcoreutils-ae0074289cd7d70cf8fb1d96f2625b2b9bb62b29.tar.xz
merge with 1.8.1 + partial --version and --help
Diffstat (limited to 'src/id.c')
-rw-r--r--src/id.c35
1 files changed, 23 insertions, 12 deletions
diff --git a/src/id.c b/src/id.c
index a6708fbe4..7d55d7105 100644
--- a/src/id.c
+++ b/src/id.c
@@ -23,6 +23,9 @@
#include <sys/types.h>
#include <pwd.h>
#include <grp.h>
+#include <getopt.h>
+
+#include "version.h"
#include "system.h"
#ifdef _POSIX_VERSION
@@ -31,16 +34,6 @@
#define NGROUPS_MAX sysconf (_SC_NGROUPS_MAX)
#endif /* !NGROUPS_MAX */
-/* Even though SunOS 4, Ultrix 4, and 386BSD are mostly POSIX.1 compliant,
- their getgroups system call (except in the `System V' environment, which
- is troublesome in other ways) fills in an array of int, not gid_t
- (which is `short' on those systems). Kludge, kludge. */
-
-#if !defined(sun) && !defined(ultrix) && !defined(__386BSD__)
-#define GETGROUPS_T gid_t
-#else /* sun or ultrix or 386BSD */
-#define GETGROUPS_T int
-#endif /* sun or ultrix or 386BSD */
#else /* not _POSIX_VERSION */
struct passwd *getpwuid ();
struct group *getgrgid ();
@@ -52,7 +45,6 @@ gid_t getegid ();
#if !defined(NGROUPS_MAX) && defined(NGROUPS)
#define NGROUPS_MAX NGROUPS
#endif /* not NGROUPS_MAX and NGROUPS */
-#define GETGROUPS_T int
#endif /* not _POSIX_VERSION */
char *xmalloc ();
@@ -90,13 +82,21 @@ static gid_t rgid, egid;
/* The number of errors encountered so far. */
static int problems = 0;
+/* If non-zero, display usage information and exit. */
+static int show_help;
+
+/* If non-zero, print the version on standard error. */
+static int show_version;
+
static struct option const longopts[] =
{
{"group", no_argument, NULL, 'g'},
+ {"groups", no_argument, NULL, 'G'},
+ {"help", no_argument, &show_help, 1},
{"name", no_argument, NULL, 'n'},
{"real", no_argument, NULL, 'r'},
{"user", no_argument, NULL, 'u'},
- {"groups", no_argument, NULL, 'G'},
+ {"version", no_argument, &show_version, 1},
{NULL, 0, NULL, 0}
};
@@ -114,6 +114,8 @@ main (argc, argv)
{
switch (optc)
{
+ case 0:
+ break;
case 'g':
just_group = 1;
break;
@@ -134,6 +136,15 @@ main (argc, argv)
}
}
+ if (show_version)
+ {
+ printf ("%s\n", version_string);
+ exit (0);
+ }
+
+ if (show_help)
+ usage ();
+
if (just_user + just_group + just_group_list > 1)
error (1, 0, "cannot print only user and only group");