1
mirror of https://github.com/mpv-player/mpv synced 2024-08-04 14:59:58 +02:00

get_path()

git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@179 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
szabii 2001-03-21 00:14:42 +00:00
parent 42e933e8d4
commit e0f650031f
2 changed files with 51 additions and 22 deletions

View File

@ -38,6 +38,8 @@ static reg_handle_t* head=0;
#define DIR -25
extern char *get_path(char *);
static void create_registry();
static void open_registry();
static void save_registry();
@ -68,17 +70,18 @@ static void open_registry()
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 @@ error:
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)

View File

@ -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);