diff options
author | Eduardo Chappa <chappa@washington.edu> | 2013-07-21 15:34:39 -0600 |
---|---|---|
committer | Eduardo Chappa <chappa@washington.edu> | 2013-07-21 15:34:39 -0600 |
commit | 33d5c0604e830bb65c2f5ccd69170b1c1453802b (patch) | |
tree | 14221cffd0c811a9a0e4241e5c3015f4e313c19d /pith/conf.c | |
parent | 9dcb8528d0ce6afb8afc1b0a219fc7eae0c9bb99 (diff) | |
download | alpine-33d5c0604e830bb65c2f5ccd69170b1c1453802b.tar.xz |
* Unix only: Support for local .pinerc files that are symbolic links
.pinerc -> some/other/file
Diffstat (limited to 'pith/conf.c')
-rw-r--r-- | pith/conf.c | 46 |
1 files changed, 43 insertions, 3 deletions
diff --git a/pith/conf.c b/pith/conf.c index 18eaf8f0..990688aa 100644 --- a/pith/conf.c +++ b/pith/conf.c @@ -5490,6 +5490,10 @@ write_pinerc(struct pine *ps, EditWhich which, int flags) REMDATA_S *rd = NULL; PINERC_S *prc = NULL; STORE_S *so = NULL; +#ifndef _WINDOWS + struct stat sbuf; + char *slink = NULL; +#endif dprint((2,"---- write_pinerc(%s) ----\n", (which == Main) ? "Main" : "Post")); @@ -5867,9 +5871,45 @@ write_pinerc(struct pine *ps, EditWhich which, int flags) if(so_give(&so)) goto io_err; - file_attrib_copy(tmp, filename); - if(rename_file(tmp, filename) < 0) - goto io_err; +#ifndef _WINDOWS + /* if .pinerc is a symbolic link, override symbolic link */ + if(our_lstat(filename, &sbuf) == 0){ + if((slink = fs_get((sbuf.st_size+1)*sizeof(char))) != NULL){ + int r = -1; /* assume error */ + if(readlink(filename, slink, sbuf.st_size + 1) >= 0){ + char *slpath; + + slink[sbuf.st_size] = '\0'; + if(*slink == '/') + slpath = cpystr(slink); + else{ + char * basep; + basep = strrchr(filename, '/'); + if(basep == NULL){ + *basep = '\0'; + slpath = (char *) fs_get((strlen(filename) + strlen(slink) + 2)*sizeof(char)); + sprintf(slpath, "%s/%s", filename, slink); + *basep = '/'; + } else { + slpath = (char *) fs_get((strlen(ps_global->home_dir) + strlen(slink) + 2)*sizeof(char)); + sprintf(slpath, "%s/%s", ps_global->home_dir, slink); + } + } + file_attrib_copy(tmp, slpath); + r = rename_file(tmp, slpath); + fs_give((void **)&slpath); + } + fs_give((void **)&slink); + if (r < 0) goto io_err; + } + } + else +#endif /* _WINDOWS */ + { + file_attrib_copy(tmp, filename); + if(rename_file(tmp, filename) < 0) + goto io_err; + } } if(prc->type != Loc){ |