home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
unix
/
volume26
/
idutil
/
getlogin.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-06-12
|
1KB
|
68 lines
/*
** NAME : getlogin.c
** PURPOSE : Shell level access to getlogin(3)
*/
#include <stdio.h>
#include <errno.h>
#include <gnu/fileutil.h>
static char *RCSid="$Header: getlogin.c,v 1.3 92/02/25 14:00:06 dtb Exp $";
int fpr_usage();
static char *trim_main_name;
static short main_verbose = 0;
int main ( argc, argv, envp )
int argc;
char **argv;
char **envp;
{
char *optstring = "Iv" ;
int optchar;
extern char *optarg;
extern int optind;
extern int opterr;
char *login_name;
int rval = 0; /* Default return success */
trim_main_name = basename(*argv);
main_verbose = 0; /* verbose off */
opterr = 0;
while ((optchar = getopt(argc, argv, optstring)) != -1)
switch (optchar) {
case 'I':
fprintf (stderr, "%s %s\n", __FILE__, RCSid);
break;
case 'v':
main_verbose = 1;
break;
case '?':
fpr_usage (stderr);
exit (EINVAL);
}
if ((login_name = (char *)getlogin())==NULL) {
if (main_verbose) {
fprintf(stderr, "%s: getlogin() returned null\n",
trim_main_name);
rval = 1;
}
} else {
if (main_verbose)
printf("Your login according to /etc/utmp is ");
printf ("%s\n", login_name);
}
return (rval);
}
int fpr_usage (fp)
FILE *fp;
{
int nout = 0;
nout += fprintf (stderr, "Usage: %s [-v]\n", trim_main_name);
return (nout);
}