diff --git a/cmd/ipfs/init.c b/cmd/ipfs/init.c index a9c414c..55aad5f 100644 --- a/cmd/ipfs/init.c +++ b/cmd/ipfs/init.c @@ -1,22 +1,30 @@ +#include + #include "init.h" int get_init_command(struct command* cmd) { // help text cmd->help_text.tagline = "Initializes IPFS config file."; cmd->help_text.short_description = "\nInitializes IPFS configuration files and generates a new keypair.\n\nipfs uses a repository in the local file system. By default, the repo is\nlocated at ~/.ipfs. To change the repo location, set the $IPFS_PATH\nenvironment variable.:\n\n export IPFS_PATH=/path/to/ipfsrepo"; + // arguments // initialize an array of arguments with size of 1 - struct argument argument; - int retVal = init_string_argument(&argument, "default-config", 0, 0, "Initialize with the given configuration"); - argument.enable_stdin = 1; - struct argument* array[] = { &argument }; - cmd->arguments = array; cmd->argument_count = 1; + // allocate memory for array of pointers + cmd->arguments = malloc(cmd->argument_count * sizeof(struct argument*)); + if (cmd->arguments == NULL) + return 0; + // allocate memory for argument + cmd->arguments[0] = malloc(sizeof(struct argument)); + int retVal = init_string_argument(cmd->arguments[0], "default-config", 0, 0, "Initialize with the given configuration"); + cmd->arguments[0]->enable_stdin = 1; + return retVal; } int uninit_command(struct command* cmd) { for(int i = 0; i < cmd->argument_count; i++) uninit_argument(cmd->arguments[i]); + free(cmd->arguments); return 0; } diff --git a/commands/argument.c b/commands/argument.c index 2aeaec7..8035695 100644 --- a/commands/argument.c +++ b/commands/argument.c @@ -4,15 +4,10 @@ #include "argument.h" int uninit_argument(struct argument* argument) { - free(argument->name); return 1; } int init_argument(struct argument* argument, char* name, int required, int variadic, char* description) { - argument->name = name == NULL ? NULL : strdup(name); - if (argument->name == NULL) - return 0; - strncpy(argument->name, name, strlen(name)); argument->name = name; argument->required = required; argument->variadic = variadic; diff --git a/repo/config/datastore.h b/repo/config/datastore.h index 5a2305e..4aa82af 100644 --- a/repo/config/datastore.h +++ b/repo/config/datastore.h @@ -3,7 +3,7 @@ #include -const char* datastore_default_directory = "datastore"; +//const char* datastore_default_directory = "datastore"; struct datastore { char* type;