1: #include    <stdio.h>
   2: #include    <sys/types.h>
   3: #include    <pwd.h>
   4: #include    <time.h>
   5: 
   6: main()
   7:     {
   8:     struct  tm  *tm;
   9:     struct  passwd  *pw;
  10:     char    *cp;
  11:     time_t  l;
  12:     uid_t   uid;
  13: 
  14:     l = time(0);
  15:     cp = ctime(&l);
  16:     printf("ctime(%ld) = %s", l, cp);
  17:     tm = gmtime(&l);
  18:     dump_tm("gmtime", tm);
  19:     cp = asctime(tm);
  20:     printf("asctime(tm) = %s", cp);
  21:     tm = localtime(&l);
  22:     dump_tm("localtime", tm);
  23: 
  24:     if  (setpassent(1))
  25:         printf("setpassent(1) returned non-zero (success) status\n");
  26:     else
  27:         printf("setpassent(1) returned zero (shouldn't happen)\n");
  28: 
  29:     printf("getpwent\n");
  30:     while   (pw = getpwent())
  31:         {
  32:         dump_pw(pw);
  33:         }
  34:     printf("getpwnam(root)\n");
  35:     pw = getpwnam("root");
  36:     if  (!pw)
  37:         printf("OOPS - root doesn't apparently exist\n");
  38:     else
  39:         dump_pw(pw);
  40:     printf("getpwnam(nobody)\n");
  41:     pw = getpwnam("nobody");
  42:     if  (!pw)
  43:         printf("OOPS - nobody doesn't apparently exist\n");
  44:     uid = pw->pw_uid;
  45:     printf("getpwuid\n");
  46:     pw = getpwuid(uid);
  47:     if  (!pw)
  48:         printf("OOPS - uid %u (from nobody) doesn't exist\n", uid);
  49:     else
  50:         dump_pw(pw);
  51: 
  52:     printf("endpwent\n");
  53:     endpwent();
  54:     }
  55: 
  56: dump_tm(str, tm)
  57:     char    *str;
  58:     struct  tm *tm;
  59:     {
  60:     printf("%s sec: %d min: %d hr: %d mday: %d mon: %d yr: %d wday: %d yday: %d isdst: %d zone: %s gmtoff: %d\n",
  61:         str,
  62:         tm->tm_sec,
  63:         tm->tm_min,
  64:         tm->tm_hour,
  65:         tm->tm_mday,
  66:         tm->tm_mon,
  67:         tm->tm_year,
  68:         tm->tm_wday,
  69:         tm->tm_yday,
  70:         tm->tm_isdst,
  71:         tm->tm_zone,
  72:         tm->tm_gmtoff);
  73:     }
  74: 
  75: dump_pw(p)
  76:     struct  passwd *p;
  77:     {
  78:     printf("%s:%s:%u:%u:%s:%ld:%ld:%s:%s:%s\n",
  79:         p->pw_name,
  80:         p->pw_passwd,
  81:         p->pw_uid, p->pw_gid,
  82:         p->pw_class, p->pw_change, p->pw_expire,
  83:         p->pw_gecos, p->pw_dir, p->pw_shell);
  84:     }

Defined functions

dump_pw defined in line 75; used 3 times
dump_tm defined in line 56; used 2 times
main defined in line 6; never used
Last modified: 1996-06-26
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1145
Valid CSS Valid XHTML 1.0 Strict