[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: PATH_MAX
From: |
Jim Meyering |
Subject: |
Re: PATH_MAX |
Date: |
Sun, 12 Aug 2001 20:46:08 +0200 |
User-agent: |
Gnus/5.090004 (Oort Gnus v0.04) Emacs/21.0.105 |
Neal H Walfield <address@hidden> wrote:
> This bug report was verified against v 2.0.11-11 as found in the Debian
> unstable archive and the version marked as 2.0 on ftp.gnu.org. I did
> not see a cvs module on subversions.
>
> Shell utils makes use of the macro PATH_MAX. On the Hurd, this is
> undefined. Happily, shell utils handles this situation by using
> pathconf, however, it does so incorrectly: pathconf returns -1 on the
> Hurd. By definition, this means that there is no system imposed limit
> but shell utils chooses to use 1024 in this case. This is clearly
> a hack and is wrong. Dynamic allocation checking for ENAMETOOLONG,
> etc., should instead be performed.
Thanks for the report.
I've begun fixing that.
Here's the first installment (untested):
* src/pathchk.c (PATH_MAX_FOR): Use pathconf via wrapper.
(NAME_MAX_FOR): Likewise.
Guard the above pathconf-using definitions with `#if HAVE_PATHCONF'
rather than with `#ifdef _POSIX_VERSION'.
(pathconf_wrapper): New function.
(validate_path): Declare length variables to be `long', not `int'.
Adjust corresponding printf-style specs to use %ld.
Would you please give it a try?
Jim
Index: pathchk.c
===================================================================
RCS file: /fetish/shellutils/src/pathchk.c,v
retrieving revision 1.52
diff -u -p -r1.52 pathchk.c
--- pathchk.c 2000/05/07 14:55:48 1.52
+++ pathchk.c 2001/08/12 18:42:50
@@ -1,5 +1,5 @@
/* pathchk -- check whether pathnames are valid or portable
- Copyright (C) 1991-2000 Free Software Foundation, Inc.
+ Copyright (C) 1991-2001 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -43,6 +43,11 @@
#include <getopt.h>
#include <sys/types.h>
+#include <errno.h>
+#ifndef errno
+extern int errno;
+#endif
+
#include "system.h"
#include "error.h"
#include "long-options.h"
@@ -53,15 +58,15 @@
#define AUTHORS "David MacKenzie and Jim Meyering"
-#ifdef _POSIX_VERSION
+#if HAVE_PATHCONF
# ifndef PATH_MAX
-# define PATH_MAX_FOR(p) pathconf ((p), _PC_PATH_MAX)
+# define PATH_MAX_FOR(p) pathconf_wrapper ((p), _PC_PATH_MAX)
# endif /* not PATH_MAX */
# ifndef NAME_MAX
-# define NAME_MAX_FOR(p) pathconf ((p), _PC_NAME_MAX);
+# define NAME_MAX_FOR(p) pathconf_wrapper ((p), _PC_NAME_MAX);
# endif /* not NAME_MAX */
-#else /* not _POSIX_VERSION */
+#else
# include <sys/param.h>
# ifndef PATH_MAX
@@ -80,7 +85,7 @@
# endif /* not MAXNAMLEN */
# endif /* not NAME_MAX */
-#endif /* not _POSIX_VERSION */
+#endif
#ifndef _POSIX_PATH_MAX
# define _POSIX_PATH_MAX 255
@@ -107,6 +112,23 @@ static struct option const longopts[] =
{NULL, 0, NULL, 0}
};
+/* Distinguish between the cases when pathconf fails and when it reports there
+ is no limit (the latter is the case for PATH_MAX on the Hurd). When there
+ is no limit, return LONG_MAX. Otherwise, return pathconf's return value.
*/
+
+static long int
+pathconf_wrapper (const char *filename, int param)
+{
+ long int ret;
+
+ errno = 0;
+ ret = pathconf (filename, param);
+ if (ret < 0 && errno == 0)
+ return LONG_MAX;
+
+ return ret;
+}
+
void
usage (int status)
{
@@ -263,7 +285,7 @@ dir_ok (const char *path)
static int
validate_path (char *path, int portability)
{
- int path_max;
+ long int path_max;
int last_elem; /* Nonzero if checking last element of path. */
int exists IF_LINT (= 0); /* 2 if the path element exists. */
char *slash;
@@ -282,8 +304,8 @@ validate_path (char *path, int portabili
last_elem = 0;
while (1)
{
- int name_max;
- int length; /* Length of partial path being checked. */
+ long int name_max;
+ long int length; /* Length of partial path being checked. */
char *start; /* Start of path element being checked. */
/* Find the end of this element of the path.
@@ -324,7 +346,7 @@ validate_path (char *path, int portabili
name_max = _POSIX_NAME_MAX;
if (length > name_max)
{
- error (0, 0, _("name `%s' has length %d; exceeds limit of %d"),
+ error (0, 0, _("name `%s' has length %ld; exceeds limit of %ld"),
start, length, name_max);
free (parent);
return 1;
@@ -350,7 +372,7 @@ validate_path (char *path, int portabili
free (parent);
if (strlen (path) > (size_t) path_max)
{
- error (0, 0, _("path `%s' has length %d; exceeds limit of %d"),
+ error (0, 0, _("path `%s' has length %d; exceeds limit of %ld"),
path, strlen (path), path_max);
return 1;
}
- PATH_MAX, Neal H Walfield, 2001/08/12
- Re: PATH_MAX,
Jim Meyering <=