]> git.ipfire.org Git - thirdparty/sarg.git/blobdiff - longline.c
Optimize away a useless strcpy.
[thirdparty/sarg.git] / longline.c
index 1261ea93a2f9796789850199c58d6b6082465e4c..2e4761d919a982c5ab7c84ce6f9d826b778c0557 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * SARG Squid Analysis Report Generator      http://sarg.sourceforge.net
- *                                                            1998, 2012
+ *                                                            1998, 2015
  *
  * SARG donations:
  *      please look at http://sarg.sourceforge.net/donations.php
@@ -94,11 +94,11 @@ void longline_reset(longline line)
        }
 }
 
-char *longline_read(FILE *fp_in,longline line)
+char *longline_read(FileObject *fp_in,longline line)
 {
        int i;
        char *newbuf;
-       size_t nread;
+       int nread;
 
        if (line==NULL || line->buffer==NULL) return(NULL);
 
@@ -108,8 +108,8 @@ char *longline_read(FILE *fp_in,longline line)
                        line->end=i;
                        break;
                }
-               nread=(feof(fp_in)!=0) ? 0 : fread(line->buffer,1,line->size,fp_in);
-               if (nread==0) return(NULL);
+               nread=(FileObject_Eof(fp_in)!=0) ? 0 : FileObject_Read(fp_in,line->buffer,line->size);
+               if (nread<=0) return(NULL);
                line->length=nread;
                line->end=0;
        }
@@ -133,25 +133,25 @@ char *longline_read(FILE *fp_in,longline line)
                if (line->length>=line->size) {
                        line->size+=LINE_BUFFER_SIZE_INCREMENT;
                        if (line->size>=MAX_LINE_BUFFER_SIZE) {
-                               debuga(_("A text line is more than %d bytes long denoting a corrupted file\n"),MAX_LINE_BUFFER_SIZE);
+                               debuga(__FILE__,__LINE__,_("A text line is more than %d bytes long denoting a corrupted file\n"),MAX_LINE_BUFFER_SIZE);
                                exit(EXIT_FAILURE);
                        }
                        newbuf=realloc(line->buffer,line->size);
                        if (!newbuf) {
-                               debuga(_("Not enough memory to read one more line from the file\n"));
+                               debuga(__FILE__,__LINE__,_("Not enough memory to read one more line from the file\n"));
                                exit(EXIT_FAILURE);
                        }
                        line->buffer=newbuf;
                }
-               nread=(feof(fp_in)!=0) ? 0 : fread(line->buffer+line->length,1,line->size-line->length,fp_in);
-               if (nread==0) {
+               nread=(FileObject_Eof(fp_in)!=0) ? 0 : FileObject_Read(fp_in,line->buffer+line->length,line->size-line->length);
+               if (nread<=0) {
                        if (line->end<=line->start) return(NULL);
                        if (line->end>=line->size) {
                                line->end=line->size;
                                line->size++;
                                newbuf=realloc(line->buffer,line->size);
                                if (!newbuf) {
-                                       debuga(_("Not enough memory to read one more line from the file\n"));
+                                       debuga(__FILE__,__LINE__,_("Not enough memory to read one more line from the file\n"));
                                        exit(EXIT_FAILURE);
                                }
                                line->buffer=newbuf;