]>
git.saurik.com Git - wxWidgets.git/blob - src/expat/xmlwf/unixfilemap.c
1 /* Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd
2 See the file COPYING for copying permission.
21 filemap(const char *name
,
22 void (*processor
)(const void *, size_t, const char *, void *arg
),
30 fd
= open(name
, O_RDONLY
);
35 if (fstat(fd
, &sb
) < 0) {
40 if (!S_ISREG(sb
.st_mode
)) {
42 fprintf(stderr
, "%s: not a regular file\n", name
);
47 /* mmap fails for zero length files */
49 static const char c
= '\0';
50 processor(&c
, 0, name
, arg
);
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) {
61 processor(p
, nbytes
, name
, arg
);
62 munmap((caddr_t
)p
, nbytes
);