summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/expat/xmlwf/unixfilemap.c
diff options
context:
space:
mode:
Diffstat (limited to '3rdparty/expat/xmlwf/unixfilemap.c')
-rw-r--r--3rdparty/expat/xmlwf/unixfilemap.c68
1 files changed, 53 insertions, 15 deletions
diff --git a/3rdparty/expat/xmlwf/unixfilemap.c b/3rdparty/expat/xmlwf/unixfilemap.c
index e13299da05f..0d0dc0424dc 100644
--- a/3rdparty/expat/xmlwf/unixfilemap.c
+++ b/3rdparty/expat/xmlwf/unixfilemap.c
@@ -1,5 +1,33 @@
-/* Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd
- See the file COPYING for copying permission.
+/*
+ __ __ _
+ ___\ \/ /_ __ __ _| |_
+ / _ \\ /| '_ \ / _` | __|
+ | __// \| |_) | (_| | |_
+ \___/_/\_\ .__/ \__,_|\__|
+ |_| XML parser
+
+ Copyright (c) 1997-2000 Thai Open Source Software Center Ltd
+ Copyright (c) 2000-2017 Expat development team
+ Licensed under the MIT license:
+
+ Permission is hereby granted, free of charge, to any person obtaining
+ a copy of this software and associated documentation files (the
+ "Software"), to deal in the Software without restriction, including
+ without limitation the rights to use, copy, modify, merge, publish,
+ distribute, sublicense, and/or sell copies of the Software, and to permit
+ persons to whom the Software is furnished to do so, subject to the
+ following conditions:
+
+ The above copyright notice and this permission notice shall be included
+ in all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
+ NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+ DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+ OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+ USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <sys/types.h>
@@ -12,36 +40,46 @@
#include <unistd.h>
#ifndef MAP_FILE
-#define MAP_FILE 0
+# 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),
- void *arg)
-{
+filemap(const tchar *name,
+ void (*processor)(const void *, size_t, const tchar *, void *arg),
+ void *arg) {
int fd;
size_t nbytes;
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)) {
+ 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) {
+ close(fd);
+ return 2; /* Cannot be passed to XML_Parse in one go */
+ }
nbytes = sb.st_size;
/* mmap fails for zero length files */
@@ -51,10 +89,10 @@ filemap(const char *name,
close(fd);
return 1;
}
- p = (void *)mmap((void *)0, (size_t)nbytes, PROT_READ,
- MAP_FILE|MAP_PRIVATE, fd, (off_t)0);
+ 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;
}