aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorWarren Dukes <warren.dukes@gmail.com>2004-02-24 21:20:16 +0000
committerWarren Dukes <warren.dukes@gmail.com>2004-02-24 21:20:16 +0000
commit068d307a711bbcefc6868ff97fdf931269d13b44 (patch)
tree77423f3b95b640e7272b01c990e7c02b3006f1fd /src
parent71a48f07bc699af75a879bf2d226bcbc2bef1e94 (diff)
downloadmpd-068d307a711bbcefc6868ff97fdf931269d13b44.tar.gz
mpd-068d307a711bbcefc6868ff97fdf931269d13b44.tar.xz
mpd-068d307a711bbcefc6868ff97fdf931269d13b44.zip
make ~ work for paths
git-svn-id: https://svn.musicpd.org/mpd/trunk@37 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to 'src')
-rw-r--r--src/conf.c48
1 files changed, 47 insertions, 1 deletions
diff --git a/src/conf.c b/src/conf.c
index 656771cb0..889a0086b 100644
--- a/src/conf.c
+++ b/src/conf.c
@@ -29,6 +29,9 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <pwd.h>
#define MAX_STRING_SIZE MAXPATHLEN+80
@@ -206,11 +209,54 @@ char ** readConf(char * file) {
for(i=0;i<CONF_NUMBER_OF_PATHS;i++) {
if(conf_params[conf_absolutePaths[i]] &&
- conf_params[conf_absolutePaths[i]][0]!='/') {
+ conf_params[conf_absolutePaths[i]][0]!='/' &&
+ conf_params[conf_absolutePaths[i]][0]!='~')
+ {
ERROR("\"%s\" is not an absolute path\n",
conf_params[conf_absolutePaths[i]]);
exit(-1);
}
+ else if(conf_params[conf_absolutePaths[i]] &&
+ conf_params[conf_absolutePaths[i]][0]=='~')
+ {
+ struct passwd * pwd = NULL;
+ char * path;
+ int pos = 1;
+ if(conf_params[conf_absolutePaths[i]][1]=='/') {
+ uid_t uid = geteuid();
+ if((pwd = getpwuid(uid)) == NULL) {
+ ERROR("problems getting passwd entry "
+ "for current user\n");
+ exit(-1);
+ }
+ }
+ else {
+ int foundSlash = 0;
+ char * ch = &(
+ conf_params[conf_absolutePaths[i]][1]);
+ for(;*ch!='\0' && *ch!='/';ch++);
+ if(*ch=='/') foundSlash = 1;
+ * ch = '\0';
+ pos+= ch-
+ &(conf_params[
+ conf_absolutePaths[i]][1]);
+ if((pwd = getpwnam(&(conf_params[
+ conf_absolutePaths[i]][1]))) == NULL)
+ {
+ ERROR("user \"%s\" not found\n",
+ &(conf_params[
+ conf_absolutePaths[i]][1]));
+ exit(-1);
+ }
+ if(foundSlash) *ch = '/';
+ }
+ path = malloc(strlen(pwd->pw_dir)+strlen(
+ &(conf_params[conf_absolutePaths[i]][pos])));
+ strcpy(path,pwd->pw_dir);
+ strcat(path,&(conf_params[conf_absolutePaths[i]][pos]));
+ free(conf_params[conf_absolutePaths[i]]);
+ conf_params[conf_absolutePaths[i]] = path;
+ }
}
return conf_params;