# include <unistd.h>
#endif
-#ifndef S_ISREG
-#ifndef S_IFREG
-#define S_IFREG _S_IFREG
-#endif
-#ifndef S_IFMT
-#define S_IFMT _S_IFMT
+/* Function "read": */
+#if defined(_MSC_VER)
+ /* https://msdn.microsoft.com/en-us/library/wyssk1bs(v=vs.100).aspx */
+# define _EXPAT_read _read
+# define _EXPAT_read_count_t int
+#else /* POSIX */
+ /* http://pubs.opengroup.org/onlinepubs/009695399/functions/read.html */
+# define _EXPAT_read read
+# define _EXPAT_read_count_t ssize_t
#endif
-#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
+
+#ifndef S_ISREG
+# ifndef S_IFREG
+# define S_IFREG _S_IFREG
+# endif
+# ifndef S_IFMT
+# define S_IFMT _S_IFMT
+# endif
+# define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
#endif /* not S_ISREG */
#ifndef O_BINARY
-#ifdef _O_BINARY
-#define O_BINARY _O_BINARY
-#else
-#define O_BINARY 0
-#endif
+# ifdef _O_BINARY
+# define O_BINARY _O_BINARY
+# else
+# define O_BINARY 0
+# endif
#endif
+#include "xmltchar.h"
#include "filemap.h"
int
-filemap(const char *name,
- void (*processor)(const void *, size_t, const char *, void *arg),
+filemap(const tchar *name,
+ void (*processor)(const void *, size_t, const tchar *, void *arg),
void *arg)
{
size_t nbytes;
int fd;
- ssize_t n;
+ _EXPAT_read_count_t n;
struct stat sb;
void *p;
- fd = open(name, O_RDONLY|O_BINARY);
+ fd = topen(name, O_RDONLY|O_BINARY);
if (fd < 0) {
- perror(name);
+ tperror(name);
return 0;
}
if (fstat(fd, &sb) < 0) {
- perror(name);
+ tperror(name);
close(fd);
return 0;
}
if (!S_ISREG(sb.st_mode)) {
- fprintf(stderr, "%s: not a regular file\n", name);
+ ftprintf(stderr, T("%s: not a regular file\n"), name);
close(fd);
return 0;
}
}
p = malloc(nbytes);
if (!p) {
- fprintf(stderr, "%s: out of memory\n", name);
+ ftprintf(stderr, T("%s: out of memory\n"), name);
close(fd);
return 0;
}
- n = read(fd, p, nbytes);
+ n = _EXPAT_read(fd, p, nbytes);
if (n < 0) {
- perror(name);
+ tperror(name);
free(p);
close(fd);
return 0;
}
- if (n != (ssize_t)nbytes) {
- fprintf(stderr, "%s: read unexpected number of bytes\n", name);
+ if (n != (_EXPAT_read_count_t)nbytes) {
+ ftprintf(stderr, T("%s: read unexpected number of bytes\n"), name);
free(p);
close(fd);
return 0;