mirror of
git://git.sv.gnu.org/nano.git
synced 2024-11-30 00:23:28 +03:00
tweaks: strip four unneeded checks
The functions to read and write history files will not even be called when the home directory is missing, so there is no need to check for that eventuality again.
This commit is contained in:
parent
5f4fb8e513
commit
09ab91c79c
@ -216,21 +216,17 @@ char *get_history_completion(filestruct **h, char *s, size_t len)
|
|||||||
}
|
}
|
||||||
#endif /* ENSABLE_TABCOMP */
|
#endif /* ENSABLE_TABCOMP */
|
||||||
|
|
||||||
/* Return the constructed dirfile path, or NULL if we can't find the home
|
/* Return a dynamically-allocated path that is the concatenation of the
|
||||||
* directory. The string is dynamically allocated, and should be freed. */
|
* user's home directory and the given name. */
|
||||||
char *construct_filename(const char *str)
|
char *construct_filename(const char *name)
|
||||||
{
|
{
|
||||||
char *newstr = NULL;
|
size_t homelen = strlen(homedir);
|
||||||
|
char *joined = charalloc(homelen + strlen(name) + 1);
|
||||||
|
|
||||||
if (homedir != NULL) {
|
strcpy(joined, homedir);
|
||||||
size_t homelen = strlen(homedir);
|
strcpy(joined + homelen, name);
|
||||||
|
|
||||||
newstr = charalloc(homelen + strlen(str) + 1);
|
return joined;
|
||||||
strcpy(newstr, homedir);
|
|
||||||
strcpy(newstr + homelen, str);
|
|
||||||
}
|
|
||||||
|
|
||||||
return newstr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
char *histfilename(void)
|
char *histfilename(void)
|
||||||
@ -299,10 +295,6 @@ void load_history(void)
|
|||||||
struct stat hstat;
|
struct stat hstat;
|
||||||
FILE *histfile;
|
FILE *histfile;
|
||||||
|
|
||||||
/* If no home directory was found, we can't do anything. */
|
|
||||||
if (histname == NULL || legacyhist == NULL)
|
|
||||||
return;
|
|
||||||
|
|
||||||
/* If there is an old history file, migrate it. */
|
/* If there is an old history file, migrate it. */
|
||||||
/* (To be removed in 2018.) */
|
/* (To be removed in 2018.) */
|
||||||
if (stat(legacyhist, &hstat) != -1 && stat(histname, &hstat) == -1) {
|
if (stat(legacyhist, &hstat) != -1 && stat(histname, &hstat) == -1) {
|
||||||
@ -390,10 +382,6 @@ void save_history(void)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
histname = histfilename();
|
histname = histfilename();
|
||||||
|
|
||||||
if (histname == NULL)
|
|
||||||
return;
|
|
||||||
|
|
||||||
histfile = fopen(histname, "wb");
|
histfile = fopen(histname, "wb");
|
||||||
|
|
||||||
if (histfile == NULL)
|
if (histfile == NULL)
|
||||||
@ -418,13 +406,7 @@ void save_history(void)
|
|||||||
void load_poshistory(void)
|
void load_poshistory(void)
|
||||||
{
|
{
|
||||||
char *poshist = poshistfilename();
|
char *poshist = poshistfilename();
|
||||||
FILE *histfile;
|
FILE *histfile = fopen(poshist, "rb");
|
||||||
|
|
||||||
/* If the home directory is missing, do_rcfile() will have reported it. */
|
|
||||||
if (poshist == NULL)
|
|
||||||
return;
|
|
||||||
|
|
||||||
histfile = fopen(poshist, "rb");
|
|
||||||
|
|
||||||
if (histfile == NULL) {
|
if (histfile == NULL) {
|
||||||
if (errno != ENOENT) {
|
if (errno != ENOENT) {
|
||||||
@ -491,12 +473,7 @@ void save_poshistory(void)
|
|||||||
{
|
{
|
||||||
char *poshist = poshistfilename();
|
char *poshist = poshistfilename();
|
||||||
poshiststruct *posptr;
|
poshiststruct *posptr;
|
||||||
FILE *histfile;
|
FILE *histfile = fopen(poshist, "wb");
|
||||||
|
|
||||||
if (poshist == NULL)
|
|
||||||
return;
|
|
||||||
|
|
||||||
histfile = fopen(poshist, "wb");
|
|
||||||
|
|
||||||
if (histfile == NULL)
|
if (histfile == NULL)
|
||||||
fprintf(stderr, _("Error writing %s: %s\n"), poshist, strerror(errno));
|
fprintf(stderr, _("Error writing %s: %s\n"), poshist, strerror(errno));
|
||||||
|
Loading…
Reference in New Issue
Block a user