These functions all call the gengetopt parser which aborts on errors. It is therefore
pointless to check the return value. Document this fact and make it explicit by renaming
->parse_config of struct writer to ->parse_config_or_die().
t->error = ret;
}
-__malloc static void *alsa_parse_config(const char *options)
+__malloc static void *alsa_parse_config_or_die(const char *options)
{
- int ret;
- struct alsa_write_args_info *conf
- = para_calloc(sizeof(struct alsa_write_args_info));
+ struct alsa_write_args_info *conf = para_calloc(sizeof(*conf));
PARA_INFO_LOG("options: %s, %zd\n", options, strcspn(options, " \t"));
- ret = alsa_cmdline_parser_string(options, conf, "alsa_write");
- if (ret)
- goto err_out;
- PARA_INFO_LOG("help given: %d\n", conf->help_given);
+ /* exits on errors */
+ alsa_cmdline_parser_string(options, conf, "alsa_write");
return conf;
-err_out:
- free(conf);
- return NULL;
}
static void alsa_free_config(void *conf)
w->close = alsa_close;
w->pre_select = alsa_write_pre_select;
w->post_select = alsa_write_post_select;
- w->parse_config = alsa_parse_config;
+ w->parse_config_or_die = alsa_parse_config_or_die;
w->shutdown = NULL; /* nothing to do */
w->free_config = alsa_free_config;
w->help = (struct ggo_help) {
t->error = ret;
}
-__malloc static void *file_write_parse_config(const char *options)
+__malloc static void *file_write_parse_config_or_die(const char *options)
{
- struct file_write_args_info *conf
- = para_calloc(sizeof(struct file_write_args_info));
- int ret = file_cmdline_parser_string(options, conf, "file_write");
-
- PARA_INFO_LOG("conf->filename_given: %d\n", conf->filename_given);
- if (!ret)
- return conf;
- free(conf);
- return NULL;
+ struct file_write_args_info *conf = para_calloc(sizeof(*conf));
+
+ /* exits on errors */
+ file_cmdline_parser_string(options, conf, "file_write");
+ return conf;
}
static void file_write_free_config(void *conf)
w->open = file_write_open;
w->pre_select = file_write_pre_select;
w->post_select = file_write_post_select;
- w->parse_config = file_write_parse_config;
+ w->parse_config_or_die = file_write_parse_config_or_die;
w->free_config = file_write_free_config;
w->close = file_write_close;
w->shutdown = NULL; /* nothing to do */
return 1;
}
-__malloc static void *oss_parse_config(const char *options)
+__malloc static void *oss_parse_config_or_die(const char *options)
{
- int ret;
struct oss_write_args_info *conf = para_calloc(sizeof(*conf));
- ret = oss_cmdline_parser_string(options, conf, "oss_write");
- if (ret)
- goto err_out;
+ /* exits on errors */
+ oss_cmdline_parser_string(options, conf, "oss_write");
return conf;
-err_out:
- free(conf);
- return NULL;
}
static void oss_free_config(void *conf)
w->close = oss_close;
w->pre_select = oss_pre_select;
w->post_select = oss_post_select;
- w->parse_config = oss_parse_config;
+ w->parse_config_or_die = oss_parse_config_or_die;
w->free_config = oss_free_config;
w->shutdown = NULL;
w->help = (struct ggo_help) {
return ret;
}
-__malloc static void *osx_write_parse_config(const char *options)
+__malloc static void *osx_write_parse_config_or_die(const char *options)
{
- struct osx_write_args_info *conf
- = para_calloc(sizeof(struct osx_write_args_info));
- PARA_INFO_LOG("options: %s\n", options);
- int ret = osx_cmdline_parser_string(options, conf, "osx_write");
- if (ret)
- goto err_out;
- return conf;
-err_out:
- free(conf);
- return NULL;
+ struct osx_write_args_info *conf = para_calloc(sizeof(*conf));
+ /* exits on errors */
+ osx_cmdline_parser_string(options, conf, "osx_write");
+ return conf;
}
static void osx_free_config(void *conf)
w->close = osx_write_close;
w->pre_select = osx_write_pre_select;
w->post_select = osx_write_post_select;
- w->parse_config = osx_write_parse_config;
+ w->parse_config_or_die = osx_write_parse_config_or_die;
w->free_config = osx_free_config;
w->shutdown = NULL; /* nothing to do */
w->help = (struct ggo_help) {
/**
* The command line parser of the writer.
*
- * It should check whether the command line options given by \a options are
- * valid. On success, it should return a pointer to the writer-specific
- * configuration data determined by \a options. Note that this might be called
- * more than once with different values of \a options. \sa \ref free_config().
+ * It should check whether the command line options given by \a options
+ * are valid and return a pointer to the writer-specific configuration
+ * data determined by \a options. This function must either succeed or
+ * call exit(). Note that parse_config_or_die() might be called more
+ * than once with different values of \a options. \sa \ref
+ * free_config().
*/
- void *(*parse_config)(const char *options);
+ void *(*parse_config_or_die)(const char *options);
/**
* Dellocate all configuration resources.
*
- * This should free whatever was allocated by \ref parse_config().
+ * This should free whatever was allocated by \ref parse_config_or_die().
*/
void (*free_config)(void *config);
/**
c = wa[len];
if (c && c != ' ')
continue;
- if (c && !writers[i].parse_config)
+ if (c && !writers[i].parse_config_or_die)
return NULL;
*writer_num = i;
- return writers[i].parse_config(c? wa + len + 1 : "");
+ return writers[i].parse_config_or_die(c? wa + len + 1 : "");
}
PARA_ERROR_LOG("writer not found\n");
return NULL;
wn->conf = check_writer_arg(arg, &wn->writer_num);
else {
wn->writer_num = DEFAULT_WRITER;
- wn->conf = writers[DEFAULT_WRITER].parse_config("");
+ wn->conf = writers[DEFAULT_WRITER].parse_config_or_die("");
}
if (!wn->conf)
return -E_WRITE_COMMON_SYNTAX;
return 1;
}
-
/**
* Print the help text of all writers to stdout.
*