verbose = 1;
else if (!strcmp(argv[aindex], updateoption))
update = 1;
- else if (!strcmp(argv[aindex], hashoption))
- {
- db5util_db_args_size++;
- {
- char **temp = realloc( db5util_db_args, sizeof(char*) * (db5util_db_args_size+1)); /* one for NULL */
- if( temp == NULL )
- {
- com_err(progname, ENOMEM, "while parsing command arguments\n");
- exit(1);
- }
-
- db5util_db_args = temp;
+ else if (!strcmp(argv[aindex], hashoption)) {
+ if (!add_db_arg("hash=true")) {
+ com_err(progname, ENOMEM, "while parsing command arguments\n");
+ exit(1);
}
- db5util_db_args[db5util_db_args_size-1] = "hash=true";
- db5util_db_args[db5util_db_args_size] = NULL;
- }
- else
+ } else
break;
}
if ((argc - aindex) != 1) {
do_stash++;
break;
case 'h':
- db5util_db_args_size++;
- {
- char **temp = realloc( db5util_db_args, sizeof(char*) * (db5util_db_args_size+1)); /* one for NULL */
- if( temp == NULL )
- {
- com_err(progname, ENOMEM, "while parsing command arguments\n");
- exit(1);
- }
-
- db5util_db_args = temp;
+ if (!add_db_arg("hash=true")) {
+ com_err(progname, ENOMEM, "while parsing command arguments\n");
+ exit(1);
}
- db5util_db_args[db5util_db_args_size-1] = "hash=true";
- db5util_db_args[db5util_db_args_size] = NULL;
+ break;
case '?':
default:
usage();
fprintf (stderr, "\n");
}
+int add_db_arg(char *arg)
+{
+ char **temp;
+ db5util_db_args_size++;
+ temp = realloc(db5util_db_args,
+ sizeof(char *) * (db5util_db_args_size + 1));
+ if (temp == NULL)
+ return 0;
+ db5util_db_args[db5util_db_args_size-1] = arg;
+ db5util_db_args[db5util_db_args_size] = NULL;
+ return 1;
+}
+
int main(argc, argv)
int argc;
char *argv[];
strcpy( db_name_tmp, "dbname=");
strcat( db_name_tmp, global_params.dbname );
- db5util_db_args_size++;
- {
- char **temp = realloc( db5util_db_args, sizeof(char*) * (db5util_db_args_size+1)); /* one for NULL */
- if( temp == NULL )
- {
- com_err(progname, ENOMEM, "while parsing command arguments\n");
- exit(1);
- }
-
- db5util_db_args = temp;
+ if (!add_db_arg(db_name_tmp)) {
+ com_err(progname, ENOMEM, "while parsing command arguments\n");
+ exit(1);
}
- db5util_db_args[db5util_db_args_size-1] = db_name_tmp;
- db5util_db_args[db5util_db_args_size] = NULL;
} else if (strcmp(*argv, "-x") == 0 && ARG_VAL) {
db5util_db_args_size++;
- {
- char **temp = realloc( db5util_db_args, sizeof(char*) * (db5util_db_args_size+1)); /* one for NULL */
- if( temp == NULL )
- {
- fprintf(stderr,"%s: Cannot initialize. Not enough memory\n",
- argv[0]);
- exit(1);
- }
-
- db5util_db_args = temp;
+ if (!add_db_arg(koptarg)) {
+ fprintf(stderr,"%s: Cannot initialize. Not enough memory\n",
+ argv[0]);
+ exit(1);
}
- db5util_db_args[db5util_db_args_size-1] = koptarg;
- db5util_db_args[db5util_db_args_size] = NULL;
} else if (strcmp(*argv, "-r") == 0 && ARG_VAL) {
global_params.realm = koptarg;