home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume25 / finger / part01 / getgroup.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-04-03  |  1.2 KB  |  54 lines

  1. /*
  2.  * getgroup.c -- report file group ID for autoconfig
  3.  *
  4.  * Copyright (C) 1988, 1990  Philip L. Budne
  5.  *
  6.  * This file is part of "Phil's Finger Program".
  7.  *
  8.  * This program is free software; you can redistribute it and/or modify
  9.  * it under the terms of the GNU General Public License as published by
  10.  * the Free Software Foundation; either version 1, or (at your option)
  11.  * any later version.
  12.  *
  13.  */
  14.  
  15. # ifndef lint
  16. static char *rcsid = "$Id: getgroup.c,v 3.0 90/07/06 13:10:49 budd Rel $";
  17. static char Copyright[] = "Copyright (C) 1986, 1990  Philip L. Budne";
  18. # endif /* lint not defined */
  19.  
  20. # include <sys/types.h>
  21. # include <sys/stat.h>
  22. # include <stdio.h>
  23. # include <grp.h>
  24. /* cannot use finger.h -- run from autoconfig */
  25.  
  26. extern struct group *getgrgid();    /* USG grp.h loses */
  27.  
  28. int
  29. main( c, v )
  30.     int c;
  31.     char **v;
  32. {
  33.     struct stat st;
  34.     struct group *gr;
  35.  
  36.     if( c < 1 ) {
  37.     fprintf( stderr, "Usage %s file\n", v[0] );
  38.     exit( 1 );
  39.     }
  40.     c--;
  41.     v++;
  42.     while( c > 0 ) {
  43.     if( stat( v[0], &st ) < 0 )
  44.         perror( v[0] );
  45.     else if( (gr = getgrgid( st.st_gid )) != NULL )
  46.         printf("%s %d %s\n", v[0], st.st_gid, gr->gr_name );
  47.     else
  48.         printf("%s %d\n", v[0], st.st_gid );
  49.     c--;
  50.     v++;
  51.     }
  52.     return( 0 );            /* be ANSI */
  53. } /* main */
  54.