Re: [PATCH] Add support for `-' file to read from stdin

From: Jens Axboe <jens.axboe_at_oracle.com>
Date: Thu, 27 Sep 2007 09:03:32 +0200

On Thu, Sep 27 2007, Aaron Carroll wrote:
> init.c | 11 +++++++++--
> 1 files changed, 9 insertions(+), 2 deletions(-)

Thanks Aaron. I modified it slightly for style and getting rid of
close_file.

diff --git a/init.c b/init.c
index 84cb2d2..45bd92f 100644
--- a/init.c
+++ b/init.c
@@ -571,7 +571,11 @@ static int parse_jobs_ini(char *file, int stonewall_flag)
         int ret = 0, stonewall;
         int first_sect = 1;
 
- f = fopen(file, "r");
+ if (!strcmp(file, "-"))
+ f = stdin;
+ else
+ f = fopen(file, "r");
+
         if (!f) {
                 perror("fopen job file");
                 return 1;
@@ -665,7 +669,8 @@ static int parse_jobs_ini(char *file, int stonewall_flag)
 
         free(string);
         free(name);
- fclose(f);
+ if (f != stdin)
+ fclose(f);
         return ret;
 }
 

-- 
Jens Axboe
Received on Thu Sep 27 2007 - 09:03:32 CEST

This archive was generated by hypermail 2.2.0 : Thu Sep 27 2007 - 09:30:01 CEST