From 0fa0f6fad5bb2dcf7f6936a7af30e2d549704a62 Mon Sep 17 00:00:00 2001 From: Frank Mori Hess Date: Thu, 25 Jan 2001 12:34:48 +0000 Subject: [PATCH] fixed bug with option parsing when both read and write buffers are resized simultaneously --- comedi_config/comedi_config.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/comedi_config/comedi_config.c b/comedi_config/comedi_config.c index 463ddd0..967598c 100644 --- a/comedi_config/comedi_config.c +++ b/comedi_config/comedi_config.c @@ -40,9 +40,7 @@ int quiet=0,verbose=0; -int read_buf_flag=0; int read_buf_size=0; -int write_buf_flag=0; int write_buf_size=0; int init_fd; @@ -56,8 +54,8 @@ struct option options[] = { { "version", 0, 0, 'V' }, { "init-data", 1, 0, 'i' }, { "remove", 0, 0, 'r' }, - { "read-buffer", 1, &read_buf_flag, 1}, - { "write-buffer", 1, &write_buf_flag, 1}, + { "read-buffer", 1, NULL, 0x1000}, + { "write-buffer", 1, NULL, 0x1001}, }; void do_help(int i) @@ -123,10 +121,17 @@ int main(int argc,char *argv[]) case 'i': init_file=optarg; break; - case 0: - if(read_buf_flag) read_buf_size = strtol(optarg, NULL, 0); - if(write_buf_flag) write_buf_size = strtol(optarg, NULL, 0); - if(read_buf_size < 0 || write_buf_size < 0) + case 0x1000: + read_buf_size = strtol(optarg, NULL, 0); + if(read_buf_size < 0) + { + fprintf(stderr, "invalid buffer size\n"); + exit(-1); + } + break; + case 0x1001: + write_buf_size = strtol(optarg, NULL, 0); + if(write_buf_size < 0) { fprintf(stderr, "invalid buffer size\n"); exit(-1); @@ -138,7 +143,7 @@ int main(int argc,char *argv[]) } if((argc-optind) < 1 || (argc-optind) > 3 || - ((argc-optind) == 1 && read_buf_flag == 0 && write_buf_flag == 0)){ + ((argc-optind) == 1 && read_buf_size == 0 && write_buf_size == 0)){ do_help(1); } @@ -258,7 +263,7 @@ int main(int argc,char *argv[]) } // do buffer resizing - if(read_buf_flag || write_buf_flag) + if(read_buf_size || write_buf_size) { memset(&bc, 0, sizeof(bc)); bc.read_size = read_buf_size * 1024; -- 2.26.2