From 705eaef8b847e2fe924e76b18cb4d5064650d3ce Mon Sep 17 00:00:00 2001 From: jdp Date: Sun, 6 Sep 1998 20:43:25 +0000 Subject: Fix calls to mmap. It returns void *, and on failure it returns MAP_FAILED. Don't try to extend the mapping in place if it is too short. There's no guarantee it will be possible. Remap the file instead. Put in a few style fixes. Submitted by: Bruce Evans --- sbin/ldconfig/ldconfig.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'sbin/ldconfig') diff --git a/sbin/ldconfig/ldconfig.c b/sbin/ldconfig/ldconfig.c index e26c61c..2206c0b 100644 --- a/sbin/ldconfig/ldconfig.c +++ b/sbin/ldconfig/ldconfig.c @@ -30,7 +30,7 @@ #ifndef lint static const char rcsid[] = - "$Id: ldconfig.c,v 1.25 1998/09/05 03:30:54 jdp Exp $"; + "$Id: ldconfig.c,v 1.26 1998/09/05 16:20:15 jdp Exp $"; #endif /* not lint */ #include @@ -169,12 +169,10 @@ char *argv[]; if (stat(argv[i], &stbuf) == -1) { warn("%s", argv[i]); rval = -1; - } - else if (!strcmp(argv[i], "/usr/lib")) { + } else if (strcmp(argv[i], "/usr/lib") == 0) { warnx("WARNING! '%s' can not be used", argv[i]); rval = -1; - } - else { + } else { /* * See if this is a directory-containing * file instead of a directory @@ -573,7 +571,8 @@ static int readhints() { int fd; - caddr_t addr; + void *addr; + long fsize; long msize; struct hints_header *hdr; struct hints_bucket *blist; @@ -589,7 +588,7 @@ readhints() msize = PAGE_SIZE; addr = mmap(0, msize, PROT_READ, MAP_COPY, fd, 0); - if (addr == (caddr_t)-1) { + if (addr == MAP_FAILED) { warn("%s", hints_file); return -1; } @@ -608,13 +607,14 @@ readhints() } if (hdr->hh_ehints > msize) { - if (mmap(addr+msize, hdr->hh_ehints - msize, - PROT_READ, MAP_COPY|MAP_FIXED, - fd, msize) != (caddr_t)(addr+msize)) { - + fsize = hdr->hh_ehints; + munmap(addr, msize); + addr = mmap(0, fsize, PROT_READ, MAP_COPY, fd, 0); + if (addr == MAP_FAILED) { warn("%s", hints_file); return -1; } + hdr = (struct hints_header *)addr; } close(fd); -- cgit v1.1