[pacman-dev] [PATCH] Detect undefined PATH_MAX
Allan McRae
allan at archlinux.org
Fri Dec 17 20:42:14 EST 2010
POSIX does not require PATH_MAX be defined when there is not actual
limit to its value. This affects HURD based systems. Work around
this by defining PATH_MAX to 4096 (as on Linux) when this is not
defined.
Also, clean up inclusions of limits.h
Signed-off-by: Allan McRae <allan at archlinux.org>
---
We do something like:
#if !defined(PATH_MAX)
#include <limits.h>
#endif
to only include limits.h when necessary, but given any decent
compiler gets rid of unused stuff anyway, I do not think it
necessary.
acinclude.m4 | 16 ++++++++++++++++
configure.ac | 1 +
lib/libalpm/be_sync.c | 1 +
lib/libalpm/db.h | 1 -
lib/libalpm/dload.c | 1 -
lib/libalpm/error.c | 1 -
lib/libalpm/package.c | 1 -
lib/libalpm/sync.c | 1 +
lib/libalpm/trans.c | 1 +
src/util/cleanupdelta.c | 2 ++
src/util/testdb.c | 2 ++
11 files changed, 24 insertions(+), 4 deletions(-)
diff --git a/acinclude.m4 b/acinclude.m4
index 6693da4..7309d73 100644
--- a/acinclude.m4
+++ b/acinclude.m4
@@ -125,3 +125,19 @@ extern int getmntinfo (struct statfs **, int);
[Defined as the filesystem stats type ('statvfs' or 'statfs')])
])
+dnl Checks for PATH_MAX and defines it if not present
+AC_DEFUN([PATH_MAX_DEFINED],
+ [AC_CACHE_CHECK([PATH_MAX defined], path_max_cv_defined,
+ [AC_EGREP_CPP(yes, [[
+#include <limits.h>
+#if defined(PATH_MAX)
+yes
+#endif
+]],
+ [path_max_cv_defined=yes],
+ [path_max_cv_defined=no])]
+ )
+ if test $path_max_cv_defined = no; then
+ AC_DEFINE([PATH_MAX], 4096, [Define if PATH_MAX is undefined by limits.h.])
+ fi
+])
diff --git a/configure.ac b/configure.ac
index 747c8b7..18e8996 100644
--- a/configure.ac
+++ b/configure.ac
@@ -185,6 +185,7 @@ AC_TYPE_SIZE_T
AC_STRUCT_TM
AC_TYPE_UID_T
AC_STRUCT_DIRENT_D_TYPE
+PATH_MAX_DEFINED
# Checks for library functions.
AC_FUNC_FORK
diff --git a/lib/libalpm/be_sync.c b/lib/libalpm/be_sync.c
index b201c00..d5d3a44 100644
--- a/lib/libalpm/be_sync.c
+++ b/lib/libalpm/be_sync.c
@@ -23,6 +23,7 @@
#include <errno.h>
#include <ctype.h>
#include <locale.h>
+#include <limits.h>
/* libarchive */
#include <archive.h>
diff --git a/lib/libalpm/db.h b/lib/libalpm/db.h
index ace366d..10aa164 100644
--- a/lib/libalpm/db.h
+++ b/lib/libalpm/db.h
@@ -23,7 +23,6 @@
#define _ALPM_DB_H
#include "alpm.h"
-#include <limits.h>
#include <time.h>
/* libarchive */
diff --git a/lib/libalpm/dload.c b/lib/libalpm/dload.c
index 1cb24e6..ea7f557 100644
--- a/lib/libalpm/dload.c
+++ b/lib/libalpm/dload.c
@@ -29,7 +29,6 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <signal.h>
-#include <limits.h>
/* the following two are needed on BSD for libfetch */
#if defined(HAVE_SYS_SYSLIMITS_H)
#include <sys/syslimits.h> /* PATH_MAX */
diff --git a/lib/libalpm/error.c b/lib/libalpm/error.c
index 78a7866..d4c296f 100644
--- a/lib/libalpm/error.c
+++ b/lib/libalpm/error.c
@@ -22,7 +22,6 @@
/* TODO: needed for the libfetch stuff, unfortunately- we should kill it */
#include <stdio.h>
-#include <limits.h>
/* the following two are needed on BSD for libfetch */
#if defined(HAVE_SYS_SYSLIMITS_H)
#include <sys/syslimits.h> /* PATH_MAX */
diff --git a/lib/libalpm/package.c b/lib/libalpm/package.c
index 2ea5125..edfb7bd 100644
--- a/lib/libalpm/package.c
+++ b/lib/libalpm/package.c
@@ -25,7 +25,6 @@
#include <stdio.h>
#include <stdlib.h>
-#include <limits.h>
#include <string.h>
#include <ctype.h>
#include <errno.h>
diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c
index 2d0a899..7a1e503 100644
--- a/lib/libalpm/sync.c
+++ b/lib/libalpm/sync.c
@@ -31,6 +31,7 @@
#include <stdint.h> /* intmax_t */
#include <unistd.h>
#include <time.h>
+#include <limits.h>
/* libalpm */
#include "sync.h"
diff --git a/lib/libalpm/trans.c b/lib/libalpm/trans.c
index 5bc2c91..5c13211 100644
--- a/lib/libalpm/trans.c
+++ b/lib/libalpm/trans.c
@@ -31,6 +31,7 @@
#include <sys/stat.h>
#include <sys/statvfs.h>
#include <errno.h>
+#include <limits.h>
/* libalpm */
#include "trans.h"
diff --git a/src/util/cleanupdelta.c b/src/util/cleanupdelta.c
index c1ef18c..2010282 100644
--- a/src/util/cleanupdelta.c
+++ b/src/util/cleanupdelta.c
@@ -17,6 +17,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include "config.h"
+
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
diff --git a/src/util/testdb.c b/src/util/testdb.c
index 28f2b2b..f77583a 100644
--- a/src/util/testdb.c
+++ b/src/util/testdb.c
@@ -17,6 +17,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include "config.h"
+
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
--
1.7.3.3
More information about the pacman-dev
mailing list