home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume26 / cputt-2.3 / part01 / hash.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-04-05  |  1001 b   |  50 lines

  1. #include     <sys/user.h>
  2. #include     <kvm.h>
  3. #include     <pwd.h>
  4. #include     "cputt.h"
  5.  
  6. #define       HASHFN1(a) (((unsigned)(a)*91 + 17) % MAXUSERS)
  7.  
  8. /*
  9.    HASHUID - Returns a pointer to a slot in the hash table that corresponds
  10.    to the hash table entry for `uid'. It returns a null pointer if there is
  11.    no such slot.
  12. */
  13.  
  14. struct hashtab *
  15. hashuid(uid)
  16. int      uid;
  17. {
  18.      struct hashtab *hp;
  19.  
  20.      hp = &Info.i_hnames[HASHFN1(uid)];
  21.      if (hp->h_uid == uid)
  22.          return(hp);
  23.      return(0);
  24. }
  25.  
  26. /*
  27.    INITUSERS - builds the uid hash table.
  28. */
  29.  
  30. void
  31. initusers ()
  32. {
  33.      struct passwd  *pw;
  34.      struct hashtab *hp;
  35.      struct passwd  *getpwent();
  36.  
  37.      while (pw = getpwent())
  38.      {
  39.           /* Try to find a free slot in the hash table and fill it. */
  40.  
  41.           hp = &Info.i_hnames[HASHFN1(pw->pw_uid)];
  42.           if (!hp->h_uname[0])
  43.           {
  44.                hp->h_uid = pw->pw_uid;
  45.                strncpy(hp->h_uname,pw->pw_name,UNAMELEN);
  46.           }
  47.      }
  48.      endpwent();
  49. }
  50.