[Opensrf-commits] r1279 - trunk/src/libopensrf
svn at svn.open-ils.org
svn at svn.open-ils.org
Mon Mar 10 10:10:48 EDT 2008
Author: miker
Date: 2008-03-10 09:37:44 -0400 (Mon, 10 Mar 2008)
New Revision: 1279
Modified:
trunk/src/libopensrf/utils.c
Log:
Patch from Scott McKellar providing speed improvement by using fread() instead of fgets()
Modified: trunk/src/libopensrf/utils.c
===================================================================
--- trunk/src/libopensrf/utils.c 2008-03-10 13:32:28 UTC (rev 1278)
+++ trunk/src/libopensrf/utils.c 2008-03-10 13:37:44 UTC (rev 1279)
@@ -459,21 +459,19 @@
if(!filename) return NULL;
- int len = 1024;
- char buf[len];
- osrf_clearbuf(buf, sizeof(buf));
- growing_buffer* gb = buffer_init(len);
-
- FILE* file = fopen(filename, "r");
- if(!file) {
+ FILE * file = fopen( filename, "r" );
+ if( !file ) {
osrfLogError( OSRF_LOG_MARK, "Unable to open file [%s]", filename );
- buffer_free(gb);
return NULL;
}
- while(fgets(buf, sizeof(buf), file)) {
+ size_t num_read;
+ char buf[ BUFSIZ + 1 ];
+ growing_buffer* gb = buffer_init(sizeof(buf));
+
+ while( ( num_read = fread( buf, 1, sizeof(buf) - 1, file) ) ) {
+ buf[ num_read ] = '\0';
buffer_add(gb, buf);
- osrf_clearbuf(buf, sizeof(buf));
}
fclose(file);
More information about the opensrf-commits
mailing list