Author: scantor
Date: Sat Feb 28 02:00:45 2015
New Revision: 1662881

URL: http://svn.apache.org/r1662881
Log:
XERCESC-1998

Modified:
    xerces/c/branches/xerces-3.1/configure.ac
    xerces/c/branches/xerces-3.1/src/xercesc/util/FileManagers/PosixFileMgr.cpp

Modified: xerces/c/branches/xerces-3.1/configure.ac
URL: 
http://svn.apache.org/viewvc/xerces/c/branches/xerces-3.1/configure.ac?rev=1662881&r1=1662880&r2=1662881&view=diff
==============================================================================
--- xerces/c/branches/xerces-3.1/configure.ac (original)
+++ xerces/c/branches/xerces-3.1/configure.ac Sat Feb 28 02:00:45 2015
@@ -24,7 +24,7 @@
 #
 
 AC_PREREQ(2.60)
-AC_INIT([xerces-c],[3.1.1])
+AC_INIT([xerces-c],[3.1.2])
 AC_CONFIG_SRCDIR([src/Makefile.am])
 AC_CONFIG_LIBOBJ_DIR([src])
 AC_CONFIG_AUX_DIR([config])
@@ -141,6 +141,20 @@ AC_CHECK_FUNCS([getcwd pathconf realpath
         wcsupr wcslwr wcsnicmp wcsicmp \
                ])
 
+# Some Unix systems, like Gnu Hurd, don't define PATH_MAX
+AC_MSG_CHECKING([for PATH_MAX])
+AC_COMPILE_IFELSE( [AC_LANG_PROGRAM([[#include <limits.h>]],
+                                    [[char dummy[PATH_MAX];]])],
+                   [
+                      AC_MSG_RESULT([yes])
+                      AC_DEFINE_UNQUOTED([HAVE_PATH_MAX], 1, [Define to 1 if 
you have the PATH_MAX macro.])
+                    ],
+                    [
+                      AC_MSG_RESULT([no])
+                      AC_DEFINE_UNQUOTED([HAVE_PATH_MAX], 0, [Define to 1 if 
you have the PATH_MAX macro.])
+                    ]
+                 )
+
 # The check for mbrlen, wcsrtombs and mbsrtowcs gives a false
 # positive on HP-UX, so we use a different snippet to set the
 # corresponding macro

Modified: 
xerces/c/branches/xerces-3.1/src/xercesc/util/FileManagers/PosixFileMgr.cpp
URL: 
http://svn.apache.org/viewvc/xerces/c/branches/xerces-3.1/src/xercesc/util/FileManagers/PosixFileMgr.cpp?rev=1662881&r1=1662880&r2=1662881&view=diff
==============================================================================
--- xerces/c/branches/xerces-3.1/src/xercesc/util/FileManagers/PosixFileMgr.cpp 
(original)
+++ xerces/c/branches/xerces-3.1/src/xercesc/util/FileManagers/PosixFileMgr.cpp 
Sat Feb 28 02:00:45 2015
@@ -19,9 +19,16 @@
  * $Id$
  */
 
+#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 @@ void
 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 @@ void
 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 @@ XMLFilePos
 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 @@ XMLFilePos
 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 @@ XMLSize_t
 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 @@ void
 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 @@ PosixFileMgr::getFullPath(const XMLCh* c
     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;
 }
 
 



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to