Patch from Scott McKellar providing speed improvement by using fread() instead of...
authormiker <miker@9efc2488-bf62-4759-914b-345cdb29e865>
Mon, 10 Mar 2008 13:37:44 +0000 (13:37 +0000)
committermiker <miker@9efc2488-bf62-4759-914b-345cdb29e865>
Mon, 10 Mar 2008 13:37:44 +0000 (13:37 +0000)
git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@1279 9efc2488-bf62-4759-914b-345cdb29e865

src/libopensrf/utils.c

index 4b156bb..01fd382 100644 (file)
@@ -459,21 +459,19 @@ char* file_to_string(const char* filename) {
 
        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);