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

  1. /*
  2.  * sortgrp(str) - returns the appropriate gid for group name str
  3.  */
  4.  
  5. #include <stdio.h>
  6. #include <grp.h>
  7.  
  8. struct group    *gr;
  9.  
  10. sortgrp(str)
  11. char    str[20];
  12. {
  13.     lockgrfile();
  14.     setgrent();
  15.     
  16.     while ((gr = getgrent()) != NULL) {
  17.         if (strcmp(gr->gr_name, str) == 0) { /* Compare gname */
  18.             endgrent();
  19.             unlockgrfile();
  20.             return(gr->gr_gid);    /* return gid */
  21.         }
  22.     }
  23.     unlockgrfile();
  24.     endgrent();
  25.     return(-1);
  26. }
  27.