summaryrefslogtreecommitdiffstats
path: root/usr.bin
diff options
context:
space:
mode:
authoralex <alex@FreeBSD.org>1997-01-16 21:58:40 +0000
committeralex <alex@FreeBSD.org>1997-01-16 21:58:40 +0000
commita3118e8c6826349b3fc54da3850d6dea994a3a35 (patch)
treed61898dd79824c10ca33127214d8569c804559c2 /usr.bin
parent752ba4d26f2e94cc31940f50407a6b18b86ee0e8 (diff)
downloadFreeBSD-src-a3118e8c6826349b3fc54da3850d6dea994a3a35.zip
FreeBSD-src-a3118e8c6826349b3fc54da3850d6dea994a3a35.tar.gz
Sweep through the tree fixing mmap() usage:
- Use MAP_FAILED instead of the constant -1 to indicate failure (required by POSIX). - Removed flag arguments of '0' (required by POSIX). - Fixed code which expected an error return of 0. - Fixed code which thought any address with the high bit set was an error. - Check for failure where no checks were present. Discussed with: bde
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/cmp/regular.c4
-rw-r--r--usr.bin/locate/locate/locate.c2
-rw-r--r--usr.bin/look/look.c2
-rw-r--r--usr.bin/strip/strip.c2
-rw-r--r--usr.bin/tail/forward.c2
-rw-r--r--usr.bin/tail/reverse.c2
-rw-r--r--usr.bin/xinstall/xinstall.c10
-rw-r--r--usr.bin/xlint/lint1/mem1.c2
-rw-r--r--usr.bin/xlint/lint2/mem2.c2
9 files changed, 14 insertions, 14 deletions
diff --git a/usr.bin/cmp/regular.c b/usr.bin/cmp/regular.c
index 5d301fa..f540ab4 100644
--- a/usr.bin/cmp/regular.c
+++ b/usr.bin/cmp/regular.c
@@ -80,12 +80,12 @@ c_regular(fd1, file1, skip1, len1, fd2, file2, skip2, len2)
return (c_special(fd1, file1, skip1, fd2, file2, skip2));
if ((p1 = (u_char *)mmap(NULL,
- (size_t)length, PROT_READ, 0, fd1, off1)) == (u_char *)-1)
+ (size_t)length, PROT_READ, MAP_SHARED, fd1, off1)) == (u_char *)MAP_FAILED)
err(ERR_EXIT, "%s", file1);
madvise(p1, length, MADV_SEQUENTIAL);
if ((p2 = (u_char *)mmap(NULL,
- (size_t)length, PROT_READ, 0, fd2, off2)) == (u_char *)-1)
+ (size_t)length, PROT_READ, MAP_SHARED, fd2, off2)) == (u_char *)MAP_FAILED)
err(ERR_EXIT, "%s", file2);
madvise(p2, length, MADV_SEQUENTIAL);
diff --git a/usr.bin/locate/locate/locate.c b/usr.bin/locate/locate/locate.c
index 427d49d..791c3eb 100644
--- a/usr.bin/locate/locate/locate.c
+++ b/usr.bin/locate/locate/locate.c
@@ -301,7 +301,7 @@ search_mmap(db, s)
if ((p = mmap((caddr_t)0, (size_t)len,
PROT_READ, MAP_SHARED,
- fd, (off_t)0)) == (caddr_t)-1)
+ fd, (off_t)0)) == MAP_FAILED)
err(1, "mmap ``%s''", path_fcodes);
/* foreach search string ... */
diff --git a/usr.bin/look/look.c b/usr.bin/look/look.c
index e2bd952..daef12f 100644
--- a/usr.bin/look/look.c
+++ b/usr.bin/look/look.c
@@ -143,7 +143,7 @@ main(argc, argv)
if (sb.st_size > SIZE_T_MAX)
err("%s: %s", file, strerror(EFBIG));
if ((front = mmap(NULL,
- (size_t)sb.st_size, PROT_READ, 0, fd, (off_t)0)) == NULL)
+ (size_t)sb.st_size, PROT_READ, MAP_SHARED, fd, (off_t)0)) == MAP_FAILED)
err("%s: %s", file, strerror(errno));
back = front + sb.st_size;
exit(look(string, front, back));
diff --git a/usr.bin/strip/strip.c b/usr.bin/strip/strip.c
index 8fe4c49..36f14c2 100644
--- a/usr.bin/strip/strip.c
+++ b/usr.bin/strip/strip.c
@@ -173,7 +173,7 @@ s_stab(fn, fd, ep)
/* Map the file. */
if ((ep = (EXEC *)mmap(NULL, (size_t)sb.st_size,
- PROT_READ | PROT_WRITE, MAP_SHARED, fd, (off_t)0)) == (EXEC *)-1) {
+ PROT_READ | PROT_WRITE, MAP_SHARED, fd, (off_t)0)) == (EXEC *)MAP_FAILED) {
err(0, "%s: %s", fn, strerror(errno));
return;
}
diff --git a/usr.bin/tail/forward.c b/usr.bin/tail/forward.c
index 4b22eef..b9457af 100644
--- a/usr.bin/tail/forward.c
+++ b/usr.bin/tail/forward.c
@@ -210,7 +210,7 @@ rlines(fp, off, sbp)
}
if ((start = mmap(NULL, (size_t)size,
- PROT_READ, 0, fileno(fp), (off_t)0)) == (caddr_t)-1) {
+ PROT_READ, MAP_SHARED, fileno(fp), (off_t)0)) == MAP_FAILED) {
ierr();
return;
}
diff --git a/usr.bin/tail/reverse.c b/usr.bin/tail/reverse.c
index 2653add..0a07f4f 100644
--- a/usr.bin/tail/reverse.c
+++ b/usr.bin/tail/reverse.c
@@ -125,7 +125,7 @@ r_reg(fp, style, off, sbp)
}
if ((start = mmap(NULL, (size_t)size,
- PROT_READ, 0, fileno(fp), (off_t)0)) == (caddr_t)-1) {
+ PROT_READ, MAP_SHARED, fileno(fp), (off_t)0)) == MAP_FAILED) {
ierr();
return;
}
diff --git a/usr.bin/xinstall/xinstall.c b/usr.bin/xinstall/xinstall.c
index 9a2a991..0148958 100644
--- a/usr.bin/xinstall/xinstall.c
+++ b/usr.bin/xinstall/xinstall.c
@@ -513,11 +513,11 @@ compare(int from_fd, const char *from_name, int to_fd, const char *to_name,
if (tsize <= 8 * 1024 * 1024) {
done_compare = 0;
if (trymmap(from_fd) && trymmap(to_fd)) {
- p = mmap(NULL, tsize, PROT_READ, 0, from_fd, (off_t)0);
- if ((long)p == -1)
+ p = mmap(NULL, tsize, PROT_READ, MAP_SHARED, from_fd, (off_t)0);
+ if (p == (char *)MAP_FAILED)
goto out;
- q = mmap(NULL, tsize, PROT_READ, 0, to_fd, (off_t)0);
- if ((long)q == -1) {
+ q = mmap(NULL, tsize, PROT_READ, MAP_SHARED, to_fd, (off_t)0);
+ if (q == (char *)MAP_FAILED) {
munmap(p, tsize);
goto out;
}
@@ -581,7 +581,7 @@ copy(from_fd, from_name, to_fd, to_name, size)
done_copy = 0;
if (size <= 8 * 1048576 && trymmap(from_fd)) {
if ((p = mmap(NULL, (size_t)size, PROT_READ,
- 0, from_fd, (off_t)0)) == (char *)-1)
+ MAP_SHARED, from_fd, (off_t)0)) == (char *)MAP_FAILED)
goto out;
if ((nw = write(to_fd, p, size)) != size) {
serrno = errno;
diff --git a/usr.bin/xlint/lint1/mem1.c b/usr.bin/xlint/lint1/mem1.c
index df880b1..f3bf3c6 100644
--- a/usr.bin/xlint/lint1/mem1.c
+++ b/usr.bin/xlint/lint1/mem1.c
@@ -180,7 +180,7 @@ xnewblk()
prot = PROT_READ | PROT_WRITE;
flags = MAP_ANON | MAP_PRIVATE;
mb->blk = mmap(NULL, mblklen, prot, flags, -1, (off_t)0);
- if (mb->blk == (void *)-1)
+ if (mb->blk == (void *)MAP_FAILED)
err(1, "can't map memory");
if (ALIGN((u_long)mb->blk) != (u_long)mb->blk)
errx(1, "mapped address is not aligned");
diff --git a/usr.bin/xlint/lint2/mem2.c b/usr.bin/xlint/lint2/mem2.c
index 06d7491..ed97c6f 100644
--- a/usr.bin/xlint/lint2/mem2.c
+++ b/usr.bin/xlint/lint2/mem2.c
@@ -82,7 +82,7 @@ xalloc(sz)
prot = PROT_READ | PROT_WRITE;
flags = MAP_ANON | MAP_PRIVATE;
mbuf = mmap(NULL, mblklen, prot, flags, -1, (off_t)0);
- if (mbuf == (void *)-1)
+ if (mbuf == (void *)MAP_FAILED)
err(1, "can't map memory");
if (ALIGN((u_long)mbuf) != (u_long)mbuf)
errx(1, "mapped address is not aligned");
OpenPOWER on IntegriCloud