From a8059c5962ba5695b3622fe0cf7b5e2eb383db1f Mon Sep 17 00:00:00 2001 From: David Adam Date: Sun, 7 Dec 2014 16:41:15 +0800 Subject: [PATCH 01/10] Solaris build fixes: pick the right curses more of the time --- builtin_set_color.cpp | 5 ++++ common.cpp | 6 +++- configure.ac | 68 ++++++++++++++++++++++++------------------- env.cpp | 5 ++++ fallback.cpp | 5 ++++ input.cpp | 5 ++++ io.cpp | 5 ++++ osx/config.h | 3 ++ output.cpp | 5 ++++ proc.cpp | 5 ++++ reader.cpp | 5 ++++ screen.cpp | 5 ++++ 12 files changed, 91 insertions(+), 31 deletions(-) diff --git a/builtin_set_color.cpp b/builtin_set_color.cpp index b3757e1c3..76efde82b 100644 --- a/builtin_set_color.cpp +++ b/builtin_set_color.cpp @@ -11,8 +11,13 @@ Functions used for implementing the set_color builtin. #if HAVE_NCURSES_H #include +#elif HAVE_NCURSES_CURSES_H +#include #else +// Solaris curses defines lots of unneeded macros which conflict with C++ +#define NOMACROS #include +#undef NOMACROS #endif #if HAVE_TERM_H diff --git a/common.cpp b/common.cpp index ceb323cb2..db0f76e08 100644 --- a/common.cpp +++ b/common.cpp @@ -45,11 +45,15 @@ parts of fish. #include #endif - #if HAVE_NCURSES_H #include +#elif HAVE_NCURSES_CURSES_H +#include #else +// Solaris curses defines lots of unneeded macros which conflict with C++ +#define NOMACROS #include +#undef NOMACROS #endif #if HAVE_TERM_H diff --git a/configure.ac b/configure.ac index 6c0e32e92..a17166364 100644 --- a/configure.ac +++ b/configure.ac @@ -301,35 +301,6 @@ case $target_os in ;; esac -# Check for Solaris curses tputs having fixed length parameter list. -AC_MSG_CHECKING([if we are using non varargs tparm.]) -AC_COMPILE_IFELSE( - [ - AC_LANG_PROGRAM( - [ - #include - #include - ], - [ - tparm( "" ); - ] - ) - ], - [tparm_solaris_kludge=no], - [tparm_solaris_kludge=yes] -) -if test "x$tparm_solaris_kludge" = "xyes"; then - AC_MSG_RESULT(yes) - AC_DEFINE( - [TPARM_SOLARIS_KLUDGE], - [1], - [Define to 1 if tparm accepts a fixed amount of paramters.] - ) -else - AC_MSG_RESULT(no) -fi - - # # BSD-specific flags go here # @@ -390,7 +361,7 @@ fi # Check presense of various header files # -AC_CHECK_HEADERS([getopt.h termios.h sys/resource.h term.h ncurses/term.h ncurses.h curses.h stropts.h siginfo.h sys/select.h sys/ioctl.h execinfo.h spawn.h sys/sysctl.h]) +AC_CHECK_HEADERS([getopt.h termios.h sys/resource.h term.h ncurses/term.h ncurses.h ncurses/curses.h curses.h stropts.h siginfo.h sys/select.h sys/ioctl.h execinfo.h spawn.h sys/sysctl.h]) if test x$local_gettext != xno; then AC_CHECK_HEADERS([libintl.h]) @@ -748,6 +719,43 @@ else AC_MSG_RESULT(no) fi +# Check for Solaris curses tputs having fixed length parameter list. +AC_MSG_CHECKING([if we are using non varargs tparm.]) +AC_COMPILE_IFELSE( + [ + AC_LANG_PROGRAM( + [ + #if HAVE_NCURSES_H + #include + #else + #include + #endif + + #if HAVE_TERM_H + #include + #elif HAVE_NCURSES_TERM_H + #include + #endif + ], + [ + tparm( "" ); + ] + ) + ], + [tparm_solaris_kludge=no], + [tparm_solaris_kludge=yes] +) +if test "x$tparm_solaris_kludge" = "xyes"; then + AC_MSG_RESULT(yes) + AC_DEFINE( + [TPARM_SOLARIS_KLUDGE], + [1], + [Define to 1 if tparm accepts a fixed amount of paramters.] + ) +else + AC_MSG_RESULT(no) +fi + # Tell the world what we know AC_CONFIG_FILES([Makefile]) AC_OUTPUT diff --git a/env.cpp b/env.cpp index 996784558..1e63a335b 100644 --- a/env.cpp +++ b/env.cpp @@ -21,8 +21,13 @@ #if HAVE_NCURSES_H #include +#elif HAVE_NCURSES_CURSES_H +#include #else +// Solaris curses defines lots of unneeded macros which conflict with C++ +#define NOMACROS #include +#undef NOMACROS #endif #if HAVE_TERM_H diff --git a/fallback.cpp b/fallback.cpp index d69d76f4c..1a87a0927 100644 --- a/fallback.cpp +++ b/fallback.cpp @@ -32,8 +32,13 @@ #if HAVE_NCURSES_H #include +#elif HAVE_NCURSES_CURSES_H +#include #else +// Solaris curses defines lots of unneeded macros which conflict with C++ +#define NOMACROS #include +#undef NOMACROS #endif #if HAVE_TERM_H diff --git a/input.cpp b/input.cpp index 8eeb44779..b4e323e95 100644 --- a/input.cpp +++ b/input.cpp @@ -24,8 +24,13 @@ #if HAVE_NCURSES_H #include +#elif HAVE_NCURSES_CURSES_H +#include #else +// Solaris curses defines lots of unneeded macros which conflict with C++ +#define NOMACROS #include +#undef NOMACROS #endif #if HAVE_TERM_H diff --git a/io.cpp b/io.cpp index 57ce43d3c..56cb63b6d 100644 --- a/io.cpp +++ b/io.cpp @@ -24,8 +24,13 @@ Utilities for io redirection. #if HAVE_NCURSES_H #include +#elif HAVE_NCURSES_CURSES_H +#include #else +// Solaris curses defines lots of unneeded macros which conflict with C++ +#define NOMACROS #include +#undef NOMACROS #endif #if HAVE_TERM_H diff --git a/osx/config.h b/osx/config.h index 99f837427..8a29644ae 100644 --- a/osx/config.h +++ b/osx/config.h @@ -61,6 +61,9 @@ /* Define to 1 if you have the nan function */ #define HAVE_NAN 1 +/* Define to 1 if you have the header file. */ +/* #undef HAVE_NCURSES_CURSES_H */ + /* Define to 1 if you have the header file. */ #define HAVE_NCURSES_H 1 diff --git a/output.cpp b/output.cpp index 6144746ab..7be8954d3 100644 --- a/output.cpp +++ b/output.cpp @@ -22,8 +22,13 @@ #if HAVE_NCURSES_H #include +#elif HAVE_NCURSES_CURSES_H +#include #else +// Solaris curses defines lots of unneeded macros which conflict with C++ +#define NOMACROS #include +#undef NOMACROS #endif #if HAVE_TERM_H diff --git a/proc.cpp b/proc.cpp index 1c8b8e6d3..a1a393f3d 100644 --- a/proc.cpp +++ b/proc.cpp @@ -33,8 +33,13 @@ Some of the code in this file is based on code from the Glibc manual. #if HAVE_NCURSES_H #include +#elif HAVE_NCURSES_CURSES_H +#include #else +// Solaris curses defines lots of unneeded macros which conflict with C++ +#define NOMACROS #include +#undef NOMACROS #endif #if HAVE_TERM_H diff --git a/reader.cpp b/reader.cpp index 9e1afd224..07ee5154e 100644 --- a/reader.cpp +++ b/reader.cpp @@ -45,8 +45,13 @@ commence. #if HAVE_NCURSES_H #include +#elif HAVE_NCURSES_CURSES_H +#include #else +// Solaris curses defines lots of unneeded macros which conflict with C++ +#define NOMACROS #include +#undef NOMACROS #endif #if HAVE_TERM_H diff --git a/screen.cpp b/screen.cpp index 36a31f4b0..d4bf02ae4 100644 --- a/screen.cpp +++ b/screen.cpp @@ -20,8 +20,13 @@ efficient way for transforming that to the desired screen content. #if HAVE_NCURSES_H #include +#elif HAVE_NCURSES_CURSES_H +#include #else +// Solaris curses defines lots of unneeded macros which conflict with C++ +#define NOMACROS #include +#undef NOMACROS #endif #if HAVE_TERM_H From 14fde56d32560f4bf983d5036fe53329e0d90ce8 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Mon, 7 Jul 2014 01:37:16 -0700 Subject: [PATCH 02/10] Define some macros to stop Solaris curses headers from breaking the STL --- configure.ac | 3 +++ 1 file changed, 3 insertions(+) diff --git a/configure.ac b/configure.ac index a17166364..9c5c72626 100644 --- a/configure.ac +++ b/configure.ac @@ -337,6 +337,9 @@ AC_DEFINE( [Define to 1 if the wgettext function should be used for translating strings.] ) +# Disable curses macros that conflict with the STL +AC_DEFINE([NCURSES_NOMACROS], [1], [Define to 1 to disable ncurses macros that conflict with the STL]) +AC_DEFINE([NOMACROS], [1], [Define to 1 to disable curses macros that conflict with the STL]) # # Check presense of various libraries. This is done on a per-binary From 1edb7d3aa53454edc13a0ca68c4e1afc074febef Mon Sep 17 00:00:00 2001 From: David Adam Date: Sun, 21 Dec 2014 22:58:16 +0800 Subject: [PATCH 03/10] Update osx/config.h with new configure headers --- osx/config.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/osx/config.h b/osx/config.h index 8a29644ae..d245f1989 100644 --- a/osx/config.h +++ b/osx/config.h @@ -179,6 +179,12 @@ /* Define to 1 if the __environ symbol is exported. */ /* #undef HAVE___ENVIRON */ +/* Define to 1 to disable ncurses macros that conflict with the STL */ +#define NCURSES_NOMACROS 1 + +/* Define to 1 to disable curses macros that conflict with the STL */ +#define NOMACROS 1 + /* Define to the address where bug reports for this package should be sent. */ #define PACKAGE_BUGREPORT "fish-users@lists.sf.net" From 9b43e6fa8b9ab11826370ca6e4c6fa2aac3b486a Mon Sep 17 00:00:00 2001 From: David Adam Date: Thu, 11 Dec 2014 14:14:36 +0800 Subject: [PATCH 04/10] use configure to define NOMACROS (added in 9ec808a4c) --- builtin_set_color.cpp | 3 --- common.cpp | 3 --- env.cpp | 3 --- fallback.cpp | 3 --- input.cpp | 3 --- io.cpp | 3 --- output.cpp | 3 --- proc.cpp | 3 --- reader.cpp | 3 --- screen.cpp | 3 --- 10 files changed, 30 deletions(-) diff --git a/builtin_set_color.cpp b/builtin_set_color.cpp index 76efde82b..36ad70805 100644 --- a/builtin_set_color.cpp +++ b/builtin_set_color.cpp @@ -14,10 +14,7 @@ Functions used for implementing the set_color builtin. #elif HAVE_NCURSES_CURSES_H #include #else -// Solaris curses defines lots of unneeded macros which conflict with C++ -#define NOMACROS #include -#undef NOMACROS #endif #if HAVE_TERM_H diff --git a/common.cpp b/common.cpp index db0f76e08..fcb58bc0b 100644 --- a/common.cpp +++ b/common.cpp @@ -50,10 +50,7 @@ parts of fish. #elif HAVE_NCURSES_CURSES_H #include #else -// Solaris curses defines lots of unneeded macros which conflict with C++ -#define NOMACROS #include -#undef NOMACROS #endif #if HAVE_TERM_H diff --git a/env.cpp b/env.cpp index 1e63a335b..1b1b0d98c 100644 --- a/env.cpp +++ b/env.cpp @@ -24,10 +24,7 @@ #elif HAVE_NCURSES_CURSES_H #include #else -// Solaris curses defines lots of unneeded macros which conflict with C++ -#define NOMACROS #include -#undef NOMACROS #endif #if HAVE_TERM_H diff --git a/fallback.cpp b/fallback.cpp index 1a87a0927..43b954354 100644 --- a/fallback.cpp +++ b/fallback.cpp @@ -35,10 +35,7 @@ #elif HAVE_NCURSES_CURSES_H #include #else -// Solaris curses defines lots of unneeded macros which conflict with C++ -#define NOMACROS #include -#undef NOMACROS #endif #if HAVE_TERM_H diff --git a/input.cpp b/input.cpp index b4e323e95..9e1560cff 100644 --- a/input.cpp +++ b/input.cpp @@ -27,10 +27,7 @@ #elif HAVE_NCURSES_CURSES_H #include #else -// Solaris curses defines lots of unneeded macros which conflict with C++ -#define NOMACROS #include -#undef NOMACROS #endif #if HAVE_TERM_H diff --git a/io.cpp b/io.cpp index 56cb63b6d..7f9d5d445 100644 --- a/io.cpp +++ b/io.cpp @@ -27,10 +27,7 @@ Utilities for io redirection. #elif HAVE_NCURSES_CURSES_H #include #else -// Solaris curses defines lots of unneeded macros which conflict with C++ -#define NOMACROS #include -#undef NOMACROS #endif #if HAVE_TERM_H diff --git a/output.cpp b/output.cpp index 7be8954d3..5a0d221b3 100644 --- a/output.cpp +++ b/output.cpp @@ -25,10 +25,7 @@ #elif HAVE_NCURSES_CURSES_H #include #else -// Solaris curses defines lots of unneeded macros which conflict with C++ -#define NOMACROS #include -#undef NOMACROS #endif #if HAVE_TERM_H diff --git a/proc.cpp b/proc.cpp index a1a393f3d..1c887c62c 100644 --- a/proc.cpp +++ b/proc.cpp @@ -36,10 +36,7 @@ Some of the code in this file is based on code from the Glibc manual. #elif HAVE_NCURSES_CURSES_H #include #else -// Solaris curses defines lots of unneeded macros which conflict with C++ -#define NOMACROS #include -#undef NOMACROS #endif #if HAVE_TERM_H diff --git a/reader.cpp b/reader.cpp index 07ee5154e..ba50cd98c 100644 --- a/reader.cpp +++ b/reader.cpp @@ -48,10 +48,7 @@ commence. #elif HAVE_NCURSES_CURSES_H #include #else -// Solaris curses defines lots of unneeded macros which conflict with C++ -#define NOMACROS #include -#undef NOMACROS #endif #if HAVE_TERM_H diff --git a/screen.cpp b/screen.cpp index d4bf02ae4..8eb514afc 100644 --- a/screen.cpp +++ b/screen.cpp @@ -23,10 +23,7 @@ efficient way for transforming that to the desired screen content. #elif HAVE_NCURSES_CURSES_H #include #else -// Solaris curses defines lots of unneeded macros which conflict with C++ -#define NOMACROS #include -#undef NOMACROS #endif #if HAVE_TERM_H From b9db5553430d8355bab48275727f685c7c42fa66 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Mon, 7 Jul 2014 02:45:30 -0700 Subject: [PATCH 05/10] Support for dirents without d_type (e.g. Solaris) --- wutil.cpp | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/wutil.cpp b/wutil.cpp index 903131983..0c877f36d 100644 --- a/wutil.cpp +++ b/wutil.cpp @@ -77,14 +77,32 @@ bool wreaddir_resolving(DIR *dir, const std::wstring &dir_path, std::wstring &ou if (out_is_dir) { /* The caller cares if this is a directory, so check */ - bool is_dir; + bool is_dir = false; + + /* We may be able to skip stat, if the readdir can tell us the file type directly */ + bool check_with_stat = true; +#if defined(_DIRENT_HAVE_D_TYPE) || __APPLE__ if (d->d_type == DT_DIR) { + /* Known directory */ is_dir = true; + check_with_stat = false; } else if (d->d_type == DT_LNK || d->d_type == DT_UNKNOWN) { /* We want to treat symlinks to directories as directories. Use stat to resolve it. */ + check_with_stat = true; + } + else + { + /* Regular file */ + is_dir = false; + check_with_stat = false; + } +#endif + if (check_with_stat) + { + /* We couldn't determine the file type from the dirent; check by stat'ing it */ cstring fullpath = wcs2string(dir_path); fullpath.push_back('/'); fullpath.append(d->d_name); @@ -98,10 +116,6 @@ bool wreaddir_resolving(DIR *dir, const std::wstring &dir_path, std::wstring &ou is_dir = !!(S_ISDIR(buf.st_mode)); } } - else - { - is_dir = false; - } *out_is_dir = is_dir; } return true; From a10f729ef9f778f09d8e0995f43551b3990daae7 Mon Sep 17 00:00:00 2001 From: David Adam Date: Thu, 11 Dec 2014 15:24:42 +0800 Subject: [PATCH 06/10] use configure to detect dirent.d_type --- configure.ac | 4 ++++ osx/config.h | 18 ++++++++++++++++++ wutil.cpp | 4 ++-- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index 9c5c72626..46b466d0c 100644 --- a/configure.ac +++ b/configure.ac @@ -502,6 +502,10 @@ fi AC_CHECK_MEMBERS([struct stat.st_mtimespec.tv_nsec]) AC_CHECK_MEMBERS([struct stat.st_mtim.tv_nsec]) +# +# Check for D_TYPE in dirent, only on BSD and Linux +# +AC_STRUCT_DIRENT_D_TYPE # # Check for presense of various functions used by fish diff --git a/osx/config.h b/osx/config.h index d245f1989..fde95a19a 100644 --- a/osx/config.h +++ b/osx/config.h @@ -19,6 +19,10 @@ /* Define to 1 if you have the `dcgettext' function. */ /* #undef HAVE_DCGETTEXT */ +/* Define to 1 if you have the header file, and it defines `DIR'. + */ +#define HAVE_DIRENT_H 1 + /* Define to 1 if you have the header file. */ #define HAVE_EXECINFO_H 1 @@ -70,6 +74,9 @@ /* Define to 1 if you have the header file. */ /* #undef HAVE_NCURSES_TERM_H */ +/* Define to 1 if you have the header file, and it defines `DIR'. */ +/* #undef HAVE_NDIR_H */ + /* Define to 1 if realpath accepts null for its second argument. */ #define HAVE_REALPATH_NULL 1 @@ -97,12 +104,23 @@ /* Define to 1 if you have the header file. */ /* #undef HAVE_STROPTS_H */ +/* Define to 1 if `d_type' is a member of `struct dirent'. */ +#define HAVE_STRUCT_DIRENT_D_TYPE 1 + /* Define to 1 if you have the `sysconf' function. */ #define HAVE_SYSCONF 1 +/* Define to 1 if you have the header file, and it defines `DIR'. + */ +/* #undef HAVE_SYS_DIR_H */ + /* Define to 1 if you have the header file. */ #define HAVE_SYS_IOCTL_H 1 +/* Define to 1 if you have the header file, and it defines `DIR'. + */ +/* #undef HAVE_SYS_NDIR_H */ + /* Define to 1 if you have the header file. */ #define HAVE_SYS_RESOURCE_H 1 diff --git a/wutil.cpp b/wutil.cpp index 0c877f36d..52373fc82 100644 --- a/wutil.cpp +++ b/wutil.cpp @@ -81,7 +81,7 @@ bool wreaddir_resolving(DIR *dir, const std::wstring &dir_path, std::wstring &ou /* We may be able to skip stat, if the readdir can tell us the file type directly */ bool check_with_stat = true; -#if defined(_DIRENT_HAVE_D_TYPE) || __APPLE__ +#ifdef HAVE_STRUCT_DIRENT_D_TYPE if (d->d_type == DT_DIR) { /* Known directory */ @@ -99,7 +99,7 @@ bool wreaddir_resolving(DIR *dir, const std::wstring &dir_path, std::wstring &ou is_dir = false; check_with_stat = false; } -#endif +#endif // HAVE_STRUCT_DIRENT_D_TYPE if (check_with_stat) { /* We couldn't determine the file type from the dirent; check by stat'ing it */ From 11bece80a83eafeb436eae87aa5d6e8c88e47691 Mon Sep 17 00:00:00 2001 From: David Adam Date: Mon, 8 Dec 2014 11:48:28 +0800 Subject: [PATCH 07/10] Solaris build fixes: fallback to _XOPEN_NAME_MAX if defined --- env_universal_common.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/env_universal_common.cpp b/env_universal_common.cpp index f9adb4acd..15c1524d8 100644 --- a/env_universal_common.cpp +++ b/env_universal_common.cpp @@ -36,6 +36,13 @@ #include #endif +// 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 */ From 9cec0ad02c056c8c22b61847833fe6b27b7badda Mon Sep 17 00:00:00 2001 From: David Adam Date: Mon, 8 Dec 2014 14:17:44 +0800 Subject: [PATCH 08/10] Solaris build fixes: use memset instead of bzero --- color.cpp | 8 ++++---- common.cpp | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/color.cpp b/color.cpp index 64beaa20e..e570b1bc8 100644 --- a/color.cpp +++ b/color.cpp @@ -6,7 +6,7 @@ bool rgb_color_t::try_parse_special(const wcstring &special) { - bzero(&data, sizeof data); + memset(&data, 0, sizeof data); const wchar_t *name = special.c_str(); if (! wcscasecmp(name, L"normal")) { @@ -102,7 +102,7 @@ static unsigned char convert_color(const unsigned char rgb[3], const uint32_t *c bool rgb_color_t::try_parse_rgb(const wcstring &name) { - bzero(&data, sizeof data); + memset(&data, 0, sizeof data); /* We support the following style of rgb formats (case insensitive): #FA3 #F3A035 @@ -184,7 +184,7 @@ wcstring_list_t rgb_color_t::named_color_names(void) bool rgb_color_t::try_parse_named(const wcstring &str) { - bzero(&data, sizeof data); + memset(&data, 0, sizeof data); size_t max = sizeof named_colors / sizeof *named_colors; for (size_t idx=0; idx < max; idx++) { @@ -333,7 +333,7 @@ void rgb_color_t::parse(const wcstring &str) if (! success) success = try_parse_rgb(str); if (! success) { - bzero(&this->data, sizeof this->data); + memset(&this->data, 0, sizeof this->data); this->type = type_none; } } diff --git a/common.cpp b/common.cpp index fcb58bc0b..c6fa91298 100644 --- a/common.cpp +++ b/common.cpp @@ -217,14 +217,14 @@ static wcstring str2wcs_internal(const char *in, const size_t in_len) wc = ENCODE_DIRECT_BASE + (unsigned char)in[in_pos]; result.push_back(wc); in_pos++; - bzero(&state, sizeof state); + memset(&state, 0, sizeof state); } else if (ret == 0) { /* Embedded null byte! */ result.push_back(L'\0'); in_pos++; - bzero(&state, sizeof state); + memset(&state, 0, sizeof state); } else { @@ -315,7 +315,7 @@ std::string wcs2string(const wcstring &input) } else { - bzero(converted, sizeof converted); + memset(converted, 0, sizeof converted); size_t len = wcrtomb(converted, wc, &state); if (len == (size_t)(-1)) { @@ -1996,7 +1996,7 @@ void format_size_safe(char buff[128], unsigned long long sz) { const size_t buff_size = 128; const size_t max_len = buff_size - 1; //need to leave room for a null terminator - bzero(buff, buff_size); + memset(buff, 0, buff_size); size_t idx = 0; const char * const sz_name[]= { From 90629caa61b605c403aa33c1e3d7bdd2d7b6cb6b Mon Sep 17 00:00:00 2001 From: David Adam Date: Mon, 8 Dec 2014 14:38:49 +0800 Subject: [PATCH 09/10] Solaris build fixes: detect in configure The header is already used appropriately in the code. --- configure.ac | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/configure.ac b/configure.ac index 46b466d0c..99a12cd4c 100644 --- a/configure.ac +++ b/configure.ac @@ -450,6 +450,10 @@ for i in "" "-D_POSIX_C_SOURCE=200112L" "-D_XOPEN_SOURCE=600 -D_POSIX_C_SOURCE=2 /* As above (under at least Linux and FreeBSD). */ #include #endif + + #ifdef HAVE_TERMIOS_H + #include + #endif ], [ /* Avert high-level optimisation, by making the program's From 147078f43db61e75301a80a0d2eb182c945e9e74 Mon Sep 17 00:00:00 2001 From: David Adam Date: Mon, 8 Dec 2014 08:43:38 +0800 Subject: [PATCH 10/10] Solaris build fixes: use _sys_errs if available --- configure.ac | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ osx/config.h | 6 ++++++ wutil.cpp | 14 ++++++++++++-- 3 files changed, 68 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index 99a12cd4c..cba178477 100644 --- a/configure.ac +++ b/configure.ac @@ -694,6 +694,56 @@ else AC_MSG_RESULT(no) fi +# Check for sys_errlist +AC_MSG_CHECKING([for sys_errlist array]) +AC_TRY_LINK( + [ + #include + ], + [ + const char *p; + p = sys_errlist[sys_nerr]; + ], + have_sys_errlist=yes, + have_sys_errlist=no +) +if test "$have_sys_errlist" = yes; then + AC_MSG_RESULT(yes) + AC_DEFINE( + [HAVE_SYS_ERRLIST], + [1], + [Define to 1 if the sys_errlist array is available.] + ) +else + AC_MSG_RESULT(no) +fi + +# Check for _sys_errs +AC_MSG_CHECKING([for _sys_errs array]) +AC_TRY_LINK( + [ + #include + ], + [ + std::string p; + extern const char _sys_errs[]; + extern const int _sys_index[]; + p = _sys_errs[_sys_index[0]]; + ], + have__sys__errs=yes, + have__sys__errs=no +) +if test "$have__sys__errs" = yes; then + AC_MSG_RESULT(yes) + AC_DEFINE( + [HAVE__SYS__ERRS], + [1], + [Define to 1 if the _sys_errs array is available.] + ) +else + AC_MSG_RESULT(no) +fi + # Check if getopt_long exists and works AC_MSG_CHECKING([if getopt_long exists and works]) AC_TRY_LINK( diff --git a/osx/config.h b/osx/config.h index fde95a19a..3206701c0 100644 --- a/osx/config.h +++ b/osx/config.h @@ -114,6 +114,9 @@ */ /* #undef HAVE_SYS_DIR_H */ +/* Define to 1 if the sys_errlist array is available. */ +#define HAVE_SYS_ERRLIST 1 + /* Define to 1 if you have the header file. */ #define HAVE_SYS_IOCTL_H 1 @@ -194,6 +197,9 @@ /* Define to 1 if you have the file `/proc/self/stat'. */ /* #undef HAVE__PROC_SELF_STAT */ +/* Define to 1 if the _sys_errs array is available. */ +/* #undef HAVE__SYS__ERRS */ + /* Define to 1 if the __environ symbol is exported. */ /* #undef HAVE___ENVIRON */ diff --git a/wutil.cpp b/wutil.cpp index 52373fc82..41400e98f 100644 --- a/wutil.cpp +++ b/wutil.cpp @@ -323,12 +323,23 @@ const char *safe_strerror(int err) // uClibc does not have sys_errlist, however, its strerror is believed to be async-safe // See #808 return strerror(err); -#else +#elif defined(HAVE__SYS__ERRS) || defined(HAVE_SYS_ERRLIST) +#ifdef HAVE_SYS_ERRLIST if (err >= 0 && err < sys_nerr && sys_errlist[err] != NULL) { return sys_errlist[err]; } +#elif defined(HAVE__SYS__ERRS) + extern const char _sys_errs[]; + extern const int _sys_index[]; + extern int _sys_num_err; + + if (err >= 0 && err < _sys_num_err) { + return &_sys_errs[_sys_index[err]]; + } +#endif // either HAVE__SYS__ERRS or HAVE_SYS_ERRLIST else +#endif // defined(HAVE__SYS__ERRS) || defined(HAVE_SYS_ERRLIST) { int saved_err = errno; @@ -345,7 +356,6 @@ const char *safe_strerror(int err) errno = saved_err; return buff; } -#endif } void safe_perror(const char *message)