]>
git.saurik.com Git - wxWidgets.git/blob - src/expat/xmlwf/readfilemap.c
1 /* Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd
2 See the file COPYING for copying permission.
25 #define S_IFREG _S_IFREG
28 #define S_IFMT _S_IFMT
30 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
31 #endif /* not S_ISREG */
35 #define O_BINARY _O_BINARY
44 filemap(const char *name
,
45 void (*processor
)(const void *, size_t, const char *, void *arg
),
54 fd
= open(name
, O_RDONLY
|O_BINARY
);
59 if (fstat(fd
, &sb
) < 0) {
64 if (!S_ISREG(sb
.st_mode
)) {
65 fprintf(stderr
, "%s: not a regular file\n", name
);
70 /* malloc will return NULL with nbytes == 0, handle files with size 0 */
72 static const char c
= '\0';
73 processor(&c
, 0, name
, arg
);
79 fprintf(stderr
, "%s: out of memory\n", name
);
83 n
= read(fd
, p
, nbytes
);
91 fprintf(stderr
, "%s: read unexpected number of bytes\n", name
);
96 processor(p
, nbytes
, name
, arg
);