2 Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd
3 See the file copying.txt for copying permission.
14 #define S_IFREG _S_IFREG
17 #define S_IFMT _S_IFMT
19 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
20 #endif /* not S_ISREG */
24 #define O_BINARY _O_BINARY
30 int filemap(const char *name,
31 void (*processor)(const void *, size_t, const char *, void *arg),
40 fd = open(name, O_RDONLY|O_BINARY);
45 if (fstat(fd, &sb) < 0) {
49 if (!S_ISREG(sb.st_mode)) {
50 fprintf(stderr, "%s: not a regular file\n", name);
56 fprintf(stderr, "%s: out of memory\n", name);
59 n = read(fd, p, nbytes);
66 fprintf(stderr, "%s: read unexpected number of bytes\n", name);
70 processor(p, nbytes, name, arg);