make, grep: let them use mmap

This commit is contained in:
Ben Gras 2013-03-16 03:15:27 +00:00
parent 6da3d19afb
commit a498a32ee9
3 changed files with 14 additions and 18 deletions

View File

@ -42,9 +42,7 @@ static size_t lnbuflen;
#endif
#define FILE_STDIO 0
#ifndef __minix
#define FILE_MMAP 1
#endif
#define FILE_GZIP 2
struct file {

View File

@ -1,4 +1,3 @@
#ifndef __minix
/* $OpenBSD: mmfile.c,v 1.11 2006/09/19 05:52:23 otto Exp $ */
/*-
@ -40,6 +39,9 @@
#define MAX_MAP_LEN 1048576
#define munmap minix_munmap
#define mmap minix_mmap
mmf_t *
mmopen(char *fn, char *mode)
{
@ -87,7 +89,7 @@ mmclose(mmf_t *mmf)
char *
mmfgetln(mmf_t *mmf, size_t *l)
{
static char *p;
static unsigned char *p;
char *start = mmf->ptr; /* Remove speed bump */
char *end = mmf->end; /* Remove speed bump */
@ -101,4 +103,3 @@ mmfgetln(mmf_t *mmf, size_t *l)
++mmf->ptr;
return p;
}
#endif

View File

@ -68,6 +68,15 @@
* SUCH DAMAGE.
*/
#ifdef __minix
#define mmap minix_mmap
#define munmap minix_munmap
#ifndef MAP_COPY
#define MAP_COPY MAP_PRIVATE
#endif
#endif
#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: parse.c,v 1.185 2012/06/12 19:21:51 joerg Exp $";
#else
@ -133,9 +142,6 @@ __RCSID("$NetBSD: parse.c,v 1.185 2012/06/12 19:21:51 joerg Exp $");
#include <stdarg.h>
#include <stdio.h>
#ifndef MAP_FILE
#define MAP_FILE 0
#endif
#ifndef MAP_COPY
#define MAP_COPY MAP_PRIVATE
#endif
@ -403,9 +409,7 @@ loadedfile_destroy(struct loadedfile *lf)
{
if (lf->buf != NULL) {
if (lf->maplen > 0) {
#ifndef __minix
munmap(lf->buf, lf->maplen);
#endif
} else {
free(lf->buf);
}
@ -430,7 +434,6 @@ loadedfile_nextbuf(void *x, size_t *len)
return lf->buf;
}
#ifndef __minix
/*
* Try to get the size of a file.
*/
@ -463,7 +466,6 @@ load_getsize(int fd, size_t *ret)
*ret = (size_t) st.st_size;
return SUCCESS;
}
#endif /* ndef __minix */
/*
* Read in a file.
@ -479,9 +481,7 @@ static struct loadedfile *
loadfile(const char *path, int fd)
{
struct loadedfile *lf;
#ifndef __minix
long pagesize;
#endif
ssize_t result;
size_t bufpos;
@ -501,7 +501,6 @@ loadfile(const char *path, int fd)
#endif
}
#ifndef __minix
if (load_getsize(fd, &lf->len) == SUCCESS) {
/* found a size, try mmap */
pagesize = sysconf(_SC_PAGESIZE);
@ -524,6 +523,7 @@ loadfile(const char *path, int fd)
* FUTURE: remove PROT_WRITE when the parser no longer
* needs to scribble on the input.
*/
lf->buf = mmap(NULL, lf->maplen, PROT_READ|PROT_WRITE,
MAP_FILE|MAP_COPY, fd, 0);
if (lf->buf != MAP_FAILED) {
@ -539,7 +539,6 @@ loadfile(const char *path, int fd)
goto done;
}
}
#endif
/* cannot mmap; load the traditional way */
@ -572,9 +571,7 @@ loadfile(const char *path, int fd)
lf->buf = bmake_realloc(lf->buf, lf->len);
}
#ifndef __minix
done:
#endif /* !defined(__minix) */
if (path != NULL) {
close(fd);
}