mirror of
https://github.com/google/flatbuffers.git
synced 2026-07-04 19:31:12 +00:00
[C++] Updates real_path to be truly portable (#5787)
* Removes posix definition stat and fseeko are not used. Tested on QNX (GCC 5.4.0) and MinGw * Updates realpath to more modern (2008) version * Removes unix specific headers * Adds detection of strtoll_l as android API < 21 does not provide it * Includes cstdlib and formatting Removes cmakelist alterations as not necessary. Formatting not complete. * Stdlib outside if Stdlib is available on all platforms * Fixes indentation * Adds locale check to android build * Adds missing brace * full names * Removes again, no clue * Updates base to check for locale independent android Cmake already checks for others, also MSC? * Changes to test on available and not requested * Fixes android bad xopen_version define * Removes warning
This commit is contained in:
@@ -46,6 +46,10 @@
|
|||||||
#include <iterator>
|
#include <iterator>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
|
#if defined(__unix__) && !defined(FLATBUFFERS_LOCALE_INDEPENDENT)
|
||||||
|
#include <unistd.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef _STLPORT_VERSION
|
#ifdef _STLPORT_VERSION
|
||||||
#define FLATBUFFERS_CPP98_STL
|
#define FLATBUFFERS_CPP98_STL
|
||||||
#endif
|
#endif
|
||||||
@@ -53,6 +57,10 @@
|
|||||||
#include <functional>
|
#include <functional>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef __ANDROID__
|
||||||
|
#include <android/api-level.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "flatbuffers/stl_emulation.h"
|
#include "flatbuffers/stl_emulation.h"
|
||||||
|
|
||||||
#if defined(__ICCARM__)
|
#if defined(__ICCARM__)
|
||||||
@@ -236,10 +244,8 @@ namespace flatbuffers {
|
|||||||
|
|
||||||
#ifndef FLATBUFFERS_LOCALE_INDEPENDENT
|
#ifndef FLATBUFFERS_LOCALE_INDEPENDENT
|
||||||
// Enable locale independent functions {strtof_l, strtod_l,strtoll_l, strtoull_l}.
|
// Enable locale independent functions {strtof_l, strtod_l,strtoll_l, strtoull_l}.
|
||||||
// They are part of the POSIX-2008 but not part of the C/C++ standard.
|
|
||||||
// GCC/Clang have definition (_XOPEN_SOURCE>=700) if POSIX-2008.
|
|
||||||
#if ((defined(_MSC_VER) && _MSC_VER >= 1800) || \
|
#if ((defined(_MSC_VER) && _MSC_VER >= 1800) || \
|
||||||
(defined(_XOPEN_SOURCE) && (_XOPEN_SOURCE>=700)))
|
(defined(_XOPEN_VERSION) && (_XOPEN_VERSION>=700)) && (!defined(__ANDROID_API__) || (defined(__ANDROID_API__) && (__ANDROID_API__>=21))))
|
||||||
#define FLATBUFFERS_LOCALE_INDEPENDENT 1
|
#define FLATBUFFERS_LOCALE_INDEPENDENT 1
|
||||||
#else
|
#else
|
||||||
#define FLATBUFFERS_LOCALE_INDEPENDENT 0
|
#define FLATBUFFERS_LOCALE_INDEPENDENT 0
|
||||||
|
|||||||
19
src/util.cpp
19
src/util.cpp
@@ -16,7 +16,10 @@
|
|||||||
|
|
||||||
// clang-format off
|
// clang-format off
|
||||||
// Dont't remove `format off`, it prevent reordering of win-includes.
|
// Dont't remove `format off`, it prevent reordering of win-includes.
|
||||||
#define _POSIX_C_SOURCE 200112L // For stat from stat/stat.h and fseeko() (POSIX extensions).
|
|
||||||
|
# define _POSIX_C_SOURCE 200809L
|
||||||
|
# define _XOPEN_SOURCE 700L
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
# ifndef WIN32_LEAN_AND_MEAN
|
# ifndef WIN32_LEAN_AND_MEAN
|
||||||
# define WIN32_LEAN_AND_MEAN
|
# define WIN32_LEAN_AND_MEAN
|
||||||
@@ -31,9 +34,6 @@
|
|||||||
# include <direct.h>
|
# include <direct.h>
|
||||||
# include <winbase.h>
|
# include <winbase.h>
|
||||||
# undef interface // This is also important because of reasons
|
# undef interface // This is also important because of reasons
|
||||||
#else
|
|
||||||
# define _XOPEN_SOURCE 600 // For PATH_MAX from limits.h (SUSv2 extension)
|
|
||||||
# include <limits.h>
|
|
||||||
#endif
|
#endif
|
||||||
// clang-format on
|
// clang-format on
|
||||||
|
|
||||||
@@ -42,6 +42,7 @@
|
|||||||
|
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <clocale>
|
#include <clocale>
|
||||||
|
#include <cstdlib>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
namespace flatbuffers {
|
namespace flatbuffers {
|
||||||
@@ -196,8 +197,14 @@ std::string AbsolutePath(const std::string &filepath) {
|
|||||||
char abs_path[MAX_PATH];
|
char abs_path[MAX_PATH];
|
||||||
return GetFullPathNameA(filepath.c_str(), MAX_PATH, abs_path, nullptr)
|
return GetFullPathNameA(filepath.c_str(), MAX_PATH, abs_path, nullptr)
|
||||||
#else
|
#else
|
||||||
char abs_path[PATH_MAX];
|
char *abs_path_temp = realpath(filepath.c_str(), nullptr);
|
||||||
return realpath(filepath.c_str(), abs_path)
|
bool success = abs_path_temp != nullptr;
|
||||||
|
std::string abs_path;
|
||||||
|
if(success) {
|
||||||
|
abs_path = abs_path_temp;
|
||||||
|
free(abs_path_temp);
|
||||||
|
}
|
||||||
|
return success
|
||||||
#endif
|
#endif
|
||||||
? abs_path
|
? abs_path
|
||||||
: filepath;
|
: filepath;
|
||||||
|
|||||||
Reference in New Issue
Block a user