]> git.ipfire.org Git - thirdparty/sarg.git/blobdiff - splitlog.c
Indent the configure script for more readability.
[thirdparty/sarg.git] / splitlog.c
index 2273603f1b6a28c62e71222d12bca2a2f7be2b61..0816e03fdf381ebf13eca0842b9ee6241c115f53 100644 (file)
@@ -46,7 +46,7 @@ the files are named after the day they contain prefixed with the string containe
 */
 void splitlog(const char *arq, char df, int dfrom, int duntil, int convert, const char *splitprefix)
 {
-       FILE *fp_in;
+       FileObject *fp_in;
        FILE *fp_ou=NULL;
        char *buf;
        char data[30];
@@ -67,7 +67,7 @@ void splitlog(const char *arq, char df, int dfrom, int duntil, int convert, cons
                // '/' + '-YYYY-mm-dd' + '\0' == 13
                output_prefix_len=snprintf(output_file,sizeof(output_file)-12,"%s%s",outdir,splitprefix);
                if (output_prefix_len>=sizeof(output_file)-12) {
-                       debuga(_("Path too long: "));
+                       debuga(__FILE__,__LINE__,_("Path too long: "));
                        debuga_more("%s%s-YYYY-mm-dd\n",outdir,splitprefix);
                        exit(EXIT_FAILURE);
                }
@@ -79,13 +79,13 @@ void splitlog(const char *arq, char df, int dfrom, int duntil, int convert, cons
        if(arq[0] == '\0')
                arq="/var/log/squid/access.log";
 
-       if((fp_in=MY_FOPEN(arq,"r"))==NULL) {
-               debuga(_("Cannot open file \"%s\": %s\n"),arq,strerror(errno));
+       if((fp_in=FileObject_Open(arq))==NULL) {
+               debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),arq,FileObject_GetLastOpenError());
                exit(EXIT_FAILURE);
        }
 
        if ((line=longline_create())==NULL) {
-               debuga(_("Not enough memory to read the log file %s\n"),arq);
+               debuga(__FILE__,__LINE__,_("Not enough memory to read file \"%s\"\n"),arq);
                exit(EXIT_FAILURE);
        }
        time(&min_tt);
@@ -93,7 +93,7 @@ void splitlog(const char *arq, char df, int dfrom, int duntil, int convert, cons
        while((buf=longline_read(fp_in,line))!=NULL) {
                getword_start(&gwarea,buf);
                if (getword(data,sizeof(data),&gwarea,' ')<0) {
-                       debuga(_("Invalid date in file \"%s\"\n"),arq);
+                       debuga(__FILE__,__LINE__,_("Invalid date in file \"%s\"\n"),arq);
                        exit(EXIT_FAILURE);
                }
                tt=atoi(data);
@@ -110,7 +110,7 @@ void splitlog(const char *arq, char df, int dfrom, int duntil, int convert, cons
                        prev_month=t->tm_mon;
                        prev_day=t->tm_mday;
                        if (fp_ou && fclose(fp_ou)==EOF) {
-                               debuga(_("Write error in \"%s\": %s\n"),output_file,strerror(errno));
+                               debuga(__FILE__,__LINE__,_("Write error in \"%s\": %s\n"),output_file,strerror(errno));
                                exit(EXIT_FAILURE);
                        }
                        strftime(output_file+output_prefix_len, sizeof(output_file)-output_prefix_len, "-%Y-%m-%d", t);
@@ -120,7 +120,7 @@ void splitlog(const char *arq, char df, int dfrom, int duntil, int convert, cons
                        a second time.
                        */
                        if ((fp_ou=MY_FOPEN(output_file,(tt>=min_tt && tt<=max_tt) ? "a" : "w"))==NULL) {
-                               debuga(_("Cannot open file \"%s\": %s\n"),output_file,strerror(errno));
+                               debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),output_file,strerror(errno));
                                exit(EXIT_FAILURE);
                        }
                        if (tt<min_tt) min_tt=tt;
@@ -140,13 +140,13 @@ void splitlog(const char *arq, char df, int dfrom, int duntil, int convert, cons
        }
 
        longline_destroy(&line);
-       if (fclose(fp_in)==EOF) {
-               debuga(_("Read error in \"%s\": %s\n"),arq,strerror(errno));
+       if (FileObject_Close(fp_in)) {
+               debuga(__FILE__,__LINE__,_("Read error in \"%s\": %s\n"),arq,FileObject_GetLastCloseError());
                exit(EXIT_FAILURE);
        }
        if (autosplit && fp_ou) {
                if (fclose(fp_ou)==EOF) {
-                       debuga(_("Write error in \"%s\": %s\n"),output_file,strerror(errno));
+                       debuga(__FILE__,__LINE__,_("Write error in \"%s\": %s\n"),output_file,strerror(errno));
                        exit(EXIT_FAILURE);
                }
        }