vis
a vi-like editor based on Plan 9's structural regular expressions
git clone https://9o.is/git/vis.git
commit ec59bc19d2cabbc62f98adf0d0925ad93c1dc411 parent e35469dbf431c066c6e458d90bc6869ddf14799f Author: Gregor Best <gbe@unobtanium.de> Date: Tue, 16 Sep 2014 13:24:37 +0200 Fix editing of files with length 0 Signed-off-by: Gregor Best <gbe@unobtanium.de> Diffstat:
| M | text.c | | | 8 | +++++--- |
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/text.c b/text.c @@ -663,9 +663,11 @@ Text *text_load(const char *filename) { goto out; // XXX: use lseek(fd, 0, SEEK_END); instead? txt->buf.size = txt->info.st_size; - txt->buf.data = mmap(NULL, txt->info.st_size, PROT_READ, MAP_SHARED, txt->fd, 0); - if (txt->buf.data == MAP_FAILED) - goto out; + if (txt->buf.size != 0) { + txt->buf.data = mmap(NULL, txt->info.st_size, PROT_READ, MAP_SHARED, txt->fd, 0); + if (txt->buf.data == MAP_FAILED) + goto out; + } Piece *p = piece_alloc(txt); if (!p)