Charles Levert
2001-Mar-20 06:40 UTC
[2.5.2p1] openbsd-compat/glob.c: ARG_MAX not defined, alternative
Hi. On sparc-sun-sunos4.1.4 (i.e., -DSUNOS4), ARG_MAX is not defined anywhere, although <sys/limits.h> has the following line: #define _POSIX_ARG_MAX 4096 This is more a minimum imposed by POSIX than anything else. The proper solution revolves around this: =======================================================================bash$ cat > x.c #include <unistd.h> #include <stdio.h> int main(int argc, char **argv) { printf("%ld\n", sysconf(_SC_ARG_MAX)); return 0; } ^D bash$ gcc -o x x.c bash$ ./x 1048576 ======================================================================= Charles
Damien Miller
2001-Mar-20 07:18 UTC
[2.5.2p1] openbsd-compat/glob.c: ARG_MAX not defined, alternative
On Tue, 20 Mar 2001, Charles Levert wrote:> Hi. > > On sparc-sun-sunos4.1.4 (i.e., -DSUNOS4), ARG_MAX is not defined > anywhere, although <sys/limits.h> has the following line: > > #define _POSIX_ARG_MAX 4096 > > This is more a minimum imposed by POSIX than anything else. The > proper solution revolves around this:This is a known problem which will be fixed in a p2 release very soon. Until then: Index: openbsd-compat/glob.c ==================================================================RCS file: /var/cvs/openssh/openbsd-compat/glob.c,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- openbsd-compat/glob.c 2001/03/19 19:00:10 1.4 +++ openbsd-compat/glob.c 2001/03/20 04:46:51 1.5 @@ -37,6 +37,18 @@ #include "includes.h" #include <ctype.h> +long +get_arg_max() +{ +#ifdef ARG_MAX + return(ARG_MAX); +#elif defined(HAVE_SYSCONF) && defined(_SC_ARG_MAX) + return(sysconf(_SC_ARG_MAX)); +#else + return(256); /* XXX: arbitrary */ +#endif +} + #if !defined(HAVE_GLOB) || !defined(GLOB_HAS_ALTDIRFUNC) || \ !defined(GLOB_HAS_GL_MATCHC) @@ -689,7 +701,7 @@ pathv[pglob->gl_offs + pglob->gl_pathc] = NULL; if ((pglob->gl_flags & GLOB_LIMIT) && - newsize + *limitp >= ARG_MAX) { + newsize + *limitp >= (u_int) get_arg_max()) { errno = 0; return(GLOB_NOSPACE); } -- | Damien Miller <djm at mindrot.org> \ ``E-mail attachments are the poor man's | http://www.mindrot.org / distributed filesystem'' - Dan Geer