From ee1db5ae45738b1bf56e41e65aab948da2ddc0b2 Mon Sep 17 00:00:00 2001 From: Colin Percival Date: Mon, 31 Aug 2009 13:02:21 +0000 Subject: [PATCH] MFC r196558: Don't try to mmap the contents of empty files. This behaviour was harmless prior to r195693, when mmap(2) changed from silently ignoring requests for mapping zero bytes to returning EINVAL; this commit can be seen as adjusting for the change in mmap(2) in order to make look(1) act like it did previously. Reviewed by: jhb Approved by: re (kib) --- usr.bin/look/look.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/usr.bin/look/look.c b/usr.bin/look/look.c index e6fd1b8b9e2..7c590c7de08 100644 --- a/usr.bin/look/look.c +++ b/usr.bin/look/look.c @@ -140,6 +140,10 @@ main(int argc, char *argv[]) err(2, "%s", file); if (sb.st_size > SIZE_T_MAX) errx(2, "%s: %s", file, strerror(EFBIG)); + if (sb.st_size == 0) { + close(fd); + continue; + } if ((front = mmap(NULL, (size_t)sb.st_size, PROT_READ, MAP_SHARED, fd, (off_t)0)) == MAP_FAILED) err(2, "%s", file); back = front + sb.st_size;