aboutsummaryrefslogtreecommitdiffstats
path: root/src/cmdline.c
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2008-12-27 19:46:43 +0100
committerMax Kellermann <max@duempel.org>2008-12-27 19:46:43 +0100
commit83fc9480082436985df3c67aee6c5977727ab9c7 (patch)
tree52134d8f275aa286bad39193bf963324450eeec6 /src/cmdline.c
parentf5ff00bba47f028d5be19b4e45b057d7632dbde2 (diff)
downloadmpd-83fc9480082436985df3c67aee6c5977727ab9c7.tar.gz
mpd-83fc9480082436985df3c67aee6c5977727ab9c7.tar.xz
mpd-83fc9480082436985df3c67aee6c5977727ab9c7.zip
cmdline: use g_build_filename() for ~/.mpdconf
Build the path with g_build_filename(). Also use g_get_home_dir() and g_file_test().
Diffstat (limited to 'src/cmdline.c')
-rw-r--r--src/cmdline.c30
1 files changed, 10 insertions, 20 deletions
diff --git a/src/cmdline.c b/src/cmdline.c
index 423b0ddd6..f901083d8 100644
--- a/src/cmdline.c
+++ b/src/cmdline.c
@@ -29,15 +29,10 @@
#include <glib.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <unistd.h>
#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
#define SYSTEM_CONFIG_FILE_LOCATION "/etc/mpd.conf"
-#define USER_CONFIG_FILE_LOCATION "/.mpdconf"
+#define USER_CONFIG_FILE_LOCATION ".mpdconf"
static void version(void)
{
@@ -131,21 +126,16 @@ void parseOptions(int argc, char **argv, Options *options)
if (argc <= 1) {
/* default configuration file path */
- struct stat st;
- char *homedir = getenv("HOME");
- char userfile[MPD_PATH_MAX] = "";
-
- if (homedir && (strlen(homedir) +
- strlen(USER_CONFIG_FILE_LOCATION)) <
- MPD_PATH_MAX) {
- strcpy(userfile, homedir);
- strcat(userfile, USER_CONFIG_FILE_LOCATION);
- }
-
- if (strlen(userfile) && 0 == stat(userfile, &st))
- readConf(userfile);
- else if (0 == stat(SYSTEM_CONFIG_FILE_LOCATION, &st))
+ char *path;
+
+ path = g_build_filename(g_get_home_dir(),
+ USER_CONFIG_FILE_LOCATION, NULL);
+ if (g_file_test(path, G_FILE_TEST_IS_REGULAR))
+ readConf(path);
+ else if (g_file_test(SYSTEM_CONFIG_FILE_LOCATION,
+ G_FILE_TEST_IS_REGULAR))
readConf(SYSTEM_CONFIG_FILE_LOCATION);
+ g_free(path);
} else if (argc == 2) {
/* specified configuration file */
readConf(argv[1]);