make, grep: let them use mmap
This commit is contained in:
parent
6da3d19afb
commit
a498a32ee9
|
|
@ -42,9 +42,7 @@ static size_t lnbuflen;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define FILE_STDIO 0
|
#define FILE_STDIO 0
|
||||||
#ifndef __minix
|
|
||||||
#define FILE_MMAP 1
|
#define FILE_MMAP 1
|
||||||
#endif
|
|
||||||
#define FILE_GZIP 2
|
#define FILE_GZIP 2
|
||||||
|
|
||||||
struct file {
|
struct file {
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
#ifndef __minix
|
|
||||||
/* $OpenBSD: mmfile.c,v 1.11 2006/09/19 05:52:23 otto Exp $ */
|
/* $OpenBSD: mmfile.c,v 1.11 2006/09/19 05:52:23 otto Exp $ */
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
|
|
@ -40,6 +39,9 @@
|
||||||
|
|
||||||
#define MAX_MAP_LEN 1048576
|
#define MAX_MAP_LEN 1048576
|
||||||
|
|
||||||
|
#define munmap minix_munmap
|
||||||
|
#define mmap minix_mmap
|
||||||
|
|
||||||
mmf_t *
|
mmf_t *
|
||||||
mmopen(char *fn, char *mode)
|
mmopen(char *fn, char *mode)
|
||||||
{
|
{
|
||||||
|
|
@ -87,7 +89,7 @@ mmclose(mmf_t *mmf)
|
||||||
char *
|
char *
|
||||||
mmfgetln(mmf_t *mmf, size_t *l)
|
mmfgetln(mmf_t *mmf, size_t *l)
|
||||||
{
|
{
|
||||||
static char *p;
|
static unsigned char *p;
|
||||||
char *start = mmf->ptr; /* Remove speed bump */
|
char *start = mmf->ptr; /* Remove speed bump */
|
||||||
char *end = mmf->end; /* Remove speed bump */
|
char *end = mmf->end; /* Remove speed bump */
|
||||||
|
|
||||||
|
|
@ -101,4 +103,3 @@ mmfgetln(mmf_t *mmf, size_t *l)
|
||||||
++mmf->ptr;
|
++mmf->ptr;
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
|
||||||
|
|
@ -68,6 +68,15 @@
|
||||||
* SUCH DAMAGE.
|
* 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
|
#ifndef MAKE_NATIVE
|
||||||
static char rcsid[] = "$NetBSD: parse.c,v 1.185 2012/06/12 19:21:51 joerg Exp $";
|
static char rcsid[] = "$NetBSD: parse.c,v 1.185 2012/06/12 19:21:51 joerg Exp $";
|
||||||
#else
|
#else
|
||||||
|
|
@ -133,9 +142,6 @@ __RCSID("$NetBSD: parse.c,v 1.185 2012/06/12 19:21:51 joerg Exp $");
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#ifndef MAP_FILE
|
|
||||||
#define MAP_FILE 0
|
|
||||||
#endif
|
|
||||||
#ifndef MAP_COPY
|
#ifndef MAP_COPY
|
||||||
#define MAP_COPY MAP_PRIVATE
|
#define MAP_COPY MAP_PRIVATE
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -403,9 +409,7 @@ loadedfile_destroy(struct loadedfile *lf)
|
||||||
{
|
{
|
||||||
if (lf->buf != NULL) {
|
if (lf->buf != NULL) {
|
||||||
if (lf->maplen > 0) {
|
if (lf->maplen > 0) {
|
||||||
#ifndef __minix
|
|
||||||
munmap(lf->buf, lf->maplen);
|
munmap(lf->buf, lf->maplen);
|
||||||
#endif
|
|
||||||
} else {
|
} else {
|
||||||
free(lf->buf);
|
free(lf->buf);
|
||||||
}
|
}
|
||||||
|
|
@ -430,7 +434,6 @@ loadedfile_nextbuf(void *x, size_t *len)
|
||||||
return lf->buf;
|
return lf->buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef __minix
|
|
||||||
/*
|
/*
|
||||||
* Try to get the size of a file.
|
* 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;
|
*ret = (size_t) st.st_size;
|
||||||
return SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
#endif /* ndef __minix */
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Read in a file.
|
* Read in a file.
|
||||||
|
|
@ -479,9 +481,7 @@ static struct loadedfile *
|
||||||
loadfile(const char *path, int fd)
|
loadfile(const char *path, int fd)
|
||||||
{
|
{
|
||||||
struct loadedfile *lf;
|
struct loadedfile *lf;
|
||||||
#ifndef __minix
|
|
||||||
long pagesize;
|
long pagesize;
|
||||||
#endif
|
|
||||||
ssize_t result;
|
ssize_t result;
|
||||||
size_t bufpos;
|
size_t bufpos;
|
||||||
|
|
||||||
|
|
@ -501,7 +501,6 @@ loadfile(const char *path, int fd)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef __minix
|
|
||||||
if (load_getsize(fd, &lf->len) == SUCCESS) {
|
if (load_getsize(fd, &lf->len) == SUCCESS) {
|
||||||
/* found a size, try mmap */
|
/* found a size, try mmap */
|
||||||
pagesize = sysconf(_SC_PAGESIZE);
|
pagesize = sysconf(_SC_PAGESIZE);
|
||||||
|
|
@ -524,6 +523,7 @@ loadfile(const char *path, int fd)
|
||||||
* FUTURE: remove PROT_WRITE when the parser no longer
|
* FUTURE: remove PROT_WRITE when the parser no longer
|
||||||
* needs to scribble on the input.
|
* needs to scribble on the input.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
lf->buf = mmap(NULL, lf->maplen, PROT_READ|PROT_WRITE,
|
lf->buf = mmap(NULL, lf->maplen, PROT_READ|PROT_WRITE,
|
||||||
MAP_FILE|MAP_COPY, fd, 0);
|
MAP_FILE|MAP_COPY, fd, 0);
|
||||||
if (lf->buf != MAP_FAILED) {
|
if (lf->buf != MAP_FAILED) {
|
||||||
|
|
@ -539,7 +539,6 @@ loadfile(const char *path, int fd)
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
/* cannot mmap; load the traditional way */
|
/* cannot mmap; load the traditional way */
|
||||||
|
|
||||||
|
|
@ -572,9 +571,7 @@ loadfile(const char *path, int fd)
|
||||||
lf->buf = bmake_realloc(lf->buf, lf->len);
|
lf->buf = bmake_realloc(lf->buf, lf->len);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef __minix
|
|
||||||
done:
|
done:
|
||||||
#endif /* !defined(__minix) */
|
|
||||||
if (path != NULL) {
|
if (path != NULL) {
|
||||||
close(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user