Fix file access for xmlwf compiled with XML_UNICODE_WCHAR_T on MinGW

This commit is contained in:
Rhodri James 2017-08-29 17:59:04 +01:00
parent 742fbf024f
commit 71b533dae1
3 changed files with 18 additions and 8 deletions

View File

@ -70,8 +70,8 @@
#endif
#endif
#include "filemap.h"
#include "xmltchar.h"
#include "filemap.h"
int
filemap(const tchar *name,

View File

@ -43,11 +43,18 @@
#define MAP_FILE 0
#endif
#include "xmltchar.h"
#include "filemap.h"
#ifdef XML_UNICODE_WCHAR_T
#define XML_FMT_STR "ls"
#else
#define XML_FMT_STR "s"
#endif
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)
{
int fd;
@ -55,19 +62,19 @@ filemap(const char *name,
struct stat sb;
void *p;
fd = open(name, O_RDONLY);
fd = topen(name, O_RDONLY);
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)) {
close(fd);
fprintf(stderr, "%s: not a regular file\n", name);
fprintf(stderr, "%" XML_FMT_STR ": not a regular file\n", name);
return 0;
}
if (sb.st_size > XML_MAX_CHUNK_LEN) {
@ -86,7 +93,7 @@ filemap(const char *name,
p = (void *)mmap((void *)0, (size_t)nbytes, PROT_READ,
MAP_FILE|MAP_PRIVATE, fd, (off_t)0);
if (p == (void *)-1) {
perror(name);
tperror(name);
close(fd);
return 0;
}

View File

@ -30,6 +30,9 @@
USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/* Ensures compile-time constants are consistent */
#include "expat_external.h"
#ifdef XML_UNICODE
#ifndef XML_UNICODE_WCHAR_T
#error xmlwf requires a 16-bit Unicode-compatible wchar_t