diff options
author | Antoine Jacoutot <ajacoutot@cvs.openbsd.org> | 2012-04-10 14:46:35 +0000 |
---|---|---|
committer | Antoine Jacoutot <ajacoutot@cvs.openbsd.org> | 2012-04-10 14:46:35 +0000 |
commit | 8e0b6ea5c5cc887f18f09259749c292a23fd8716 (patch) | |
tree | 399c60e9cb64852f7e9ab5b619e1a077573cbeac | |
parent | 6b71ef75cbdbb8e2b08e2bf746084f89a9330144 (diff) |
Don't try to mmap a zero length file, from NetBSD.
Needed after the recent mmap(2) change.
ok ariane@
-rw-r--r-- | usr.bin/patch/inp.c | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/usr.bin/patch/inp.c b/usr.bin/patch/inp.c index 6657d198390..eed1aefad68 100644 --- a/usr.bin/patch/inp.c +++ b/usr.bin/patch/inp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: inp.c,v 1.35 2009/10/27 23:59:41 deraadt Exp $ */ +/* $OpenBSD: inp.c,v 1.36 2012/04/10 14:46:34 ajacoutot Exp $ */ /* * patch - a program to apply diffs to original files @@ -243,12 +243,16 @@ plan_a(const char *filename) if ((ifd = open(filename, O_RDONLY)) < 0) pfatal("can't open file %s", filename); - i_womp = mmap(NULL, i_size, PROT_READ, MAP_PRIVATE, ifd, 0); - if (i_womp == MAP_FAILED) { - perror("mmap failed"); + if (i_size) { + i_womp = mmap(NULL, i_size, PROT_READ, MAP_PRIVATE, ifd, 0); + if (i_womp == MAP_FAILED) { + perror("mmap failed"); + i_womp = NULL; + close(ifd); + return false; + } + } else { i_womp = NULL; - close(ifd); - return false; } close(ifd); |