nano

nano with my custom patches
git clone git://bsandro.tech/nano
Log | Files | Refs | README | LICENSE

commit 48df800db314cc7f8d80240f94b4a4fc6c2f7648
parent ee05daab924cc80adbfb26599fc1ad6ba6197dc5
Author: Benno Schulenberg <bensberg@telfort.nl>
Date:   Sun,  2 Feb 2020 11:13:54 +0100

tweaks: rewrite the same file name into the lock file as the first time

It would be better if nano wrote the full filename into the lock file,
because that would be clearer when Vim displays its warning, but...
this is faster and will do for now.

(Nano should simply also store the full filename in the openfile struct,
so that get_full_path() needs to be called just once for each file.)

This addresses https://savannah.gnu.org/bugs/?57713.

Diffstat:
Msrc/files.c | 16+++++-----------
Msrc/proto.h | 2+-
2 files changed, 6 insertions(+), 12 deletions(-)

diff --git a/src/files.c b/src/files.c @@ -142,19 +142,15 @@ void set_modified(void) titlebar(NULL); #ifndef NANO_TINY - if (openfile->lock_filename != NULL) { - char *fullname = get_full_path(openfile->filename); - - write_lockfile(openfile->lock_filename, fullname, TRUE); - free(fullname); - } + if (openfile->lock_filename != NULL) + write_lockfile(openfile->lock_filename, openfile->filename, TRUE); #endif } #ifndef NANO_TINY /* Write a lockfile, under the given lockfilename. This ALWAYS annihilates * an existing version of that file. Return 1 on success, and 0 on failure. */ -int write_lockfile(const char *lockfilename, const char *origfilename, bool modified) +int write_lockfile(const char *lockfilename, const char *filename, bool modified) { #ifdef HAVE_PWD_H int cflags, fd; @@ -240,10 +236,8 @@ int write_lockfile(const char *lockfilename, const char *origfilename, bool modi lockdata[27] = mypid / (256 * 256 * 256); strncpy(&lockdata[28], mypwuid->pw_name, 16); strncpy(&lockdata[68], myhostname, 32); - if (origfilename != NULL) - strncpy(&lockdata[108], origfilename, 768); - if (modified == TRUE) - lockdata[1007] = 0x55; + strncpy(&lockdata[108], filename, 768); + lockdata[1007] = (modified) ? 0x55 : 0x00; wroteamt = fwrite(lockdata, sizeof(char), LOCKSIZE, filestream); diff --git a/src/proto.h b/src/proto.h @@ -305,7 +305,7 @@ bool outside_of_confinement(const char *currpath, bool allow_tabcomp); #ifndef NANO_TINY void init_backup_dir(void); int delete_lockfile(const char *lockfilename); -int write_lockfile(const char *lockfilename, const char *origfilename, bool modified); +int write_lockfile(const char *lockfilename, const char *filename, bool modified); #endif int copy_file(FILE *inn, FILE *out, bool close_out); bool write_file(const char *name, FILE *f_open, bool tmp,