diff options
Diffstat (limited to 'cpp/src/XMLTransform/XMLTransform.cpp')
-rw-r--r-- | cpp/src/XMLTransform/XMLTransform.cpp | 50 |
1 files changed, 32 insertions, 18 deletions
diff --git a/cpp/src/XMLTransform/XMLTransform.cpp b/cpp/src/XMLTransform/XMLTransform.cpp index c5e20e1b444..4a7e4171c4a 100644 --- a/cpp/src/XMLTransform/XMLTransform.cpp +++ b/cpp/src/XMLTransform/XMLTransform.cpp @@ -12,6 +12,11 @@ // // ********************************************************************** +// For readdir_r +#ifdef __sun +#define _POSIX_PTHREAD_SEMANTICS +#endif + #include <IceUtil/InputUtil.h> #include <Ice/Ice.h> #include <XMLTransform/XMLTransform.h> @@ -1386,8 +1391,10 @@ public: void create(ICE_XERCES_NS DOMDocument*, ICE_XERCES_NS DOMDocument*, const Ice::StringSeq&, const Ice::StringSeq&, const Ice::StringSeq&, const Ice::StringSeq&, TransformMap*, TransformMap*); -private: + + // COMPILERBUG: Should be private but with Sun C++ 5.4, can't use Type in + // StringTypeTable below unless it's public. enum Type { TypeBoolean, @@ -1405,6 +1412,8 @@ private: TypeInternal }; +private: + // // Load all schemas in a list of directories. // @@ -1623,8 +1632,8 @@ XMLTransform::TransformFactory::create(ICE_XERCES_NS DOMDocument* fromDoc, ICE_X assert(toSchema); DocumentInfoPtr toInfo = new DocumentInfo(toDoc, false, toSchema); - _fromDocs.insert(make_pair(fromInfo->getTargetNamespace(), fromInfo)); - _toDocs.insert(make_pair(toInfo->getTargetNamespace(), toInfo)); + _fromDocs.insert(pair<const string, DocumentInfoPtr>(fromInfo->getTargetNamespace(), fromInfo)); + _toDocs.insert(pair<const string, DocumentInfoPtr>(toInfo->getTargetNamespace(), toInfo)); // // Process the import/include declarations for the source schema documents. @@ -1715,26 +1724,30 @@ XMLTransform::TransformFactory::load(DocumentMap& documents, set<string>& import #else - struct dirent **namelist; - int n = ::scandir(path.c_str(), &namelist, 0, alphasort); - if(n < 0) - { - InvalidSchema ex(__FILE__, __LINE__); + DIR* dir = opendir(path.c_str()); + + if (dir == 0) + { + InvalidSchema ex(__FILE__, __LINE__); ex.reason = "cannot read directory `" + path + "': " + strerror(errno); throw ex; - } + } + + + // TODO: make the allocation/deallocation exception-safe + struct dirent* entry = static_cast<struct dirent*>(malloc(pathconf(path.c_str(), _PC_NAME_MAX) + 1)); - for(int i = 0; i < n; ++i) - { - string name = namelist[i]->d_name; + while(readdir_r(dir, entry, &entry) == 0 && entry != 0) + { + string name = entry->d_name; assert(!name.empty()); - free(namelist[i]); - struct stat buf; string fullPath = path + '/' + name; if(::stat(fullPath.c_str(), &buf) == -1) { + free(entry); + closedir(dir); InvalidSchema ex(__FILE__, __LINE__); ex.reason = "cannot stat `" + fullPath + "': " + strerror(errno); throw ex; @@ -1752,8 +1765,9 @@ XMLTransform::TransformFactory::load(DocumentMap& documents, set<string>& import import(documents, importedFiles, "", fullPath, paths); } } - - free(namelist); + + free(entry); + closedir(dir); #endif } @@ -1830,7 +1844,7 @@ XMLTransform::TransformFactory::import(DocumentMap& documents, set<string>& impo parser.adoptDocument(); DocumentInfoPtr info = new DocumentInfo(document, true, schema, ns); - documents.insert(make_pair(info->getTargetNamespace(), info)); + documents.insert(pair<const string, DocumentInfoPtr>(info->getTargetNamespace(), info)); // // Add the file to the list of imported files. @@ -2277,7 +2291,7 @@ XMLTransform::TransformFactory::createTransform(const DocumentInfoPtr& fromTypeI if(_staticClassTransforms->find(type) == _staticClassTransforms->end()) { StructTransform* st = new StructTransform; - _staticClassTransforms->insert(make_pair(type, st)); + _staticClassTransforms->insert(pair<const string, TransformPtr>(type, st)); vector<ElementTransformPtr> v; createClassContentTransform(fromInfo, from, toInfo, to, v); |