home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume25 / finger / part01 / mywhoami.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-04-03  |  1022 b   |  42 lines

  1. /*
  2.  * mywhoami.c -- whoami for makefile/make-version on USG systems
  3.  *
  4.  * Copyright (C) 1989, 1990  Philip L. Budne
  5.  *
  6.  * This file is part of "Phil's Finger Program".
  7.  *
  8.  * This program is free software; you can redistribute it and/or modify
  9.  * it under the terms of the GNU General Public License as published by
  10.  * the Free Software Foundation; either version 1, or (at your option)
  11.  * any later version.
  12.  *
  13.  */
  14.  
  15. # ifndef lint
  16. static char *rcsid = "$Id: mywhoami.c,v 3.0 90/07/06 13:11:22 budd Rel $";
  17. static char Copyright[] = "Copyright (C) 1986, 1990  Philip L. Budne";
  18. # endif /* lint not defined */
  19.  
  20. # include <stdio.h>
  21. # include <pwd.h>
  22.  
  23. extern char *getenv();
  24. extern struct passwd *getpwuid();    /* USG pwd.h */
  25.  
  26. # define IFENV(v) if( (e = getenv(v)) != NULL ) puts( e )
  27.  
  28. int
  29. main() {
  30.     struct passwd *pw;
  31.     char *e;
  32.  
  33.     if( (pw = getpwuid( getuid())) != NULL )
  34.     puts( pw->pw_name );
  35.     else IFENV( "USER" );
  36.     else IFENV( "LOGNAME" );
  37.     else
  38.     puts("???");
  39.     return( 0 );            /* be ANSI */
  40. } /* main */
  41.  
  42.