Module Name: src
Committed By: joerg
Date: Wed Oct 21 17:16:11 UTC 2009
Modified Files:
src/usr.bin/patch: inp.c
Log Message:
Do not try to mmap a zero length file.
To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/usr.bin/patch/inp.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/usr.bin/patch/inp.c
diff -u src/usr.bin/patch/inp.c:1.22 src/usr.bin/patch/inp.c:1.23
--- src/usr.bin/patch/inp.c:1.22 Fri Jun 5 19:55:43 2009
+++ src/usr.bin/patch/inp.c Wed Oct 21 17:16:11 2009
@@ -1,7 +1,7 @@
/*
* $OpenBSD: inp.c,v 1.34 2006/03/11 19:41:30 otto Exp $
* $DragonFly: src/usr.bin/patch/inp.c,v 1.6 2007/09/29 23:11:10 swildner Exp $
- * $NetBSD: inp.c,v 1.22 2009/06/05 19:55:43 joerg Exp $
+ * $NetBSD: inp.c,v 1.23 2009/10/21 17:16:11 joerg Exp $
*/
/*
@@ -31,7 +31,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: inp.c,v 1.22 2009/06/05 19:55:43 joerg Exp $");
+__RCSID("$NetBSD: inp.c,v 1.23 2009/10/21 17:16:11 joerg Exp $");
#include <sys/types.h>
#include <sys/file.h>
@@ -261,12 +261,16 @@
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);