summaryrefslogtreecommitdiffstats
path: root/mplayer.c
diff options
context:
space:
mode:
authorszabii <szabii@b3059339-0415-0410-9bf9-f77b7e298cf2>2001-03-21 00:14:42 +0000
committerszabii <szabii@b3059339-0415-0410-9bf9-f77b7e298cf2>2001-03-21 00:14:42 +0000
commite0f650031fb81e30cc41a0702cdf63d86e894aa6 (patch)
treebcff45417464db3ee5ac2aefe53b380a0efd8275 /mplayer.c
parent42e933e8d4573b2f53213a00504c0f2a8b031113 (diff)
downloadmpv-e0f650031fb81e30cc41a0702cdf63d86e894aa6.tar.bz2
mpv-e0f650031fb81e30cc41a0702cdf63d86e894aa6.tar.xz
get_path()
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@179 b3059339-0415-0410-9bf9-f77b7e298cf2
Diffstat (limited to 'mplayer.c')
-rw-r--r--mplayer.c49
1 files changed, 37 insertions, 12 deletions
diff --git a/mplayer.c b/mplayer.c
index 02d3911a14..d9b0cf3477 100644
--- a/mplayer.c
+++ b/mplayer.c
@@ -99,6 +99,28 @@ static int cfg_include(struct config *conf, char *filename){
return parse_config_file(conf, filename);
}
+char *get_path(char *filename){
+ char *homedir;
+ char *buff;
+ static char *config_dir = "/.mplayer";
+ int len;
+
+ if ((homedir = getenv("HOME")) == NULL)
+ return NULL;
+ len = strlen(homedir) + strlen(config_dir) + 1;
+ if (filename == NULL) {
+ if ((buff = (char *) malloc(len)) == NULL)
+ return NULL;
+ sprintf(buff, "%s%s", homedir, config_dir);
+ } else {
+ len += strlen(filename) + 1;
+ if ((buff = (char *) malloc(len)) == NULL)
+ return NULL;
+ sprintf(buff, "%s%s/%s", homedir, config_dir, filename);
+ }
+ return buff;
+}
+
static int max_framesize=0;
static int dbg_es_sent=0;
@@ -385,9 +407,7 @@ int movie_size_y=0;
int out_fmt=0;
char *dsp="/dev/dsp";
int force_ni=0;
-char *homedir;
-char conffile[100];
-char confdir[100];
+char *conffile;
int conffile_fd;
#include "cfg-mplayer.h"
@@ -395,18 +415,23 @@ int conffile_fd;
if (parse_config_file(conf, "/etc/mplayer.conf") < 0)
exit(1);
-if ((homedir = getenv("HOME")) == NULL) {
+if ((conffile = get_path("")) == NULL) {
printf("Can't find HOME dir\n");
} else {
- snprintf(confdir, 100, "%s/.mplayer", homedir);
- mkdir(confdir, 0777);
- snprintf(conffile, 100, "%s/config", confdir);
- if ((conffile_fd = open(conffile, O_CREAT | O_EXCL | O_WRONLY, 0644)) != -1) {
- write(conffile_fd, default_config, strlen(default_config));
- close(conffile_fd);
+ mkdir(conffile, 0777);
+ free(conffile);
+ if ((conffile = get_path("config")) == NULL) {
+ printf("get_path(\"config\") sziiiivas\n");
+ } else {
+ if ((conffile_fd = open(conffile, O_CREAT | O_EXCL | O_WRONLY, 0666)) != -1) {
+ printf("Creating config file: %s\n", conffile);
+ write(conffile_fd, default_config, strlen(default_config));
+ close(conffile_fd);
+ }
+ if (parse_config_file(conf, conffile) < 0)
+ exit(1);
+ free(conffile);
}
- if (parse_config_file(conf, conffile) < 0)
- exit(1);
}
if (parse_command_line(conf, argc, argv, envp, &filename) < 0)
exit(1);