"Fossies" - the Fresh Open Source Software Archive

Member "rgdbm-2.1.42/group.c" (6 Jun 2007, 1440 Bytes) of package /linux/privat/old/rgdbm-2.1.42.tgz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "group.c" see the Fossies "Dox" file reference documentation.

    1 /* 
    2  * RGDBM group file manipulation code (C) Peter T. Breuer 2007.
    3  *
    4  * This code is releasd under the GNU General Public Licence (GPL)
    5  * version 2 or such later version as the FSF may release in the
    6  * fullness of time (when this licence automatically becomes THAT
    7  * licence). See GPL_V2 file in the code archive for details.
    8  */
    9 
   10 #include "config.h"
   11 
   12 #include <stdio.h>
   13 #if STDC_HEADERS
   14 # include <stdlib.h>
   15 # include <stdarg.h>
   16 # include <string.h>
   17 #else
   18 # ifndef HAVE_STRCHR
   19 #  define strchr index
   20 #  define strrchr rindex
   21 # endif
   22 char *strchr (), *strrchr ();
   23 # ifndef HAVE_MEMCPY
   24 #  define memcpy(d, s, n) bcopy ((s), (d), (n))
   25 #  define memmove(d, s, n) bcopy ((s), (d), (n))
   26 # endif
   27 #endif          /* STDC_HEADERS */
   28 
   29 #include <sys/types.h> /* for uid_t type */
   30 #include <grp.h>       /* for group struct */
   31 
   32 #include "group.h"
   33 
   34 /*
   35  * find group entry in given group's file stream.
   36  * remember to close or rewind after
   37  */
   38 struct group *
   39 fgetgrgid (FILE * grf, int gid)
   40 {
   41 
   42     struct group *gre;
   43 
   44     while (gre = fgetgrent (grf), gre) {
   45         if (gre->gr_gid == gid)
   46             return gre;
   47     }
   48     return gre;
   49 }
   50 
   51 /*
   52  * find group entry in given group's file stream.
   53  * remember to close or rewind after
   54  */
   55 struct group *
   56 fgetgrnam (FILE * grf, char *name)
   57 {
   58 
   59     struct group *gre;
   60 
   61     while (gre = fgetgrent (grf), gre) {
   62         if (strcmp (gre->gr_name, name) == 0)
   63             return gre;
   64     }
   65     return gre;
   66 }
   67 
   68