From 40fc4ee2decdfdd7fe4d748b8cac2063d510f2d0 Mon Sep 17 00:00:00 2001 From: Bruce Evans Date: Wed, 18 Nov 1998 11:47:45 +0000 Subject: [PATCH] Don't use mmap() for non-regular files, since st_size is only meaningful for regular files. This fixes recent breakage of cp'ing from /dev/zero. /dev/zero doesn't support mmap(), but the device driver mmap routines are not called for mapping 0 bytes, so the error was not detected. mmap() can't even be used for cp'ing special files that support mmap(), since there is general way to determine the file size. --- bin/cp/utils.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/cp/utils.c b/bin/cp/utils.c index 7e001b2abbf..f6c0f0d21d5 100644 --- a/bin/cp/utils.c +++ b/bin/cp/utils.c @@ -36,7 +36,7 @@ static char sccsid[] = "@(#)utils.c 8.3 (Berkeley) 4/1/94"; #endif static const char rcsid[] = - "$Id: utils.c,v 1.19 1998/06/09 03:38:26 imp Exp $"; + "$Id: utils.c,v 1.20 1998/06/10 06:29:23 peter Exp $"; #endif /* not lint */ #include @@ -124,7 +124,7 @@ copy_file(entp, dne) * wins some CPU back. */ #ifdef VM_AND_BUFFER_CACHE_SYNCHRONIZED - if (fs->st_size <= 8 * 1048576) { + if (S_ISREG(fs->st_mode) && fs->st_size <= 8 * 1048576) { if ((p = mmap(NULL, (size_t)fs->st_size, PROT_READ, MAP_SHARED, from_fd, (off_t)0)) == MAP_FAILED) { warn("%s", entp->fts_path);