home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume14 / libpw / part01 / sortuid.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-07-15  |  445 b   |  36 lines

  1. /*
  2.  * sortuid(d) - check for next available uid after d
  3.  */
  4.  
  5. #include <stdio.h>
  6. #include <pwd.h>
  7.  
  8. struct passwd    *tmp;
  9.  
  10. int sortuid(d)
  11. int    d;
  12. {
  13.     int    i = d-1;
  14.  
  15.     lockpwfile();
  16.     setpwent();
  17.  
  18.     for (;;) {
  19.         if ((tmp = getpwent()) == NULL) {
  20.             unlockpwfile();
  21.             endpwent();
  22.             return 65534;
  23.         }
  24.         if (tmp->pw_uid < d)
  25.             continue;
  26.         if (tmp->pw_uid == i+1) {
  27.             i++;
  28.             continue;
  29.         } else {
  30.             unlockpwfile();
  31.             endpwent();
  32.             return(++i);
  33.         }
  34.     }
  35. }
  36.