Deleted Added
full compact
unixfilemap.c (104349) unixfilemap.c (178848)
1/* Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd
2 See the file COPYING for copying permission.
3*/
4
5#include <sys/types.h>
6#include <sys/mman.h>
7#include <sys/stat.h>
8#include <fcntl.h>

--- 30 unchanged lines hidden (view full) ---

39 }
40 if (!S_ISREG(sb.st_mode)) {
41 close(fd);
42 fprintf(stderr, "%s: not a regular file\n", name);
43 return 0;
44 }
45
46 nbytes = sb.st_size;
1/* Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd
2 See the file COPYING for copying permission.
3*/
4
5#include <sys/types.h>
6#include <sys/mman.h>
7#include <sys/stat.h>
8#include <fcntl.h>

--- 30 unchanged lines hidden (view full) ---

39 }
40 if (!S_ISREG(sb.st_mode)) {
41 close(fd);
42 fprintf(stderr, "%s: not a regular file\n", name);
43 return 0;
44 }
45
46 nbytes = sb.st_size;
47 /* mmap fails for zero length files */
48 if (nbytes == 0) {
49 static const char c = '\0';
50 processor(&c, 0, name, arg);
51 close(fd);
52 return 1;
53 }
47 p = (void *)mmap((caddr_t)0, (size_t)nbytes, PROT_READ,
48 MAP_FILE|MAP_PRIVATE, fd, (off_t)0);
49 if (p == (void *)-1) {
50 perror(name);
51 close(fd);
52 return 0;
53 }
54 processor(p, nbytes, name, arg);
55 munmap((caddr_t)p, nbytes);
56 close(fd);
57 return 1;
58}
54 p = (void *)mmap((caddr_t)0, (size_t)nbytes, PROT_READ,
55 MAP_FILE|MAP_PRIVATE, fd, (off_t)0);
56 if (p == (void *)-1) {
57 perror(name);
58 close(fd);
59 return 0;
60 }
61 processor(p, nbytes, name, arg);
62 munmap((caddr_t)p, nbytes);
63 close(fd);
64 return 1;
65}