home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 3 / TheARMClub_PDCD3.iso / hensa / unix / unixlib_1 / !UnixLib37_src_pwd_c_getpwent < prev    next >
Encoding:
C/C++ Source or Header  |  1996-11-09  |  1.2 KB  |  58 lines

  1. /****************************************************************************
  2.  *
  3.  * $Source: /unixb/home/unixlib/source/unixlib37/src/pwd/c/RCS/getpwent,v $
  4.  * $Date: 1996/10/30 22:04:51 $
  5.  * $Revision: 1.1 $
  6.  * $State: Rel $
  7.  * $Author: unixlib $
  8.  *
  9.  * $Log: getpwent,v $
  10.  * Revision 1.1  1996/10/30 22:04:51  unixlib
  11.  * Initial revision
  12.  *
  13.  ***************************************************************************/
  14.  
  15. static const char rcs_id[] = "$Id: getpwent,v 1.1 1996/10/30 22:04:51 unixlib Rel $";
  16.  
  17. /* pwd.c.getpwent. Password-file operations.
  18.  
  19.    Written by Nick Burrett, 13 October 1996.  */
  20.  
  21. #include <stddef.h>
  22. #include <stdio.h>
  23. #include <pwd.h>
  24.  
  25. static FILE *stream = NULL;
  26.  
  27. /* Rewind the stream.  */
  28. void setpwent (void)
  29. {
  30.   if (stream != NULL)
  31.     rewind (stream);
  32. }
  33.  
  34. /* Close the stream.  */
  35. void endpwent (void)
  36. {
  37.   if (stream != NULL)
  38.     {
  39.       fclose(stream);
  40.       stream = NULL;
  41.     }
  42. }
  43.  
  44. /* Return one entry from the password file.  */
  45. struct passwd *getpwent (void)
  46. {
  47.   static struct passwd pwd;
  48.  
  49.   /* Open the password file if not already open.  */
  50.   if (stream == NULL)
  51.     stream = fopen ("/etc/passwd", "r");
  52.  
  53.   if (stream == NULL)
  54.     return NULL;
  55.  
  56.   return __pwdread (stream, &pwd);
  57. }
  58.