33 lines
757 B
C++
33 lines
757 B
C++
|
/*
|
||
|
Copyright (c) 2013 Microsoft Corporation. All rights reserved.
|
||
|
Released under Apache 2.0 license as described in the file LICENSE.
|
||
|
|
||
|
Author: Leonardo de Moura
|
||
|
*/
|
||
|
#include <iostream>
|
||
|
#include <cstdlib>
|
||
|
#include "util/realpath.h"
|
||
|
#ifdef LEAN_WINDOWS
|
||
|
#include <windows.h>
|
||
|
#endif
|
||
|
|
||
|
namespace lean {
|
||
|
std::string realpath(char const * fname) {
|
||
|
#ifdef LEAN_WINDOWS
|
||
|
constexpr unsigned buffer_size = 8192;
|
||
|
char buffer[buffer_size];
|
||
|
DWORD retval = GetFullPathName(fname, buffer_size, buffer, nullptr);
|
||
|
if (retval == 0 || retval > buffer_size) {
|
||
|
return std::string(fname);
|
||
|
} else {
|
||
|
return std::string(buffer);
|
||
|
}
|
||
|
#else
|
||
|
char * tmp = ::realpath(fname, nullptr);
|
||
|
std::string r(tmp);
|
||
|
free(tmp);
|
||
|
return r;
|
||
|
#endif
|
||
|
}
|
||
|
}
|