Subject: cygwin.dll/setpwent bug
From: [email-masked] (Tim Newsham)

29 Oct 1997 20:50:33 -0800
Message-ID: <[email-masked]>
Mime-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
To: [email-masked], [email-masked]

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
"[email-masked]" with one line of text: "help".