Changeset 545 for trunk/src/ocat.c


Ignore:
Timestamp:
02/11/10 14:42:19 (2 years ago)
Author:
eagle
Message:

parse options twice caused some troubles at least on Linux.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/ocat.c

    r543 r545  
    271271 
    272272 
    273 void parse_opt_early(int argc, char *argv[]) 
     273void parse_opt_early(int argc, char *argv_orig[]) 
    274274{ 
    275275   int c; 
    276  
     276   char *argv[argc + 1]; 
     277 
     278   log_debug("parse_opt_early()"); 
     279   // argv array is copied to prevent the original one from being modified by 
     280   // getopt(). This behavior is at least true for Linux. 
     281   memcpy(&argv, argv_orig, sizeof(char*) * (argc + 1)); 
    277282   opterr = 0; 
    278283   while ((c = getopt(argc, argv, "f:I")) != -1) 
     284   { 
     285      log_debug("getopt(): c = %c, optind = %d, opterr = %d, optarg = \"%s\"", c, optind, opterr, optarg); 
    279286      switch (c) 
    280287      { 
     
    291298            break; 
    292299      } 
     300   } 
    293301} 
    294302 
     
    298306   int c, urlconv = 0; 
    299307 
     308   log_debug("parse_opt_early()"); 
    300309   opterr = 1; 
    301310   optind = 1; 
    302311   while ((c = getopt(argc, argv, "f:IabBCd:hrRiopl:t:T:s:u:4L:P:")) != -1) 
     312   { 
     313      log_debug("getopt(): c = %c, optind = %d, opterr = %d, optarg = \"%s\"", c, optind, opterr, optarg); 
    303314      switch (c) 
    304315      { 
     
    399410            exit(1); 
    400411      } 
     412   } 
    401413 
    402414   return urlconv; 
     
    423435   } 
    424436 
     437#ifdef DEBUG 
     438   for (c = 0; c < argc; c++) log_debug("argv[%d] = \"%s\"", c, argv[c]); 
     439#endif 
    425440   parse_opt_early(argc, argv); 
    426441 
     
    439454      ctrl_handler((void*) (long) c); 
    440455  
    441  
     456#ifdef DEBUG 
     457   for (c = 0; c < argc; c++) log_debug("argv[%d] = \"%s\"", c, argv[c]); 
     458#endif 
    442459   urlconv = parse_opt(argc, argv); 
    443460 
     
    480497 
    481498   // copy onion-URL from command line 
     499   log_debug("argv[%d] = \"%s\"", optind, argv[optind]); 
    482500   if (!CNF(rand_addr)) 
    483501      strncpy(CNF(onion_url), argv[optind], NDESC(name_size)); 
Note: See TracChangeset for help on using the changeset viewer.