Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

PATCH: limited pathconf support



This is meant as a step toward getting rid of dependence on PATH_MAX.
PATH_MAX is still used in several other places for static memory allocation,
so this will need to be made dynamic, and in order to support filesystems
where _PC_PATH_MAX is infinite, reallocation may be necessary.  Of course,
this patch will break on systems where _PC_PATH_MAX is unlimited, so
further checking will be needed if pathconf() returns -1.

I'll refrain from committing this to allow sufficient time for flamage.

Index: configure.in
===================================================================
RCS file: /cvsroot/zsh/zsh/configure.in,v
retrieving revision 1.15
diff -u -r1.15 configure.in
--- configure.in	2000/07/28 09:10:36	1.15
+++ configure.in	2000/08/01 15:41:17
@@ -863,7 +863,8 @@
 	       uname \
 	       signgam \
 	       putenv getenv \
-	       brk sbrk)
+	       brk sbrk \
+              pathconf)
 AC_FUNC_STRCOLL
 
 if test $ac_cv_func_setpgrp = yes; then
Index: Src/Modules/files.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Modules/files.c,v
retrieving revision 1.1.1.9
diff -u -r1.1.1.9 files.c
--- Src/Modules/files.c	1999/12/16 14:26:36	1.1.1.9
+++ Src/Modules/files.c	2000/08/01 15:41:21
@@ -71,6 +71,9 @@
     mode_t oumask = umask(0);
     mode_t mode = 0777 & ~oumask;
     int err = 0;
+#ifdef HAVE_PATHCONF
+    int pathmax = 0;
+#endif
 
     umask(oumask);
     if(ops['m']) {
@@ -91,11 +94,20 @@
 
 	while(ptr > *args + (**args == '/') && *--ptr == '/')
 	    *ptr = 0;
-	if(ztrlen(*args) > PATH_MAX - 1) {
+#ifdef HAVE_PATHCONF
+	if((pathmax = pathconf(*args,_PC_PATH_MAX)) == -1) {
+	  zwarnnam(nam, "%s: %e", *args, errno);
+	  err = 1;
+	  continue;
+	}
+	else if(ztrlen(*args) > pathmax - 1) {
+#else
+	  if(ztrlen(*args) > PATH_MAX - 1) {
+#endif
 	    zwarnnam(nam, "%s: %e", *args, ENAMETOOLONG);
 	    err = 1;
 	    continue;
-	}
+	  }
 	if(ops['p']) {
 	    char *ptr = *args;
 
Index: Src/Modules/parameter.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Modules/parameter.c,v
retrieving revision 1.11
diff -u -r1.11 parameter.c
--- Src/Modules/parameter.c	2000/07/04 10:02:27	1.11
+++ Src/Modules/parameter.c	2000/08/01 15:41:22
@@ -1397,7 +1397,17 @@
 static void
 setpmnameddir(Param pm, char *value)
 {
+#ifdef HAVE_PATHCONF
+    int pathmax = 0;
+
+    pathmax = pathconf(value, _PC_PATH_MAX);
+    if (pathmax == -1) {
+      zwarn("%s: %e", value, errno);
+    }
+    else if (!value || *value != '/' || strlen(value) >= pathmax)
+#else
     if (!value || *value != '/' || strlen(value) >= PATH_MAX)
+#endif
 	zwarn("invalid value: %s", value, 0);
     else
 	adduserdir(pm->nam, value, 0, 1);
@@ -1420,6 +1430,9 @@
 {
     int i;
     HashNode hn, next, hd;
+#ifdef HAVE_PATHCONF
+    int pathmax = 0;
+#endif
 
     if (!ht)
 	return;
@@ -1442,8 +1455,17 @@
 	    v.arr = NULL;
 	    v.pm = (Param) hn;
 
+#ifdef HAVE_PATHCONF
+            if((pathmax = pathconf(val, _PC_PATH_MAX)) == -1)
+                zwarn("%s: %e", val, errno);
+            else
+#endif
 	    if (!(val = getstrvalue(&v)) || *val != '/' ||
+#ifdef HAVE_PATHCONF
 		strlen(val) >= PATH_MAX)
+#else
+                strlen(val) >= pathmax)
+#endif
 		zwarn("invalid value: %s", val, 0);
 	    else
 		adduserdir(hn->nam, val, 0, 1);



Messages sorted by: Reverse Date, Date, Thread, Author