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
|
/*****************************************************************************/
/* XDMF */
/* eXtensible Data Model and Format */
/* */
/* Id : XdmfSystemUtils.cpp */
/* */
/* Author: */
/* Kenneth Leiter */
/* kenneth.leiter@arl.army.mil */
/* US Army Research Laboratory */
/* Aberdeen Proving Ground, MD */
/* */
/* Copyright @ 2011 US Army Research Laboratory */
/* All Rights Reserved */
/* See Copyright.txt for details */
/* */
/* This software is distributed WITHOUT ANY WARRANTY; without */
/* even the implied warranty of MERCHANTABILITY or FITNESS */
/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
/* for more information. */
/* */
/*****************************************************************************/
#include <libxml/uri.h>
#include <limits.h>
#include <stdlib.h>
#include "XdmfSystemUtils.hpp"
#include "XdmfCoreConfig.hpp"
#include <iostream>
#include "string.h"
XdmfSystemUtils::XdmfSystemUtils()
{
}
XdmfSystemUtils::~XdmfSystemUtils()
{
}
#ifdef XDMF_NO_REALPATH
//allows symbolic links
std::string
XdmfSystemUtils::getRealPath(const std::string & path)
{
return path;
}
#else
std::string
XdmfSystemUtils::getRealPath(const std::string & path)
{
xmlURIPtr ref = NULL;
ref = xmlCreateURI();
xmlParseURIReference(ref, path.c_str());
#ifdef WIN32
char realPath[_MAX_PATH];
_fullpath(realPath, path.c_str(), _MAX_PATH);
xmlFreeURI(ref);
return realPath;
#else
char realPath[PATH_MAX];
char *rp = realpath(ref->path, realPath);
if (rp == 0)
{
//indicates a failure that we are silently ignoring
//TODO: realPath is now undefined but in practice
//ends up path.c_str()
rp = realPath;
}
xmlFreeURI(ref);
return std::string(rp);
#endif
}
#endif
char * XdmfSystemUtilsGetRealPath(char * path)
{
std::string returnstring = XdmfSystemUtils::getRealPath(std::string(path));
char * returnPointer = strdup(returnstring.c_str());
return returnPointer;
}
|