vis
a vi-like editor based on Plan 9's structural regular expressions
git clone https://9o.is/git/vis.git
commit b2b399848d6020729a82db8fe97c10dd7de0926c parent 40b12e9523849c1f87b4ed3e49707cf04950f7ae Author: Marc André Tanner <mat@brain-dump.org> Date: Mon, 22 Jun 2020 09:10:37 +0200 text: code cleanup, use local variable No functionl change. Diffstat:
| M | text.c | | | 17 | +++++++++-------- |
1 file changed, 9 insertions(+), 8 deletions(-)
diff --git a/text.c b/text.c @@ -942,30 +942,31 @@ static bool text_save_begin_inplace(TextSave *ctx) { goto err; if (fstat(ctx->fd, &meta) == -1) goto err; + Block *block = txt->block; if (meta.st_dev == txt->info.st_dev && meta.st_ino == txt->info.st_ino && - txt->block && txt->block->type == MMAP_ORIG && txt->block->size) { + block && block->type == MMAP_ORIG && block->size) { /* The file we are going to overwrite is currently mmap-ed from * text_load, therefore we copy the mmap-ed block to a temporary * file and remap it at the same position such that all pointers * from the various pieces are still valid. */ - size_t size = txt->block->size; + size_t size = block->size; char tmpname[32] = "/tmp/vis-XXXXXX"; newfd = mkstemp(tmpname); if (newfd == -1) goto err; if (unlink(tmpname) == -1) goto err; - ssize_t written = write_all(newfd, txt->block->data, size); + ssize_t written = write_all(newfd, block->data, size); if (written == -1 || (size_t)written != size) goto err; - if (munmap(txt->block->data, size) == -1) + if (munmap(block->data, size) == -1) goto err; - void *data = mmap(txt->block->data, size, PROT_READ, MAP_SHARED, newfd, 0); + void *data = mmap(block->data, size, PROT_READ, MAP_SHARED, newfd, 0); if (data == MAP_FAILED) goto err; - if (data != txt->block->data) { + if (data != block->data) { munmap(data, size); goto err; } @@ -973,8 +974,8 @@ static bool text_save_begin_inplace(TextSave *ctx) { newfd = -1; if (close_failed) goto err; - txt->block->data = data; - txt->block->type = MMAP; + block->data = data; + block->type = MMAP; newfd = -1; } /* overwrite the existing file content, if something goes wrong