char * mc_conf_path(char *def_path, char *env_path, char *user_file, int separator, char *stdpath) { char *path; /* We specify MIMETYPES as a path override */ if(def_path) /* there may need to be an override specific to pine */ path = cpystr(def_path); else if(env_path) path = cpystr(env_path); else{ #if defined(DOS) || defined(OS2) char *s; /* * This gets interesting. Since we don't have any standard location * for config/data files, look in the same directory as the PINERC * and the same dir as PINE.EXE. This is similar to the UNIX * situation with personal config info coming before * potentially shared config data... */ if(s = last_cmpnt(ps_global->pinerc)){ strncpy(tmp_20k_buf+1000, ps_global->pinerc, MIN(s - ps_global->pinerc,SIZEOF_20KBUF-1000)); tmp_20k_buf[1000+MIN(s - ps_global->pinerc,SIZEOF_20KBUF-1000-1)] = '\0'; } else strncpy(tmp_20k_buf+1000, ".\\", SIZEOF_20KBUF-1000); /* pinerc directory version of file */ build_path(tmp_20k_buf+2000, tmp_20k_buf+1000, user_file, SIZEOF_20KBUF-2000); tmp_20k_buf[SIZEOF_20KBUF-1] = '\0'; /* pine.exe directory version of file */ build_path(tmp_20k_buf+3000, ps_global->pine_dir, user_file, SIZEOF_20KBUF-3000); tmp_20k_buf[SIZEOF_20KBUF-1] = '\0'; /* combine them */ snprintf(tmp_20k_buf, SIZEOF_20KBUF, "%s%c%s", tmp_20k_buf+2000, separator, tmp_20k_buf+3000); #else /* !DOS */ build_path(tmp_20k_buf, ps_global->home_dir, stdpath, SIZEOF_20KBUF); #endif /* !DOS */ path = cpystr(tmp_20k_buf); } return(path); }
/* * Return the name of a file in the same directory as filename. * Same as temp_nam except it figures out a name in the same directory. * It also returns the name of the directory in ret_dir if ret_dir is * not NULL. That has to be freed by caller. If return is not NULL the * empty file has been created. */ char * tempfile_in_same_dir(char *filename, char *prefix, char **ret_dir) { #ifndef MAXPATH #define MAXPATH 1000 /* Longest file path we can deal with */ #endif char dir[MAXPATH+1]; char *dirp = NULL; char *ret_file = NULL; if(filename){ char *lc; if((lc = last_cmpnt(filename)) != NULL){ int to_copy; to_copy = (lc - filename > 1) ? (lc - filename - 1) : 1; strncpy(dir, filename, MIN(to_copy, sizeof(dir)-1)); dir[MIN(to_copy, sizeof(dir)-1)] = '\0'; } else{ dir[0] = '.'; dir[1] = '\0'; } dirp = dir; } /* temp_nam creates ret_file */ ret_file = temp_nam(dirp, prefix); /* * If temp_nam can't write in dirp it puts the file in a temp directory * anyway. We don't want that to happen to us. */ if(dirp && ret_file && !in_dir(dirp, ret_file)){ our_unlink(ret_file); fs_give((void **)&ret_file); /* sets it to NULL */ } if(ret_file && ret_dir && dirp) *ret_dir = cpystr(dirp); return(ret_file); }
char * rd_metadata_name(void) { char *p, *q, *metafile; char path[MAXPATH], pinerc_dir[MAXPATH]; struct variable *vars = ps_global->vars; dprint((9, "rd_metadata_name\n")); pinerc_dir[0] = '\0'; if(ps_global->pinerc){ char *prcn = ps_global->pinerc; char *lc; if((lc = last_cmpnt(prcn)) != NULL){ int to_copy; to_copy = (lc - prcn > 1) ? (lc - prcn - 1) : 1; strncpy(pinerc_dir, prcn, MIN(to_copy, sizeof(pinerc_dir)-1)); pinerc_dir[MIN(to_copy, sizeof(pinerc_dir)-1)] = '\0'; } else{ pinerc_dir[0] = '.'; pinerc_dir[1] = '\0'; } } /* * If there is no metadata file specified in the pinerc, create a filename. */ if(!(VAR_REMOTE_ABOOK_METADATA && VAR_REMOTE_ABOOK_METADATA[0])){ if(pinerc_dir[0] && (p = tempfile_in_same_dir(ps_global->pinerc, meta_prefix, NULL))){ /* fill in the pinerc variable */ q = p + strlen(pinerc_dir) + 1; set_variable(V_REMOTE_ABOOK_METADATA, q, 1, 0, Main); dprint((2, "creating name for metadata file: %s\n", q ? q : "?")); /* something's broken, return NULL rab */ if(!VAR_REMOTE_ABOOK_METADATA || !VAR_REMOTE_ABOOK_METADATA[0]){ our_unlink(p); fs_give((void **)&p); return(NULL); } fs_give((void **)&p); } else{ q_status_message(SM_ORDER, 3, 5, "can't create metadata file in pinerc directory, continuing"); return(NULL); } } build_path(path, pinerc_dir ? pinerc_dir : NULL, VAR_REMOTE_ABOOK_METADATA, sizeof(path)); metafile = path; /* * If the metadata file doesn't exist, create it. */ if(can_access(metafile, ACCESS_EXISTS) != 0){ int fd; if((fd = our_open(metafile, O_CREAT|O_EXCL|O_WRONLY|O_BINARY, 0600)) < 0){ set_variable(V_REMOTE_ABOOK_METADATA, NULL, 1, 0, Main); q_status_message2(SM_ORDER, 3, 5, "can't create cache file %.200s, continuing (%.200s)", metafile, error_description(errno)); dprint((2, "can't create metafile %s: %s\n", metafile ? metafile : "?", error_description(errno))); return(NULL); } dprint((2, "created metadata file: %s\n", metafile ? metafile : "?")); (void)close(fd); } return(cpystr(metafile));; }