diff options
Diffstat (limited to 'expat/xmlwf/readfilemap.c')
-rw-r--r-- | expat/xmlwf/readfilemap.c | 58 |
1 files changed, 30 insertions, 28 deletions
diff --git a/expat/xmlwf/readfilemap.c b/expat/xmlwf/readfilemap.c index 3cc4f7618..d5b84f995 100644 --- a/expat/xmlwf/readfilemap.c +++ b/expat/xmlwf/readfilemap.c @@ -37,37 +37,40 @@ #include <stdio.h> /* Functions close(2) and read(2) */ -#if !defined(_WIN32) && !defined(_WIN64) -# include <unistd.h> +#if ! defined(_WIN32) && ! defined(_WIN64) +# include <unistd.h> #endif /* 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 +# include <io.h> +/* https://msdn.microsoft.com/en-us/library/wyssk1bs(v=vs.100).aspx */ +# define _EXPAT_read _read +# define _EXPAT_read_count_t int +# define _EXPAT_read_req_t unsigned int +#else /* POSIX */ +/* http://pubs.opengroup.org/onlinepubs/009695399/functions/read.html */ +# define _EXPAT_read read +# define _EXPAT_read_count_t ssize_t +# define _EXPAT_read_req_t size_t #endif #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) +# 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" @@ -76,15 +79,14 @@ int filemap(const tchar *name, void (*processor)(const void *, size_t, const tchar *, void *arg), - void *arg) -{ + void *arg) { size_t nbytes; int fd; _EXPAT_read_count_t n; struct stat sb; void *p; - fd = topen(name, O_RDONLY|O_BINARY); + fd = topen(name, O_RDONLY | O_BINARY); if (fd < 0) { tperror(name); return 0; @@ -94,14 +96,14 @@ filemap(const tchar *name, close(fd); return 0; } - if (!S_ISREG(sb.st_mode)) { + if (! S_ISREG(sb.st_mode)) { ftprintf(stderr, T("%s: not a regular file\n"), name); close(fd); return 0; } if (sb.st_size > XML_MAX_CHUNK_LEN) { close(fd); - return 2; /* Cannot be passed to XML_Parse in one go */ + return 2; /* Cannot be passed to XML_Parse in one go */ } nbytes = sb.st_size; @@ -113,12 +115,12 @@ filemap(const tchar *name, return 1; } p = malloc(nbytes); - if (!p) { + if (! p) { ftprintf(stderr, T("%s: out of memory\n"), name); close(fd); return 0; } - n = _EXPAT_read(fd, p, nbytes); + n = _EXPAT_read(fd, p, (_EXPAT_read_req_t)nbytes); if (n < 0) { tperror(name); free(p); |