cygwin.dll/setpwent bug

Tim Newsham newsham@lava.net
Wed Oct 29 17:22:00 GMT 1997


Hi,

   Looks like there is a bug in setpwent/endpwent functions
in winsup/passwd.cc.  The following program should dump all
the usernames in /etc/passwd.  Instead it dumps only the last
username.  This is because setpwent sets the pointer to the last
line in the file, not the first, and getpwent moves forward
in this file.  The fix is:

----- start diff ----
*** passwd.cc.orig      Wed Oct 29 12:20:35 1997
--- passwd.cc   Wed Oct 29 12:20:51 1997
***************
*** 207,220 ****
  void
  setpwent (void)
  {
!   i = curr_lines - 1;
  }

  extern "C"
  void
  endpwent (void)
  {
!   i = 0;
  }

  extern "C"
--- 207,220 ----
  void
  setpwent (void)
  {
!   i = 0;
  }

  extern "C"
  void
  endpwent (void)
  {
!   i = curr_lines;
  }

  extern "C"
----- end diff ----

the test program is:

----- start dumppw.c ----
#include <pwd.h>

int
main()
{
    struct passwd *p;

    setpwent();
    while((p = getpwent())) {
        printf("%s %d\n", p->pw_name, p->pw_passwd);
    }
    printf("done\n");
    return 0;
}


-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".



More information about the Cygwin mailing list