2013-11-18 17:52:47 +00:00
|
|
|
/*
|
|
|
|
Copyright (c) 2013 Microsoft Corporation. All rights reserved.
|
|
|
|
Released under Apache 2.0 license as described in the file LICENSE.
|
|
|
|
|
|
|
|
Author: Leonardo de Moura
|
|
|
|
*/
|
2014-08-04 22:06:08 +00:00
|
|
|
#if defined(LEAN_CYGWIN)
|
|
|
|
#if defined(__STRICT_ANSI__)
|
|
|
|
// hack for using realpath on cygwin
|
|
|
|
#undef __STRICT_ANSI__
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2013-11-18 17:55:16 +00:00
|
|
|
#include <string>
|
2013-11-18 17:52:47 +00:00
|
|
|
#include <cstdlib>
|
|
|
|
#include "util/realpath.h"
|
2014-08-04 21:42:44 +00:00
|
|
|
|
2014-08-04 21:45:23 +00:00
|
|
|
#if defined(LEAN_WINDOWS) && !defined(LEAN_CYGWIN)
|
2013-11-18 17:52:47 +00:00
|
|
|
#include <windows.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
namespace lean {
|
2014-08-04 21:42:44 +00:00
|
|
|
std::string lrealpath(char const * fname) {
|
2014-08-04 21:45:23 +00:00
|
|
|
#if defined(LEAN_WINDOWS) && !defined(LEAN_CYGWIN)
|
2013-11-18 17:55:16 +00:00
|
|
|
constexpr unsigned BufferSize = 8192;
|
|
|
|
char buffer[BufferSize];
|
|
|
|
DWORD retval = GetFullPathName(fname, BufferSize, buffer, nullptr);
|
|
|
|
if (retval == 0 || retval > BufferSize) {
|
2013-11-18 17:52:47 +00:00
|
|
|
return std::string(fname);
|
|
|
|
} else {
|
|
|
|
return std::string(buffer);
|
|
|
|
}
|
|
|
|
#else
|
2014-08-04 21:42:44 +00:00
|
|
|
char * tmp = realpath(fname, nullptr);
|
2013-11-18 17:52:47 +00:00
|
|
|
std::string r(tmp);
|
|
|
|
free(tmp);
|
|
|
|
return r;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|