]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - tools/purge/conffile.cc
SourceFormat Enforcement
[thirdparty/squid.git] / tools / purge / conffile.cc
index 177051ca23cd67ff09e6b3a37d48876c914d21e3..84cfb4cc93ee60be0f698ba58a9e57402b223365 100644 (file)
@@ -1,8 +1,11 @@
-#include "squid.h"
+/*
+ * Copyright (C) 1996-2015 The Squid Software Foundation and contributors
+ *
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
+ */
 
-//
-// $Id$
-//
 // Author:  Jens-S. V?ckler <voeckler@rvs.uni-hannover.de>
 //
 // File:    conffile.cc
 // Revision 1.1  2000/09/21 09:44:53  voeckler
 // Initial revision
 //
-//
-#if (defined(__GNUC__) || defined(__GNUG__)) && !defined(__clang__)
-#pragma implementation
-#endif
 
+#include "squid.h"
 #include "conffile.hh"
+
+#include <cerrno>
+#include <cstdlib>
+#include <cstring>
+#include <fstream>
 #include <sys/types.h>
-#include <errno.h>
 #include <memory.h>
-#include <string.h>
-#include <stdlib.h>
-#include <stdio.h>
 
 int
 readConfigFile( CacheDirVector& cachedir, const char* fn, FILE* debug )
@@ -61,8 +62,8 @@ readConfigFile( CacheDirVector& cachedir, const char* fn, FILE* debug )
 
     // 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 @@ readConfigFile( CacheDirVector& cachedir, const char* fn, FILE* debug )
     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 @@ readConfigFile( CacheDirVector& cachedir, const char* fn, FILE* debug )
                 fprintf( stderr, "while matching \"%s\" against %s%s\n",
                          expression, line, buffer );
                 regfree(&rexp);
-                fclose(in);
+                cfgin.close();
                 return -1;
             }
         } else {
@@ -136,7 +137,7 @@ readConfigFile( CacheDirVector& cachedir, const char* fn, FILE* debug )
                     cd.type = CacheDir::CDT_DISKD;
                 else
                     cd.type = CacheDir::CDT_OTHER;
-                offset++;
+                ++offset;
             }
 
             // extract base directory
@@ -145,8 +146,8 @@ readConfigFile( CacheDirVector& cachedir, const char* fn, FILE* debug )
                                       (int)subs[offset].rm_so,
                                       (int)subs[offset].rm_eo,
                                       line+subs[offset].rm_so );
-            cd.base = strdup( line+subs[offset].rm_so );
-            offset++;
+            cd.base = xstrdup( line+subs[offset].rm_so );
+            ++offset;
 
             // extract size information
             line[ subs[offset].rm_eo ] = '\0';
@@ -155,7 +156,7 @@ readConfigFile( CacheDirVector& cachedir, const char* fn, FILE* debug )
                                       (int)subs[offset].rm_eo,
                                       line+subs[offset].rm_so );
             cd.size = strtoul( line+subs[offset].rm_so, 0, 10 );
-            offset++;
+            ++offset;
 
             // extract 1st level directories
             line[ subs[offset].rm_eo ] = '\0';
@@ -164,7 +165,7 @@ readConfigFile( CacheDirVector& cachedir, const char* fn, FILE* debug )
                                       (int)subs[offset].rm_eo,
                                       line+subs[offset].rm_so );
             cd.level[0] = strtoul( line+subs[offset].rm_so, 0, 10 );
-            offset++;
+            ++offset;
 
             // extract 2nd level directories
             line[ subs[offset].rm_eo ] = '\0';
@@ -173,13 +174,14 @@ readConfigFile( CacheDirVector& cachedir, const char* fn, FILE* debug )
                                       (int)subs[offset].rm_eo,
                                       line+subs[offset].rm_so );
             cd.level[1] = strtoul( line+subs[offset].rm_so, 0, 10 );
-            offset++;
+            ++offset;
 
             cachedir.push_back( cd );
         }
     }
 
-    fclose(in);
+    cfgin.close();
     regfree(&rexp);
     return cachedir.size();
 }
+