|
|
@ -1,30 +1,31 @@
|
|
|
|
/* Copyright (c) 2014, Pollard Banknote Limited
|
|
|
|
/* Copyright (c) 2014, Pollard Banknote Limited
|
|
|
|
All rights reserved.
|
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without modification,
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
are permitted provided that the following conditions are met:
|
|
|
|
modification, are permitted provided that the following conditions are met:
|
|
|
|
|
|
|
|
|
|
|
|
1. Redistributions of source code must retain the above copyright notice, this
|
|
|
|
1. Redistributions of source code must retain the above copyright notice,
|
|
|
|
list of conditions and the following disclaimer.
|
|
|
|
this list of conditions and the following disclaimer.
|
|
|
|
|
|
|
|
|
|
|
|
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
this list of conditions and the following disclaimer in the documentation and/or
|
|
|
|
this list of conditions and the following disclaimer in the documentation
|
|
|
|
other materials provided with the distribution.
|
|
|
|
and/or other materials provided with the distribution.
|
|
|
|
|
|
|
|
|
|
|
|
3. Neither the name of the copyright holder nor the names of its contributors
|
|
|
|
3. Neither the name of the copyright holder nor the names of its contributors
|
|
|
|
may be used to endorse or promote products derived from this software without
|
|
|
|
may be used to endorse or promote products derived from this software without
|
|
|
|
specific prior written permission.
|
|
|
|
specific prior written permission.
|
|
|
|
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
|
|
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
|
|
|
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
|
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
|
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
|
|
|
|
POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
#include "absolute.h"
|
|
|
|
#include "absolute.h"
|
|
|
|
|
|
|
|
|
|
|
@ -35,18 +36,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
namespace cpp17
|
|
|
|
namespace cpp17
|
|
|
|
{
|
|
|
|
{
|
|
|
|
namespace filesystem
|
|
|
|
namespace filesystem
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
path absolute(const path& filename)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if ( !filename.empty() )
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
#if (( defined( _POSIX_VERSION ) && _POSIX_VERSION >= 200809l ) || defined( __GLIBC__ ))
|
|
|
|
path
|
|
|
|
|
|
|
|
absolute(const path& filename)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if(!filename.empty())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
#if((defined(_POSIX_VERSION) && _POSIX_VERSION >= 200809l) \
|
|
|
|
|
|
|
|
|| defined(__GLIBC__)) \
|
|
|
|
|
|
|
|
|| defined(ANDROID)
|
|
|
|
// Preferred - POSIX-2008 and glibc will allocate the path buffer
|
|
|
|
// Preferred - POSIX-2008 and glibc will allocate the path buffer
|
|
|
|
char* res = ::realpath(filename.c_str(), NULL);
|
|
|
|
char* res = ::realpath(filename.c_str(), NULL);
|
|
|
|
|
|
|
|
|
|
|
|
if ( res )
|
|
|
|
if(res)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
path s = res;
|
|
|
|
path s = res;
|
|
|
|
::free(res);
|
|
|
|
::free(res);
|
|
|
@ -54,12 +57,12 @@ path absolute(const path& filename)
|
|
|
|
return s;
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#else
|
|
|
|
#else
|
|
|
|
#ifdef _GNU_SOURCE
|
|
|
|
#ifdef _GNU_SOURCE
|
|
|
|
// Maybe we can rely on the GNU extension
|
|
|
|
// Maybe we can rely on the GNU extension
|
|
|
|
char* res = ::canonicalize_file_name( filename.c_str() );
|
|
|
|
char* res = ::canonicalize_file_name(filename.c_str());
|
|
|
|
|
|
|
|
|
|
|
|
if ( res )
|
|
|
|
if(res)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
std::string s = res;
|
|
|
|
std::string s = res;
|
|
|
|
::free(res);
|
|
|
|
::free(res);
|
|
|
@ -67,24 +70,27 @@ path absolute(const path& filename)
|
|
|
|
return s;
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#elif ((( defined( _POSIX_VERSION ) && _POSIX_VERSION >= 200112L ) || ( defined( _XOPEN_VERSION ) && _XOPEN_VERSION >= 500 )) && defined( PATH_MAX ))
|
|
|
|
#elif(((defined(_POSIX_VERSION) && _POSIX_VERSION >= 200112L) \
|
|
|
|
/// @todo PATH_MAX may be huge or -1, according to man pages for realpath
|
|
|
|
|| (defined(_XOPEN_VERSION) && _XOPEN_VERSION >= 500)) \
|
|
|
|
|
|
|
|
&& defined(PATH_MAX))
|
|
|
|
|
|
|
|
/// @todo PATH_MAX may be huge or -1, according to man pages for
|
|
|
|
|
|
|
|
/// realpath
|
|
|
|
char resolved[PATH_MAX + 1];
|
|
|
|
char resolved[PATH_MAX + 1];
|
|
|
|
char* res = ::realpath(filename.c_str(), resolved);
|
|
|
|
char* res = ::realpath(filename.c_str(), resolved);
|
|
|
|
|
|
|
|
|
|
|
|
if ( res )
|
|
|
|
if(res)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return resolved;
|
|
|
|
return resolved;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#else
|
|
|
|
#else
|
|
|
|
#error "No way to get absolute file path!"
|
|
|
|
#error "No way to get absolute file path!"
|
|
|
|
#endif // if 1
|
|
|
|
#endif // if 1
|
|
|
|
#endif // if ( defined( _POSIX_VERSION ) && _POSIX_VERSION >= 200809l )
|
|
|
|
#endif // if ( defined( _POSIX_VERSION ) && _POSIX_VERSION >= 200809l )
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return path();
|
|
|
|
return path();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
} // namespace filesystem
|
|
|
|
}
|
|
|
|
} // namespace cpp17
|
|
|
|