Commit 113d8a6b authored by Moritz Grimm's avatar Moritz Grimm
Browse files

Make set_progname() reusable

parent 4b4fee9e
......@@ -322,7 +322,7 @@ cfg_set_metadata_no_updates(const char *no_updates, const char **errstrp)
const char *
cfg_get_program_name(void)
{
return (cfg_program.name);
return (cfg_program.name[0] ? cfg_program.name : NULL);
}
enum cfg_config_type
......
......@@ -31,6 +31,7 @@
#include "cfg.h"
#include "cmdline.h"
#include "playlist.h"
#include "util.h"
#define OPTSTRING "c:hp:qrs:Vv"
enum opt_vals {
......@@ -47,7 +48,6 @@ enum opt_vals {
static void _usage(void);
static void _usage_help(void);
static void _set_program_name(const char *);
static void
_usage(void)
......@@ -72,27 +72,6 @@ _usage_help(void)
fprintf(stderr, " -v increase logging verbosity\n");
}
static void
_set_program_name(const char *argv0)
{
#ifdef HAVE___PROGNAME
extern char *__progname;
(void)argv0;
cfg_set_program_name(__progname, NULL);
#else
if (argv0 == NULL) {
cfg_set_program_name("ezstream", NULL);
} else {
const char *p = strrchr(argv0, '/');
if (p == NULL)
p = argv0;
else
p++;
cfg_set_program_name(p, NULL);
}
#endif /* HAVE___PROGNAME */
}
int
cmdline_parse(int argc, char *argv[], int *ret_p)
{
......@@ -100,7 +79,7 @@ cmdline_parse(int argc, char *argv[], int *ret_p)
unsigned int verbosity = 0;
const char *err_str;
_set_program_name(argv[0]);
(void)cfg_set_program_name(util_get_progname(argv[0]), NULL);
optind = 1;
for (;;) {
......
......@@ -145,6 +145,31 @@ _cleanup_pidfile(void)
}
}
const char *
util_get_progname(const char *argv0)
{
#ifdef HAVE___PROGNAME
extern char *__progname;
(void)argv0;
return (__progname);
#else
if (argv0 == NULL) {
return (UTIL_DEFAULT_PROGNAME);
} else {
const char *p = strrchr(argv0, '/');
if (p == NULL)
p = argv0;
else
p++;
return (p);
}
#endif /* HAVE___PROGNAME */
}
int
util_write_pid_file(const char *path)
{
......
......@@ -16,11 +16,17 @@
#ifndef __UTIL_H__
#define __UTIL_H__
#ifndef UTIL_DEFAULT_PROGNAME
# define UTIL_DEFAULT_PROGNAME "ezstream"
#endif /* !UTIL_DEFAULT_PROGNAME */
struct util_dict {
const char *from;
const char *to;
};
const char *
util_get_progname(const char *);
int util_write_pid_file(const char *);
int util_strrcmp(const char *, const char *);
int util_strrcasecmp(const char *, const char *);
......
......@@ -10,6 +10,13 @@
Suite * util_suite(void);
START_TEST(test_util_get_progname)
{
/* Platform-dependent test might fail: */
ck_assert_str_ne(util_get_progname(NULL), "");
}
END_TEST
START_TEST(test_util_write_pid_file)
{
FILE *pidfile_2;
......@@ -116,6 +123,7 @@ util_suite(void)
s = suite_create("Util");
tc_util = tcase_create("Util");
tcase_add_test(tc_util, test_util_get_progname);
tcase_add_test(tc_util, test_util_write_pid_file);
tcase_add_test(tc_util, test_util_strrcmp);
tcase_add_test(tc_util, test_util_utf8sanity);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment