tweaks: update some comments after the previous changes

master
Benno Schulenberg 2020-02-09 20:10:28 +01:00
parent dd429d9c00
commit 9f43b4c758
1 changed files with 16 additions and 19 deletions

View File

@ -133,7 +133,7 @@ void make_new_buffer(void)
} }
#ifndef NANO_TINY #ifndef NANO_TINY
/* Delete the lockfile. Return -1 if unsuccessful, and 1 otherwise. */ /* Delete the lockfile. Return TRUE on success, and FALSE otherwise. */
bool delete_lockfile(const char *lockfilename) bool delete_lockfile(const char *lockfilename)
{ {
if (unlink(lockfilename) < 0 && errno != ENOENT) { if (unlink(lockfilename) < 0 && errno != ENOENT) {
@ -144,8 +144,8 @@ bool delete_lockfile(const char *lockfilename)
return TRUE; return TRUE;
} }
/* Write a lockfile, under the given lockfilename. This ALWAYS annihilates /* Write a lock file, under the given lockfilename. This always annihilates an
* an existing version of that file. Return 1 on success, and 0 on failure. */ * existing version of that file. Return TRUE on success; FALSE otherwise. */
bool write_lockfile(const char *lockfilename, const char *filename, bool modified) bool write_lockfile(const char *lockfilename, const char *filename, bool modified)
{ {
#ifdef HAVE_PWD_H #ifdef HAVE_PWD_H
@ -246,9 +246,10 @@ bool write_lockfile(const char *lockfilename, const char *filename, bool modifie
return TRUE; return TRUE;
} }
/* Deal with lockfiles. Return -1 on refusing to override the lockfile, /* First check if a lock file already exists. If so, and ask_the_user is TRUE,
* and 1 on successfully creating it; 0 means we were not successful in * then ask whether to open the corresponding file anyway. Return SKIPTHISFILE
* creating the lockfile but we should continue to load the file. */ * when the user answers "No", return the name of the lock file on success, and
* return NULL on failure. */
char *do_lockfile(const char *filename, bool ask_the_user) char *do_lockfile(const char *filename, bool ask_the_user)
{ {
char *namecopy = copy_of(filename); char *namecopy = copy_of(filename);
@ -377,9 +378,9 @@ bool open_buffer(const char *filename, bool new_buffer)
char *thelocksname = NULL; char *thelocksname = NULL;
#endif #endif
struct stat fileinfo; struct stat fileinfo;
FILE *f;
int descriptor = 0; int descriptor = 0;
/* Code 0 means new file, -1 means failure, and else it's the fd. */ /* Code 0 means new file, -1 means failure, and else it's the fd. */
FILE *f;
/* Display newlines in filenames as ^J. */ /* Display newlines in filenames as ^J. */
as_an_at = FALSE; as_an_at = FALSE;
@ -414,10 +415,9 @@ bool open_buffer(const char *filename, bool new_buffer)
#endif #endif
} }
/* If we're going to load into a new buffer, first create the new /* When loading into a new buffer, first check the file's path is valid,
* buffer and (if possible) lock the corresponding file. */ * and then (if requested and possible) create a lock file for it. */
if (new_buffer) { if (new_buffer && has_valid_path(realname)) {
if (has_valid_path(realname)) {
#ifndef NANO_TINY #ifndef NANO_TINY
if (ISSET(LOCKING) && !ISSET(VIEW_MODE) && filename[0] != '\0') { if (ISSET(LOCKING) && !ISSET(VIEW_MODE) && filename[0] != '\0') {
thelocksname = do_lockfile(realname, TRUE); thelocksname = do_lockfile(realname, TRUE);
@ -428,20 +428,17 @@ bool open_buffer(const char *filename, bool new_buffer)
return FALSE; return FALSE;
} }
} }
#endif /* !NANO_TINY */ #endif
}
} }
if (new_buffer) if (new_buffer)
make_new_buffer(); make_new_buffer();
/* If the filename isn't blank, and we are not in NOREAD_MODE, /* If we have a filename and are not in NOREAD mode, open the file. */
* open the file. Otherwise, treat it as a new file. */
if (filename[0] != '\0' && !ISSET(NOREAD_MODE)) if (filename[0] != '\0' && !ISSET(NOREAD_MODE))
descriptor = open_file(realname, new_buffer, &f); descriptor = open_file(realname, new_buffer, &f);
/* If we have a non-new file, read it in. Then, if the buffer has /* If we've successfully opened an existing file, read it in. */
* no stat, update the stat, if applicable. */
if (descriptor > 0) { if (descriptor > 0) {
install_handler_for_Ctrl_C(); install_handler_for_Ctrl_C();
@ -455,8 +452,8 @@ bool open_buffer(const char *filename, bool new_buffer)
#endif #endif
} }
/* If we have a file, and we've loaded it into a new buffer, set /* When we've loaded a file into a new buffer, set the filename
* the filename and put the cursor at the start of the buffer. */ * and put the cursor at the start of the buffer. */
if (descriptor >= 0 && new_buffer) { if (descriptor >= 0 && new_buffer) {
openfile->filename = mallocstrcpy(openfile->filename, realname); openfile->filename = mallocstrcpy(openfile->filename, realname);
#ifndef NANO_TINY #ifndef NANO_TINY