------------------------------------------------------------ revno: 11695 revision-id: squid3@treenet.co.nz-20121028095815-csvp7opr6amcu6uf parent: squid3@treenet.co.nz-20121028095713-zwe7xyx4h52170uo author: Francesco Chemolli committer: Amos Jeffries branch nick: 3.2 timestamp: Sun 2012-10-28 03:58:15 -0600 message: Refactored tools/purge conffile reading to c++-streams ------------------------------------------------------------ # Bazaar merge directive format 2 (Bazaar 0.90) # revision_id: squid3@treenet.co.nz-20121028095815-csvp7opr6amcu6uf # target_branch: http://bzr.squid-cache.org/bzr/squid3/branches\ # /SQUID_3_2 # testament_sha1: 507ad319c4960d05e8067715490e6b780374d6ce # timestamp: 2012-10-31 23:03:15 +0000 # source_branch: http://bzr.squid-cache.org/bzr/squid3/branches\ # /SQUID_3_2 # base_revision_id: squid3@treenet.co.nz-20121028095713-\ # zwe7xyx4h52170uo # # Begin patch === modified file 'tools/purge/conffile.cc' --- tools/purge/conffile.cc 2012-07-28 05:38:50 +0000 +++ tools/purge/conffile.cc 2012-10-28 09:58:15 +0000 @@ -48,6 +48,7 @@ #include #include #include +#include int readConfigFile( CacheDirVector& cachedir, const char* fn, FILE* debug ) @@ -61,8 +62,8 @@ // try to open file if ( debug ) fprintf( debug, "# trying to open %s\n", fn ? fn : "(null)" ); - FILE* in = fopen( fn, "r" ); - if ( in == NULL ) { + std::ifstream cfgin(fn); + if (!cfgin) { fprintf( stderr, "fopen %s: %s\n", fn, strerror(errno) ); return -1; } @@ -84,7 +85,7 @@ regmatch_t subs[8]; char *s, line[1024]; CacheDir cd; - while ( fgets( line, sizeof(line), in ) ) { + while ( cfgin.getline( line, sizeof(line)) ) { // FIXME: overly long lines // terminate line at start of comment @@ -102,7 +103,7 @@ fprintf( stderr, "while matching \"%s\" against %s%s\n", expression, line, buffer ); regfree(&rexp); - fclose(in); + cfgin.close(); return -1; } } else { @@ -179,7 +180,7 @@ } } - fclose(in); + cfgin.close(); regfree(&rexp); return cachedir.size(); }