Changeset d3941a0


Ignore:
Timestamp:
Feb 4, 2011, 3:49:44 PM (10 years ago)
Author:
David Benjamin <davidben@mit.edu>
Branches:
master, release-1.8, release-1.9
Children:
65c753e
Parents:
b03c714
git-author:
David Benjamin <davidben@mit.edu> (01/24/11 17:14:08)
git-committer:
David Benjamin <davidben@mit.edu> (02/04/11 15:49:44)
Message:
Use g_strjoinv in owl_global_set_startupargs

It's much nicer than dealing with string lengths, although it does mean
we lose const-correctness because glib just gives up on that with lists
of strings. Also make a copy of the argument list because getopt_long
messes around with argument lists anyway.
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • global.c

    r5f8ec6b rd3941a0  
    527527/* startup args */
    528528
    529 void owl_global_set_startupargs(owl_global *g, int argc, const char *const *argv) {
    530   int i, len;
    531 
     529void owl_global_set_startupargs(owl_global *g, int argc, char **argv) {
    532530  if (g->startupargs) owl_free(g->startupargs);
    533  
    534   len=0;
    535   for (i=0; i<argc; i++) {
    536     len+=strlen(argv[i])+5;
    537   }
    538   g->startupargs=owl_malloc(len+5);
    539 
    540   strcpy(g->startupargs, "");
    541   for (i=0; i<argc; i++) {
    542     sprintf(g->startupargs + strlen(g->startupargs), "%s ", argv[i]);
    543   }
    544   g->startupargs[strlen(g->startupargs)-1]='\0';
     531  g->startupargs = g_strjoinv(" ", argv);
    545532}
    546533
  • owl.c

    rb03c714 rd3941a0  
    454454int main(int argc, char **argv, char **env)
    455455{
    456   int argcsave;
    457   const char *const *argvsave;
     456  int argc_copy;
     457  char **argv_copy;
    458458  char *perlout, *perlerr;
    459459  const owl_style *s;
     
    464464    g_error ("GLib version 2.12.0 or above is needed.");
    465465
    466   argcsave=argc;
    467   argvsave=strs(argv);
     466  argc_copy = argc;
     467  argv_copy = g_strdupv(argv);
    468468
    469469  setlocale(LC_ALL, "");
     
    483483  if (opts.confdir) owl_global_set_confdir(&g, opts.confdir);
    484484  owl_function_debugmsg("startup: first available debugging message");
    485   owl_global_set_startupargs(&g, argcsave, argvsave);
     485  owl_global_set_startupargs(&g, argc_copy, argv_copy);
     486  g_strfreev(argv_copy);
    486487  owl_global_set_haveaim(&g);
    487488
Note: See TracChangeset for help on using the changeset viewer.