Forgetting the case of an empty filename for replace_buffer(),

and not bothering to put the pointer at the top.


git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@5269 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
This commit is contained in:
Benno Schulenberg
2015-06-27 15:03:45 +00:00
parent f0bb50306c
commit ecffb85656
2 changed files with 13 additions and 18 deletions

View File

@@ -405,35 +405,26 @@ void open_buffer(const char *filename, bool undoable)
}
#ifndef DISABLE_SPELLER
/* If it's not "", filename is a file to open. We blow away the text of
* the current buffer, and then open and read the file, if
* applicable. Note that we skip the operating directory test when
* doing this. */
/* Blow away the text of the current buffer, and then open and read
* the specified file into its place. */
void replace_buffer(const char *filename)
{
FILE *f;
int rc;
/* rc == -2 means that we have a new file. -1 means that the
* open() failed. 0 means that the open() succeeded. */
int descriptor;
assert(filename != NULL);
assert(filename != NULL && filename[0] != '\0');
/* If the filename isn't blank, open the file. Otherwise, treat it
* as a new file. */
rc = (filename[0] != '\0') ? open_file(filename, TRUE, FALSE, &f) : -2;
/* Open the file quietly. */
descriptor = open_file(filename, TRUE, FALSE, &f);
/* Reinitialize the text of the current buffer. */
free_filestruct(openfile->fileage);
initialize_buffer_text();
/* If we have a non-new file, read it in. */
if (rc > 0)
read_file(f, rc, filename, FALSE, TRUE);
/* If opening the file succeeded, read it in. */
if (descriptor > 0)
read_file(f, descriptor, filename, FALSE, TRUE);
/* Move back to the beginning of the first line of the buffer. */
openfile->current = openfile->fileage;
openfile->current_x = 0;
openfile->placewewant = 0;
}
#endif /* !DISABLE_SPELLER */