Package: xerces-c / 3.1.1-5.1

hurd-path-max.patch Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
Description: check for PATH_MAX
Bug: https://issues.apache.org/jira/browse/XERCESC-1998
Bug-Debian: http://bugs.debian.org/636568
Origin: upstream, http://svn.apache.org/viewvc/xerces/c/trunk/src/xercesc/util/FileManagers/PosixFileMgr.cpp?r1=673975&r2=1478186&pathrev=1478186&view=patch

Index: xerces-c/src/xercesc/util/FileManagers/PosixFileMgr.cpp
===================================================================
--- xerces-c.orig/src/xercesc/util/FileManagers/PosixFileMgr.cpp	2014-01-08 15:44:25.211067958 -0500
+++ xerces-c/src/xercesc/util/FileManagers/PosixFileMgr.cpp	2014-01-08 15:44:25.207067926 -0500
@@ -19,9 +19,16 @@
  * $Id: PosixFileMgr.cpp 673975 2008-07-04 09:23:56Z borisk $
  */
 
+#include <config.h>
 #include <stdio.h>
+
+#if HAVE_UNISTD_H
 #include <unistd.h>
+#endif
+
+#if HAVE_LIMITS_H
 #include <limits.h>
+#endif
 
 #include <xercesc/util/FileManagers/PosixFileMgr.hpp>
 
@@ -74,7 +81,7 @@
 PosixFileMgr::fileClose(FileHandle f, MemoryManager* const manager)
 {
     if (!f)
-		ThrowXMLwithMemMgr(XMLPlatformUtilsException, XMLExcepts::CPtr_PointerIsZero, manager);
+        ThrowXMLwithMemMgr(XMLPlatformUtilsException, XMLExcepts::CPtr_PointerIsZero, manager);
 
     if (fclose((FILE*)f))
         ThrowXMLwithMemMgr(XMLPlatformUtilsException,
@@ -86,7 +93,7 @@
 PosixFileMgr::fileReset(FileHandle f, MemoryManager* const manager)
 {
     if (!f)
-		ThrowXMLwithMemMgr(XMLPlatformUtilsException, XMLExcepts::CPtr_PointerIsZero, manager);
+        ThrowXMLwithMemMgr(XMLPlatformUtilsException, XMLExcepts::CPtr_PointerIsZero, manager);
 
     // Seek to the start of the file
     if (fseek((FILE*)f, 0, SEEK_SET))
@@ -99,7 +106,7 @@
 PosixFileMgr::curPos(FileHandle f, MemoryManager* const manager)
 {
     if (!f)
-		ThrowXMLwithMemMgr(XMLPlatformUtilsException, XMLExcepts::CPtr_PointerIsZero, manager);
+        ThrowXMLwithMemMgr(XMLPlatformUtilsException, XMLExcepts::CPtr_PointerIsZero, manager);
 		 
     long curPos = ftell((FILE*)f);
 	
@@ -114,7 +121,7 @@
 PosixFileMgr::fileSize(FileHandle f, MemoryManager* const manager)
 {
     if (!f)
-		ThrowXMLwithMemMgr(XMLPlatformUtilsException, XMLExcepts::CPtr_PointerIsZero, manager);
+        ThrowXMLwithMemMgr(XMLPlatformUtilsException, XMLExcepts::CPtr_PointerIsZero, manager);
 		
     // Get the current position
     long curPos = ftell((FILE*)f);
@@ -141,16 +148,16 @@
 PosixFileMgr::fileRead(FileHandle f, XMLSize_t byteCount, XMLByte* buffer, MemoryManager* const manager)
 {
     if (!f || !buffer)
-		ThrowXMLwithMemMgr(XMLPlatformUtilsException, XMLExcepts::CPtr_PointerIsZero, manager);
+        ThrowXMLwithMemMgr(XMLPlatformUtilsException, XMLExcepts::CPtr_PointerIsZero, manager);
 		
     XMLSize_t bytesRead = 0;
-	if (byteCount > 0)
-	{
-    	bytesRead = fread((void*)buffer, 1, byteCount, (FILE*)f);
-
-		if (ferror((FILE*)f))
-			ThrowXMLwithMemMgr(XMLPlatformUtilsException, XMLExcepts::File_CouldNotReadFromFile, manager);
-	}
+    if (byteCount > 0)
+    {
+        bytesRead = fread((void*)buffer, 1, byteCount, (FILE*)f);
+
+        if (ferror((FILE*)f))
+            ThrowXMLwithMemMgr(XMLPlatformUtilsException, XMLExcepts::File_CouldNotReadFromFile, manager);
+    }
 	
     return bytesRead;
 }
@@ -160,17 +167,17 @@
 PosixFileMgr::fileWrite(FileHandle f, XMLSize_t byteCount, const XMLByte* buffer, MemoryManager* const manager)
 {
     if (!f || !buffer)
-		ThrowXMLwithMemMgr(XMLPlatformUtilsException, XMLExcepts::CPtr_PointerIsZero, manager);
+        ThrowXMLwithMemMgr(XMLPlatformUtilsException, XMLExcepts::CPtr_PointerIsZero, manager);
 
     while (byteCount > 0)
     {
         XMLSize_t bytesWritten = fwrite(buffer, sizeof(XMLByte), byteCount, (FILE*)f);
 
         if (ferror((FILE*)f))
-			ThrowXMLwithMemMgr(XMLPlatformUtilsException, XMLExcepts::File_CouldNotWriteToFile, manager);
+            ThrowXMLwithMemMgr(XMLPlatformUtilsException, XMLExcepts::File_CouldNotWriteToFile, manager);
 
-		buffer		+= bytesWritten;
-		byteCount	-= bytesWritten;
+        buffer		+= bytesWritten;
+        byteCount	-= bytesWritten;
     }
 }
 
@@ -186,28 +193,47 @@
     char* newSrc = XMLString::transcode(srcPath, manager);
     ArrayJanitor<char> janText(newSrc, manager);
 
+#if HAVE_PATH_MAX
     // Use a local buffer that is big enough for the largest legal path
     char absPath[PATH_MAX + 1];
     
     // get the absolute path
     if (!realpath(newSrc, absPath))
-   		ThrowXMLwithMemMgr(XMLPlatformUtilsException, XMLExcepts::File_CouldNotGetBasePathName, manager);
+        ThrowXMLwithMemMgr(XMLPlatformUtilsException, XMLExcepts::File_CouldNotGetBasePathName, manager);
 
-    return XMLString::transcode(absPath, manager);
+    XMLCh* ret = XMLString::transcode(absPath, manager);
+#else
+    // get the absolute path
+    char *absPath = realpath(newSrc, NULL);
+    if(!absPath)
+        ThrowXMLwithMemMgr(XMLPlatformUtilsException, XMLExcepts::File_CouldNotGetBasePathName, manager);
+
+    XMLCh* ret = XMLString::transcode(absPath, manager);
+    free(absPath);
+#endif
+    return ret;
 }
 
 
 XMLCh*
 PosixFileMgr::getCurrentDirectory(MemoryManager* const manager)
 {
+#if HAVE_PATH_MAX
     char dirBuf[PATH_MAX + 2];
     char *curDir = getcwd(&dirBuf[0], PATH_MAX + 1);
+#else
+    char *curDir = getcwd(NULL, 0);
+#endif
 
     if (!curDir)
         ThrowXMLwithMemMgr(XMLPlatformUtilsException,
                  XMLExcepts::File_CouldNotGetBasePathName, manager);
 
-    return XMLString::transcode(curDir, manager);
+    XMLCh* ret = XMLString::transcode(curDir, manager);
+#if !HAVE_PATH_MAX
+    free(curDir);
+#endif
+    return ret;
 }