You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by ab...@locus.apache.org on 2000/01/14 03:04:43 UTC
cvs commit: xml-xerces/c/src/util/Platforms/Linux LinuxPlatformUtils.cpp
abagchi 00/01/13 18:04:43
Modified: c/src/util/Platforms/Linux LinuxPlatformUtils.cpp
Log:
Introduced getFullPath() and weavePath()
Revision Changes Path
1.5 +130 -18 xml-xerces/c/src/util/Platforms/Linux/LinuxPlatformUtils.cpp
Index: LinuxPlatformUtils.cpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/util/Platforms/Linux/LinuxPlatformUtils.cpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- LinuxPlatformUtils.cpp 1999/12/14 23:53:33 1.4
+++ LinuxPlatformUtils.cpp 2000/01/14 02:04:43 1.5
@@ -56,6 +56,9 @@
/**
* $Log: LinuxPlatformUtils.cpp,v $
+ * Revision 1.5 2000/01/14 02:04:43 abagchi
+ * Introduced getFullPath() and weavePath()
+ *
* Revision 1.4 1999/12/14 23:53:33 rahulj
* Removed the offending Ctrl-M's from the commit message
* logs which was giving packaging problems.
@@ -89,6 +92,10 @@
#include <pthread.h>
#endif
+#ifndef __USE_UNIX98
+ #error __USE_UNIX98 is not defined in your compile settings
+#endif
+
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
@@ -103,7 +110,6 @@
#include <util/XMLString.hpp>
#include <util/XMLUni.hpp>
-
#if defined(XML_USE_ICU_TRANSCODER)
#include <util/Transcoders/ICU/ICUTransService.hpp>
#else
@@ -271,7 +277,114 @@
}
}
+XMLCh* XMLPlatformUtils::weavePaths(const XMLCh* const basePath
+ , const XMLCh* const relativePath)
+
+{
+ // Create a buffer as large as both parts and empty it
+ XMLCh* tmpBuf = new XMLCh[XMLString::stringLen(basePath)
+ + XMLString::stringLen(relativePath)
+ + 2];
+ *tmpBuf = 0;
+
+ //
+ // If we have no base path, then just take the relative path as
+ // is.
+ //
+ if (!basePath)
+ {
+ XMLString::copyString(tmpBuf, relativePath);
+ return tmpBuf;
+ }
+
+ if (!*basePath)
+ {
+ XMLString::copyString(tmpBuf, relativePath);
+ return tmpBuf;
+ }
+
+ const XMLCh* basePtr = basePath + (XMLString::stringLen(basePath) - 1);
+ if ((*basePtr != chForwardSlash)
+ && (*basePtr != chBackSlash))
+ {
+ while ((basePtr >= basePath)
+ && ((*basePtr != chForwardSlash) && (*basePtr != chBackSlash)))
+ {
+ basePtr--;
+ }
+ }
+
+ // There is no relevant base path, so just take the relative part
+ if (basePtr < basePath)
+ {
+ XMLString::copyString(tmpBuf, relativePath);
+ return tmpBuf;
+ }
+
+ // After this, make sure the buffer gets handled if we exit early
+ ArrayJanitor<XMLCh> janBuf(tmpBuf);
+ //
+ // We have some path part, so we need to check to see if we ahve to
+ // weave any of the parts together.
+ //
+ const XMLCh* pathPtr = relativePath;
+ while (true)
+ {
+ // If it does not start with some period, then we are done
+ if (*pathPtr != chPeriod)
+ break;
+
+ unsigned int periodCount = 1;
+ pathPtr++;
+ if (*pathPtr == chPeriod)
+ {
+ pathPtr++;
+ periodCount++;
+ }
+
+ // Has to be followed by a \ or / or the null to mean anything
+ if ((*pathPtr != chForwardSlash) && (*pathPtr != chBackSlash)
+ && *pathPtr)
+ {
+ break;
+ }
+ if (*pathPtr)
+ pathPtr++;
+
+ // If its one period, just eat it, else move backwards in the base
+ if (periodCount == 2)
+ {
+ basePtr--;
+ while ((basePtr >= basePath)
+ && ((*basePtr != chForwardSlash) && (*basePtr != chBackSlash)))
+ {
+ basePtr--;
+ }
+
+ if (basePtr < basePath)
+ {
+ // The base cannot provide enough levels, so its in error
+ // <TBD>
+ }
+ }
+ }
+
+ // Copy the base part up to the base pointer
+ XMLCh* bufPtr = tmpBuf;
+ const XMLCh* tmpPtr = basePath;
+ while (tmpPtr <= basePtr)
+ *bufPtr++ = *tmpPtr++;
+
+ // And then copy on the rest of our path
+ XMLString::copyString(bufPtr, pathPtr);
+
+ // Orphan the buffer and return it
+ janBuf.orphan();
+ return tmpBuf;
+}
+
+
// ---------------------------------------------------------------------------
// XMLPlatformUtils: Private Static Methods
// ---------------------------------------------------------------------------
@@ -504,7 +617,7 @@
}
-XMLCh* XMLPlatformUtils::getBasePath(const XMLCh* const srcPath)
+XMLCh* XMLPlatformUtils::getFullPath(const XMLCh* const srcPath)
{
//
@@ -516,24 +629,18 @@
ArrayJanitor<char> janText(newSrc);
// Use a local buffer that is big enough for the largest legal path
- // Note #1186: dirName() is not thread safe.
- char* tmpPath = dirname(newSrc);
- if (!tmpPath)
+ char *absPath = new char[1024];
+ // get the absolute path
+ char* retPath = realpath(newSrc, absPath);
+ ArrayJanitor<char> janText2(retPath);
+
+ if (!retPath)
{
- ThrowXML(XMLPlatformUtilsException,
- XML4CExcepts::File_CouldNotGetBasePathName);
+ ThrowXML(XMLPlatformUtilsException, XML4CExcepts::File_CouldNotGetBasePathName);
}
-
- char* newXMLString = new char [strlen(tmpPath) +2];
- ArrayJanitor<char> newJanitor(newXMLString);
- strcpy(newXMLString, tmpPath);
- strcat(newXMLString , "/");
-
- // Return a copy of the path, in Unicode format
- return XMLString::transcode(newXMLString);
+ return XMLString::transcode(absPath);
}
-
bool XMLPlatformUtils::isRelative(const XMLCh* const toCheck)
{
// Check for pathological case of empty path
@@ -564,7 +671,7 @@
pthread_mutex_t* mutex = new pthread_mutex_t;
pthread_mutexattr_t* attr = new pthread_mutexattr_t;
pthread_mutexattr_init(attr);
- pthread_mutexattr_setkind_np(attr, PTHREAD_MUTEX_RECURSIVE_NP);
+ pthread_mutexattr_settype(attr, PTHREAD_MUTEX_RECURSIVE_NP);
if (pthread_mutex_init(mutex, attr))
{
ThrowXML(XMLPlatformUtilsException,
@@ -575,7 +682,6 @@
return (void*)(mutex);
}
-
void XMLPlatformUtils::closeMutex(void* const mtxHandle)
{