summaryrefslogtreecommitdiff
path: root/pith/conf.c
diff options
context:
space:
mode:
authorEduardo Chappa <chappa@washington.edu>2015-09-07 01:55:58 -0600
committerEduardo Chappa <chappa@washington.edu>2015-09-07 01:55:58 -0600
commit9b66fc4cfe04b908596a15c92f25779fec727e93 (patch)
tree9e52852a37b4098fdd5c13ce0f713ba2183b8675 /pith/conf.c
parent4a65e4148ece08cab77b0e679ed4071be0f05bdb (diff)
downloadalpine-9b66fc4cfe04b908596a15c92f25779fec727e93.tar.xz
* Reimplementation of the code that allows the .pinerc file to be a
symbolic link by Kyle George from tcpsoft.com to use realpath.
Diffstat (limited to 'pith/conf.c')
-rw-r--r--pith/conf.c64
1 files changed, 19 insertions, 45 deletions
diff --git a/pith/conf.c b/pith/conf.c
index 4b2dc384..66dc6dbe 100644
--- a/pith/conf.c
+++ b/pith/conf.c
@@ -5936,54 +5936,28 @@ write_pinerc(struct pine *ps, EditWhich which, int flags)
}
if(!(rd && rd->flags & NO_FILE)){
- if(so_give(&so))
- goto io_err;
+ char *realfilename;
+ int realfilename_malloced;
+
+ if(so_give(&so)) goto io_err;
#ifndef _WINDOWS
- /* if .pinerc is a symbolic link, override symbolic link */
- if(our_lstat(filename, &sbuf) == 0
- && ((sbuf.st_mode & S_IFMT) == S_IFLNK)){
- 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;
- int n;
-
- basep = strrchr(filename, '/');
- if(basep != NULL){
- *basep = '\0';
- n = strlen(filename) + strlen(slink) + 2;
- slpath = (char *) fs_get(n*sizeof(char));
- snprintf(slpath, n, "%s/%s", filename, slink);
- *basep = '/';
- } else {
- n = strlen(ps_global->home_dir) + strlen(slink) + 2;
- slpath = (char *) fs_get(n*sizeof(char));
- snprintf(slpath, n, "%s/%s", ps_global->home_dir, slink);
- }
- slpath[n-1] = '\0';
- }
- 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
+ if ((realfilename = realpath(filename, NULL)) != NULL)
+ realfilename_malloced = 1;
+ else
+ goto io_err;
+#else
+ realfilename = filename;
+ realfilename_malloced = 0;
#endif /* _WINDOWS */
- {
- file_attrib_copy(tmp, filename);
- if(rename_file(tmp, filename) < 0)
- goto io_err;
- }
+ if(realfilename != NULL){
+ int r;
+ file_attrib_copy(tmp, realfilename);
+ r = rename_file(tmp, realfilename);
+ if(realfilename_malloced != 0)
+ free((void *)realfilename);
+ if(r < 0) goto io_err;
+ }
}
if(prc->type != Loc){