summaryrefslogtreecommitdiffstats
path: root/crypto/heimdal/lib/roken/getarg.c
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/heimdal/lib/roken/getarg.c')
-rw-r--r--crypto/heimdal/lib/roken/getarg.c30
1 files changed, 19 insertions, 11 deletions
diff --git a/crypto/heimdal/lib/roken/getarg.c b/crypto/heimdal/lib/roken/getarg.c
index eff81f2..c732d2f 100644
--- a/crypto/heimdal/lib/roken/getarg.c
+++ b/crypto/heimdal/lib/roken/getarg.c
@@ -33,13 +33,13 @@
#ifdef HAVE_CONFIG_H
#include <config.h>
-RCSID("$Id: getarg.c,v 1.46 2002/08/20 16:23:07 joda Exp $");
+RCSID("$Id: getarg.c 21005 2007-06-08 01:54:35Z lha $");
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <roken.h>
+#include "roken.h"
#include "getarg.h"
#define ISFLAG(X) ((X).type == arg_flag || (X).type == arg_negative_flag)
@@ -198,7 +198,7 @@ check_column(FILE *f, int col, int len, int columns)
return col;
}
-void
+void ROKEN_LIB_FUNCTION
arg_printusage (struct getargs *args,
size_t num_args,
const char *progname,
@@ -307,12 +307,22 @@ arg_printusage (struct getargs *args,
}
}
-static void
+static int
add_string(getarg_strings *s, char *value)
{
- s->strings = realloc(s->strings, (s->num_strings + 1) * sizeof(*s->strings));
+ char **strings;
+
+ strings = realloc(s->strings, (s->num_strings + 1) * sizeof(*s->strings));
+ if (strings == NULL) {
+ free(s->strings);
+ s->strings = NULL;
+ s->num_strings = 0;
+ return ENOMEM;
+ }
+ s->strings = strings;
s->strings[s->num_strings] = value;
s->num_strings++;
+ return 0;
}
static int
@@ -390,8 +400,7 @@ arg_match_long(struct getargs *args, size_t num_args,
}
case arg_strings:
{
- add_string((getarg_strings*)current->value, goptarg + 1);
- return 0;
+ return add_string((getarg_strings*)current->value, goptarg + 1);
}
case arg_flag:
case arg_negative_flag:
@@ -497,8 +506,7 @@ arg_match_short (struct getargs *args, size_t num_args,
*(char**)args[k].value = goptarg;
return 0;
} else if(args[k].type == arg_strings) {
- add_string((getarg_strings*)args[k].value, goptarg);
- return 0;
+ return add_string((getarg_strings*)args[k].value, goptarg);
} else if(args[k].type == arg_double) {
double tmp;
if(sscanf(goptarg, "%lf", &tmp) != 1)
@@ -515,7 +523,7 @@ arg_match_short (struct getargs *args, size_t num_args,
return 0;
}
-int
+int ROKEN_LIB_FUNCTION
getarg(struct getargs *args, size_t num_args,
int argc, char **argv, int *goptind)
{
@@ -551,7 +559,7 @@ getarg(struct getargs *args, size_t num_args,
return ret;
}
-void
+void ROKEN_LIB_FUNCTION
free_getarg_strings (getarg_strings *s)
{
free (s->strings);
OpenPOWER on IntegriCloud