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 ffebe74885)
This commit is contained in:
Mahmoud Al-Qudsi 2017-09-26 08:19:33 -05:00
parent 01c5f6eaa8
commit d1472532d3
3 changed files with 13 additions and 8 deletions

View file

@ -4,6 +4,7 @@
#include "config.h" // IWYU pragma: keep
#include <errno.h>
#include <limits.h>
#include <pthread.h>
#include <stdarg.h> // IWYU pragma: keep
#include <stddef.h>
@ -89,6 +90,17 @@ typedef std::vector<wcstring> 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 <sys/param.h>
#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.

View file

@ -55,13 +55,6 @@
#include <bsd/ifaddrs.h>
#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"

View file

@ -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;