From d1472532d3cd307afcb0dd68f2c4b9fbb5cab4da Mon Sep 17 00:00:00 2001 From: Mahmoud Al-Qudsi Date: Tue, 26 Sep 2017 08:19:33 -0500 Subject: [PATCH] Support building on Solaris 11 Took care of remaining issues preventing fish from building on Solaris. Mainly caused by some assumptions that certain defines are POSIX when they are not (`NAME_MAX`). Moved `NAME_MAX` defines to common.h - for some reason, it was being defined in a cpp file (`env_universal_common.cpp`) even though it is used in multiple source files. Now compiles on Solaris 11 with GNU Make. Still some warnings because fish was written with GNU getopt in mind and the Solaris version doesn't use `const char *` but rather just `char *` for getopt values, but it builds nevertheless. Assuming this closes #3340 (cherry picked from commit ffebe748851fc725dfec44c48bc90cf2ab92b29f) --- src/common.h | 12 ++++++++++++ src/env_universal_common.cpp | 7 ------- src/wutil.cpp | 2 +- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/common.h b/src/common.h index 46953359f..4ea4637df 100644 --- a/src/common.h +++ b/src/common.h @@ -4,6 +4,7 @@ #include "config.h" // IWYU pragma: keep #include +#include #include #include // IWYU pragma: keep #include @@ -89,6 +90,17 @@ typedef std::vector wcstring_list_t; #define INPUT_COMMON_BASE (wchar_t)0xF700 #define INPUT_COMMON_END (INPUT_COMMON_BASE + 64) +// NAME_MAX is not defined on Solaris +#if !defined(NAME_MAX) +#include +#if defined(MAXNAMELEN) +// MAXNAMELEN is defined on Linux, BSD, and Solaris among others +#define NAME_MAX MAXNAMELEN +#else +static_assert(false, "Neither NAME_MAX nor MAXNAMELEN is defined!"); +#endif +#endif + enum escape_string_style_t { STRING_STYLE_SCRIPT, STRING_STYLE_URL, STRING_STYLE_VAR }; // Flags for unescape_string functions. diff --git a/src/env_universal_common.cpp b/src/env_universal_common.cpp index eac8b1e10..86ad085bd 100644 --- a/src/env_universal_common.cpp +++ b/src/env_universal_common.cpp @@ -55,13 +55,6 @@ #include #endif // Haiku -// NAME_MAX is not defined on Solaris and suggests the use of pathconf() -// There is no obvious sensible pathconf() for shared memory and _XPG_NAME_MAX -// seems a reasonable choice. -#if !defined(NAME_MAX) && defined(_XOPEN_NAME_MAX) -#define NAME_MAX _XOPEN_NAME_MAX -#endif - /// The set command. #define SET_STR L"SET" diff --git a/src/wutil.cpp b/src/wutil.cpp index d777555bf..ab5de1d76 100644 --- a/src/wutil.cpp +++ b/src/wutil.cpp @@ -92,7 +92,7 @@ bool wreaddir(DIR *dir, wcstring &out_name) { // long when it should be at least NAME_MAX + 1. union { struct dirent d; - char c[offsetof(struct dirent, d_name) + NAME_MAX + 1]; /* NAME_MAX is POSIX. */ + char c[offsetof(struct dirent, d_name) + NAME_MAX + 1]; } d_u; struct dirent *result = NULL;