aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2005-09-17 16:17:01 +0000
committerSergey Poznyakoff <gray@gnu.org.ua>2005-09-17 16:17:01 +0000
commit71391d8b5d3e2fe5e94ff67cac0af39a3ab026dd (patch)
tree94cf0a225d04118019587450a7323f8aaa5b0ce5
parentcc7eb499511a15a8f4a22f6a88109546688d799c (diff)
downloadcflow-71391d8b5d3e2fe5e94ff67cac0af39a3ab026dd.tar.gz
cflow-71391d8b5d3e2fe5e94ff67cac0af39a3ab026dd.tar.bz2
A sample program
-rw-r--r--doc/whoami.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/doc/whoami.c b/doc/whoami.c
new file mode 100644
index 0000000..59f9180
--- /dev/null
+++ b/doc/whoami.c
@@ -0,0 +1,34 @@
+/* whoami.c - a simple implementation of whoami utility */
+#include <pwd.h>
+#include <sys/types.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+int
+who_am_i (void)
+{
+ struct passwd *pw;
+ char *user = NULL;
+
+ pw = getpwuid (geteuid ());
+ if (pw)
+ user = pw->pw_name;
+ else if ((user = getenv ("USER")) == NULL)
+ {
+ fprintf (stderr, "I don't know!\n");
+ return 1;
+ }
+ printf ("%s\n", user);
+ return 0;
+}
+
+int
+main (int argc, char **argv)
+{
+ if (argc > 1)
+ {
+ fprintf (stderr, "usage: whoami\n");
+ return 1;
+ }
+ return who_am_i ();
+}

Return to:

Send suggestions and report system problems to the System administrator.