Changeset e3c8332


Ignore:
Timestamp:
Feb 4, 2011, 3:49:44 PM (11 years ago)
Author:
David Benjamin <davidben@mit.edu>
Branches:
master, release-1.8, release-1.9
Children:
4d24650
Parents:
c6b1782
git-author:
David Benjamin <davidben@mit.edu> (01/25/11 00:10:21)
git-committer:
David Benjamin <davidben@mit.edu> (02/04/11 15:49:44)
Message:
Use GString in owl_cmddict_execute_argv

While we're at it, provide a correctly quoted command-line.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • cmd.c

    rd296c9a re3c8332  
    110110
    111111char *owl_cmddict_execute_argv(const owl_cmddict *cd, const owl_context *ctx, const char *const *argv, int argc) {
    112   char *buff, *ptr;
    113   int len = 0, i;
    114   char *retval = NULL;
    115 
     112  GString *buf = g_string_new("");
     113  int i;
     114  char *retval;
     115
     116  /* We weren't given a command line, so fabricate a valid one. */
    116117  for(i = 0; i < argc; i++) {
    117     len += strlen(argv[i]) + 1;
    118   }
    119 
    120   ptr = buff = owl_malloc(len);
    121 
    122   for(i = 0; i < argc; i++) {
    123     strcpy(ptr, argv[i]);
    124     ptr += strlen(argv[i]);
    125     *(ptr++) = ' ';
    126   }
    127   *(ptr - 1) = 0;
    128 
    129   retval = _owl_cmddict_execute(cd, ctx, argv, argc, buff);
    130 
    131   owl_free(buff);
     118    if (i != 0)
     119      g_string_append_c(buf, ' ');
     120    owl_string_append_quoted_arg(buf, argv[i]);
     121  }
     122
     123  retval = _owl_cmddict_execute(cd, ctx, argv, argc, buf->str);
     124
     125  g_string_free(buf, true);
    132126  return retval;
    133127}
Note: See TracChangeset for help on using the changeset viewer.