Changeset 010a951 for commands.c


Ignore:
Timestamp:
Mar 5, 2011, 3:25:29 PM (10 years ago)
Author:
David Benjamin <davidben@mit.edu>
Branches:
master, release-1.8, release-1.9
Children:
e3a75ed
Parents:
9620c8d
git-author:
David Benjamin <davidben@mit.edu> (02/28/11 10:53:18)
git-committer:
David Benjamin <davidben@mit.edu> (03/05/11 15:25:29)
Message:
Make owl_variable's get_tostring_fn return a newly allocated string

The mess with buffer lengths and whatnot is obnoxious. Note that this
does change semantics slightly: instead of (optionally) filling a buffer
and giving a return code for good vs no-variable/invalid, we now return
NULL for missing variables and always return a string if the variable
exists. This also appears to be more accurate from the perspective of
the calls anyway.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • commands.c

    r259e0475 r010a951  
    16141614{
    16151615  const char *var;
    1616   char valbuff[1024];
     1616  char *value;
    16171617
    16181618  if (argc==1) {
     
    16261626  var=argv[1];
    16271627   
    1628   if (0 == owl_variable_get_tostring(owl_global_get_vardict(&g),
    1629                                      var, valbuff, 1024)) {
    1630     owl_function_makemsg("%s = '%s'", var, valbuff);
     1628  value = owl_variable_get_tostring(owl_global_get_vardict(&g), var);
     1629  if (value) {
     1630    owl_function_makemsg("%s = '%s'", var, value);
     1631    g_free(value);
    16311632  } else {
    16321633    owl_function_makemsg("Unknown variable '%s'.", var);
     
    25072508char *owl_command_getvar(int argc, const char *const *argv, const char *buff)
    25082509{
    2509   char tmpbuff[1024];
    25102510  if (argc != 2) {
    25112511    owl_function_makemsg("Wrong number of arguments for %s", argv[0]);
    25122512    return NULL;
    25132513  }
    2514   if (owl_variable_get_tostring(owl_global_get_vardict(&g),
    2515                                 argv[1], tmpbuff, 1024)) {
    2516     return NULL;
    2517   }
    2518   return g_strdup(tmpbuff);
     2514  return owl_variable_get_tostring(owl_global_get_vardict(&g), argv[1]);
    25192515}
    25202516
Note: See TracChangeset for help on using the changeset viewer.