2
Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd
3
See the file COPYING for copying permission.
20
int filemap(const char *name,
21
void (*processor)(const void *, size_t, const char *, void *arg),
29
fd = open(name, O_RDONLY);
34
if (fstat(fd, &sb) < 0) {
39
if (!S_ISREG(sb.st_mode)) {
41
fprintf(stderr, "%s: not a regular file\n", name);
46
p = (void *)mmap((caddr_t)0, (size_t)nbytes, PROT_READ,
47
MAP_FILE|MAP_PRIVATE, fd, (off_t)0);
48
if (p == (void *)-1) {
53
processor(p, nbytes, name, arg);
54
munmap((caddr_t)p, nbytes);