bug-sysutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug-sysutils] getline patch for gshadow


From: Barry deFreese
Subject: [Bug-sysutils] getline patch for gshadow
Date: Thu, 03 Jun 2004 19:46:59 -0700
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6) Gecko/20040413 Debian/1.6-5

David,

OK, I changed gshadow.c to use getline rather than fgets. Let me know what you think.

Thank you,

--
Barry deFreese
Debian 3.0r1 "Woody"
GNU/Hurd
Registered Linux "Newbie" #302256 - Hurd H4XX0r wannabe

"Programming today is a race between software engineers striving
to build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots. So far, the Universe is
winning." Rich Cook.



Index: src/gshadow.c
===================================================================
RCS file: /cvsroot/sysutils/sysutils/src/gshadow.c,v
retrieving revision 1.2
diff -u -p -r1.2 gshadow.c
--- src/gshadow.c       27 May 2004 07:50:33 -0000      1.2
+++ src/gshadow.c       4 Jun 2004 03:34:44 -0000
@@ -20,6 +20,9 @@
  *  Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
  */
 
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <stdlib.h>
 #include <gshadow.h>
 
 #define BUFSIZE                BUFSIZ * 4
@@ -148,8 +151,8 @@ struct sgrp *sgetsgent(const char *strin
  */
 struct sgrp *fgetsgent(FILE *stream)
 {
-       char buf[sizeof sgbuf];
-       char *p;
+       char *buf;
+       size_t buflen = 0;
 
        /* Abort if no filepointer is provided */
        if (!stream)
@@ -158,16 +161,16 @@ struct sgrp *fgetsgent(FILE *stream)
        /* If all is well, replace the first occurence of '\n'
         * with '\0', then return the parsed entry
         */
-       while (fgets(buf, sizeof buf, stream)) {
+       while (getline(&buf, &buflen, stream)) {
                /* Just skip NIS entries */
                if (buf[0] == NIS_MARKER)
                        continue;
 
-               if ((p = strchr(buf, '\n')))
-                       *p = '\0';
-
                return sgetsgent(buf);
        }
+
+       if (buf)
+               free(buf);
 
        /* Something went wrong.  Abort */
        return 0;

reply via email to

[Prev in Thread] Current Thread [Next in Thread]