From 4a2243135cf2b1182646de13d0a9cd0dd24f0332 Mon Sep 17 00:00:00 2001 From: Enrico Forestieri Date: Mon, 20 Sep 2010 17:53:40 +0000 Subject: [PATCH] Instead of specifically addressing glibc, use NULL as second argument of realpath() when PATH_MAX is not defined in limits.h. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@35466 a592a061-630c-0410-9148-cb99ea01b6c8 --- config/lyxinclude.m4 | 20 ++++++++++++++++++++ configure.ac | 2 ++ src/support/os_unix.cpp | 10 +++++----- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/config/lyxinclude.m4 b/config/lyxinclude.m4 index 05a69d6c8e..c742c2eb25 100644 --- a/config/lyxinclude.m4 +++ b/config/lyxinclude.m4 @@ -571,6 +571,26 @@ do [AC_MSG_RESULT(no)]) done]) +dnl this is used by the macro below to generate a proper config.h.in entry +m4_define([LYX_AH_CHECK_DEF], +[AH_TEMPLATE(AS_TR_CPP(HAVE_DEF_$1), + [Define to 1 if `$1' is defined in `$2'])]) + +dnl Check whether name is defined in header by using it in codesnippet. +dnl Called like LYX_CHECK_DEF(name, header, codesnippet) +dnl Defines HAVE_DEF_{NAME} +AC_DEFUN([LYX_CHECK_DEF], +[LYX_AH_CHECK_DEF($1, $2) + AC_MSG_CHECKING([if $1 is defined by header $2]) + AC_TRY_COMPILE([#include <$2>], [$3], + lyx_have_def_name=yes, + lyx_have_def_name=no) + AC_MSG_RESULT($lyx_have_def_name) + if test "x$lyx_have_def_name" = xyes; then + AC_DEFINE_UNQUOTED(AS_TR_CPP(HAVE_DEF_$1)) + fi +]) + dnl Extract the single digits from PACKAGE_VERSION and make them available. dnl Defines LYX_MAJOR_VERSION, LYX_MINOR_VERSION, LYX_RELEASE_LEVEL, dnl LYX_RELEASE_PATCH (possibly equal to 0), LYX_DIR_VER, and LYX_USERDIR_VER. diff --git a/configure.ac b/configure.ac index c8fac2fca0..2f7680d105 100644 --- a/configure.ac +++ b/configure.ac @@ -183,6 +183,8 @@ AC_TYPE_SIGNAL AC_TYPE_SIZE_T AC_TYPE_UID_T +LYX_CHECK_DEF(PATH_MAX, limits.h, [int n = PATH_MAX;]) + AC_CHECK_FUNCS(chmod close _close fork getpid _getpid lstat mkfifo open _open pclose _pclose popen _popen readlink strerror) # Check the form of mkdir() AC_FUNC_MKDIR diff --git a/src/support/os_unix.cpp b/src/support/os_unix.cpp index 9663d98b64..20a6316fde 100644 --- a/src/support/os_unix.cpp +++ b/src/support/os_unix.cpp @@ -297,15 +297,15 @@ bool autoOpenFile(string const & filename, auto_open_mode const mode) string real_path(string const & path) { -#ifdef __GLIBC__ +#ifdef HAVE_DEF_PATH_MAX + char rpath[PATH_MAX + 1]; + char * result = realpath(path.c_str(), rpath); + return FileName::fromFilesystemEncoding(result ? rpath : path).absFileName(); +#else char * result = realpath(path.c_str(), NULL); string ret = FileName::fromFilesystemEncoding(result ? result : path).absFileName(); free(result); return ret; -#else - char rpath[PATH_MAX + 1]; - char * result = realpath(path.c_str(), rpath); - return FileName::fromFilesystemEncoding(result ? rpath : path).absFileName(); #endif }