antiright-devel
[Top][All Lists]
Advanced

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

[Antiright-devel] antiright/libantiright pipe.c util.c


From: Jeffrey Bedard
Subject: [Antiright-devel] antiright/libantiright pipe.c util.c
Date: Fri, 23 Feb 2007 15:57:53 +0000

CVSROOT:        /sources/antiright
Module name:    antiright
Changes by:     Jeffrey Bedard <jefbed> 07/02/23 15:57:53

Modified files:
        libantiright   : pipe.c util.c 

Log message:
        Added check of data in vsysprintf.  Reimplement pipe reader
        using fread.  

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/antiright/libantiright/pipe.c?cvsroot=antiright&r1=1.2&r2=1.3
http://cvs.savannah.gnu.org/viewcvs/antiright/libantiright/util.c?cvsroot=antiright&r1=1.7&r2=1.8

Patches:
Index: pipe.c
===================================================================
RCS file: /sources/antiright/antiright/libantiright/pipe.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- pipe.c      20 Feb 2007 04:29:43 -0000      1.2
+++ pipe.c      23 Feb 2007 15:57:53 -0000      1.3
@@ -1,7 +1,7 @@
 
 /*
   AntiRight
-  (c) 2002-2006 Jeffrey Bedard
+  (c) 2002-2007 Jeffrey Bedard
   address@hidden
 
   This file is part of AntiRight.
@@ -29,28 +29,23 @@
 {
   char *text_string;
   char buffer[BUFSIZ];
-  FILE *pipe_fp;
-  unsigned int buffer_size = BUFSIZ;
+  FILE *pipe;
+  size_t read, total;
 
   /* Execute the command indicated by command_string.  */
   /* Pipe is read-only.  Stdout will be directed to it.  */
-  pipe_fp = popen (command_string, "r");
+  pipe = popen (command_string, "r");
 
   /* Read the command's stdout.  */
-  /* Read in the first buffer segment.  */
-  fgets (buffer, BUFSIZ, pipe_fp);
-  asprintf (&text_string, "%s", buffer);
-  /* Read in the rest of the buffer segments.  */
-  while (fgets (buffer, BUFSIZ, pipe_fp))
+  while((read = fread (buffer, sizeof (char), BUFSIZ, pipe)) != 0)
   {
-    buffer_size += BUFSIZ;
-    text_string = (char *) realloc (text_string,
-                                   (unsigned long) buffer_size);
-    snprintf (text_string, buffer_size,
-             "%s%s", text_string, (unsigned long) buffer);
+     total += read;
+     text_string = (char*) realloc (text_string, total);
+     snprintf(text_string, total-1, "%s%s", text_string, buffer);
   }
+
   /* Close the pipe once fgets() returns a false condition.  */
-  pclose (pipe_fp);
+  pclose (pipe);
 
   return (text_string);
 }

Index: util.c
===================================================================
RCS file: /sources/antiright/antiright/libantiright/util.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -b -r1.7 -r1.8
--- util.c      20 Feb 2007 04:29:43 -0000      1.7
+++ util.c      23 Feb 2007 15:57:53 -0000      1.8
@@ -1,6 +1,6 @@
 /*
   AntiRight
-  (c) 2002-2005 Jeffrey Bedard
+  (c) 2002-2007 Jeffrey Bedard
   address@hidden
 
   This file is part of AntiRight.




reply via email to

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