tOpen infile/outfile only when needed - scribo - Email-based phlog generator
 (HTM) git clone git://git.z3bra.org/scribo.git
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit edd08054989a560b60a1039cd25e405a59dae81c
 (DIR) parent e4acb5dbbe7330f20b7762305f9b1e291c3efe92
 (HTM) Author: Willy Goiffon <dev@z3bra.org>
       Date:   Tue,  8 Sep 2020 13:35:28 +0200
       
       Open infile/outfile only when needed
       
       Diffstat:
         M scribo.c                            |      19 ++++++++++---------
       
       1 file changed, 10 insertions(+), 9 deletions(-)
       ---
 (DIR) diff --git a/scribo.c b/scribo.c
       t@@ -218,14 +218,6 @@ main(int argc, char *argv[])
                        return -1;
                }
        
       -        if (outfile && strcmp(outfile, "-"))
       -                out = fopen(outfile, "w");
       -
       -        if (!out) {
       -                perror(outfile);
       -                return -1;
       -        }
       -
                if (parseheaders(in, &headers) < 0) {
                        perror("header section");
                        return -1;
       t@@ -236,10 +228,19 @@ main(int argc, char *argv[])
                        return -1;
                }
        
       +        fclose(in);
       +
       +        if (outfile && strcmp(outfile, "-"))
       +                out = fopen(outfile, "w");
       +
       +        if (!out) {
       +                perror(outfile);
       +                return -1;
       +        }
       +
                if (writeindex(out, basedir) < 0)
                        return -1;
        
       -        fclose(in);
                fclose(out);
        
                return 0;