# HG changeset patch # User szabii # Date 985133682 0 # Node ID 55206b7915860559fadb8309d0f93edb9982f4f1 # Parent 554c6e5f36ef23d69a81903b6ab11e445415d2b8 get_path() diff -r 554c6e5f36ef -r 55206b791586 loader/registry.c --- a/loader/registry.c Tue Mar 20 22:55:50 2001 +0000 +++ b/loader/registry.c Wed Mar 21 00:14:42 2001 +0000 @@ -38,6 +38,8 @@ #define DIR -25 +extern char *get_path(char *); + static void create_registry(); static void open_registry(); static void save_registry(); @@ -68,17 +70,18 @@ int fd; int i; int len; - struct passwd* pwent; +// struct passwd* pwent; char* pathname; if(regs) { printf("Multiple open_registry(>\n"); return; } - pwent=getpwuid(getuid()); - pathname=(char*)malloc(strlen(pwent->pw_dir)+20); - strcpy(pathname, pwent->pw_dir); - strcat(pathname, "/.mplayer/registry"); +// pwent=getpwuid(getuid()); +// pathname=(char*)malloc(strlen(pwent->pw_dir)+20); +// strcpy(pathname, pwent->pw_dir); +// strcat(pathname, "/.mplayer/registry"); + pathname = get_path("registry"); fd=open(pathname, O_RDONLY); free(pathname); if(fd==-1) @@ -120,12 +123,13 @@ static void save_registry() { int fd, i, len; - struct passwd* pwent; +// struct passwd* pwent; char* pathname; - pwent=getpwuid(getuid()); - pathname=(char*)malloc(strlen(pwent->pw_dir)+20); - strcpy(pathname, pwent->pw_dir); - strcat(pathname, "/.mplayer/registry"); +// pwent=getpwuid(getuid()); +// pathname=(char*)malloc(strlen(pwent->pw_dir)+20); +// strcpy(pathname, pwent->pw_dir); +// strcat(pathname, "/.mplayer/registry"); + pathname = get_path("registry"); fd=open(pathname, O_WRONLY | O_CREAT, 00777); free(pathname); if(fd==-1) diff -r 554c6e5f36ef -r 55206b791586 mplayer.c --- a/mplayer.c Tue Mar 20 22:55:50 2001 +0000 +++ b/mplayer.c Wed Mar 21 00:14:42 2001 +0000 @@ -99,6 +99,28 @@ 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 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 @@ 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);