rcfile: actually avoid opening directories and devices
Achieve this elegantly by factoring out the reading of one rcfile.master
parent
981a1d39bf
commit
c1a484270b
|
@ -2360,7 +2360,7 @@ int main(int argc, char **argv)
|
||||||
alt_speller = NULL;
|
alt_speller = NULL;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
do_rcfile();
|
do_rcfiles();
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
fprintf(stderr, "After rebinding keys...\n");
|
fprintf(stderr, "After rebinding keys...\n");
|
||||||
|
|
|
@ -527,7 +527,7 @@ bool parse_color_names(char *combostr, short *fg, short *bg, bool *bright);
|
||||||
void grab_and_store(const char *kind, char *ptr, regexlisttype **storage);
|
void grab_and_store(const char *kind, char *ptr, regexlisttype **storage);
|
||||||
#endif
|
#endif
|
||||||
void parse_rcfile(FILE *rcstream, bool syntax_only);
|
void parse_rcfile(FILE *rcstream, bool syntax_only);
|
||||||
void do_rcfile(void);
|
void do_rcfiles(void);
|
||||||
#endif /* !DISABLE_NANORC */
|
#endif /* !DISABLE_NANORC */
|
||||||
|
|
||||||
/* All functions in search.c. */
|
/* All functions in search.c. */
|
||||||
|
|
43
src/rcfile.c
43
src/rcfile.c
|
@ -1232,25 +1232,36 @@ void parse_rcfile(FILE *rcstream, bool syntax_only)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* First read the system-wide rcfile, then the user's rcfile. */
|
/* Read and interpret one of the two nanorc files. */
|
||||||
void do_rcfile(void)
|
void parse_one_nanorc(void)
|
||||||
{
|
{
|
||||||
FILE *rcstream;
|
FILE *rcstream;
|
||||||
|
|
||||||
nanorc = mallocstrcpy(nanorc, SYSCONFDIR "/nanorc");
|
/* Don't try to open directories nor devices. */
|
||||||
|
|
||||||
/* Warn about directories, character files, or block files. */
|
|
||||||
if (!is_good_file(nanorc))
|
if (!is_good_file(nanorc))
|
||||||
;
|
return;
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
fprintf(stderr, "Parsing file \"%s\"\n", nanorc);
|
fprintf(stderr, "Going to parse file \"%s\"\n", nanorc);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Try to open the system-wide nanorc. */
|
|
||||||
rcstream = fopen(nanorc, "rb");
|
rcstream = fopen(nanorc, "rb");
|
||||||
|
|
||||||
|
/* If opening the file succeeded, parse it. Otherwise, only
|
||||||
|
* complain if the file actually exists. */
|
||||||
if (rcstream != NULL)
|
if (rcstream != NULL)
|
||||||
parse_rcfile(rcstream, FALSE);
|
parse_rcfile(rcstream, FALSE);
|
||||||
|
else if (errno != ENOENT)
|
||||||
|
rcfile_error(N_("Error reading %s: %s"), nanorc, strerror(errno));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* First read the system-wide rcfile, then the user's rcfile. */
|
||||||
|
void do_rcfiles(void)
|
||||||
|
{
|
||||||
|
nanorc = mallocstrcpy(nanorc, SYSCONFDIR "/nanorc");
|
||||||
|
|
||||||
|
/* Process the system-wide nanorc. */
|
||||||
|
parse_one_nanorc();
|
||||||
|
|
||||||
/* When configured with --disable-wrapping-as-root, turn wrapping off
|
/* When configured with --disable-wrapping-as-root, turn wrapping off
|
||||||
* for root, so that only root's .nanorc or --fill can turn it on. */
|
* for root, so that only root's .nanorc or --fill can turn it on. */
|
||||||
|
@ -1267,25 +1278,13 @@ void do_rcfile(void)
|
||||||
nanorc = charealloc(nanorc, strlen(homedir) + strlen(RCFILE_NAME) + 2);
|
nanorc = charealloc(nanorc, strlen(homedir) + strlen(RCFILE_NAME) + 2);
|
||||||
sprintf(nanorc, "%s/%s", homedir, RCFILE_NAME);
|
sprintf(nanorc, "%s/%s", homedir, RCFILE_NAME);
|
||||||
|
|
||||||
/* Warn about directories, character files, or block files. */
|
/* Process the current user's nanorc. */
|
||||||
if (!is_good_file(nanorc))
|
parse_one_nanorc();
|
||||||
;
|
|
||||||
|
|
||||||
/* Try to open the current user's nanorc. */
|
|
||||||
rcstream = fopen(nanorc, "rb");
|
|
||||||
if (rcstream == NULL) {
|
|
||||||
/* Don't complain about the file's not existing. */
|
|
||||||
if (errno != ENOENT)
|
|
||||||
rcfile_error(N_("Error reading %s: %s"), nanorc,
|
|
||||||
strerror(errno));
|
|
||||||
} else
|
|
||||||
parse_rcfile(rcstream, FALSE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
check_vitals_mapped();
|
check_vitals_mapped();
|
||||||
|
|
||||||
free(nanorc);
|
free(nanorc);
|
||||||
nanorc = NULL;
|
|
||||||
|
|
||||||
if (errors && !ISSET(QUIET)) {
|
if (errors && !ISSET(QUIET)) {
|
||||||
errors = FALSE;
|
errors = FALSE;
|
||||||
|
|
Loading…
Reference in New Issue