From e5009da0f97af971aa41ff22d6fc2dc130bdb60c Mon Sep 17 00:00:00 2001 From: Satoshi Asami Date: Tue, 5 Mar 1996 07:43:40 +0000 Subject: [PATCH] Make xargs take into account the bytes occupied by the environment. Original by: peter --- usr.bin/xargs/xargs.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/usr.bin/xargs/xargs.c b/usr.bin/xargs/xargs.c index e28e840ce91b..4d8c07159c85 100644 --- a/usr.bin/xargs/xargs.c +++ b/usr.bin/xargs/xargs.c @@ -60,14 +60,14 @@ void err __P((const char *, ...)); void run __P((char **)); void usage __P((void)); -main(argc, argv) +main(argc, argv, env) int argc; - char **argv; + char **argv, **env; { register int ch; register char *p, *bbp, *ebp, **bxp, **exp, **xp; int cnt, indouble, insingle, nargs, nflag, nline, xflag; - char **av, *argp; + char **av, *argp, **ep = env; /* * POSIX.2 limits the exec line length to ARG_MAX - 2K. Running that @@ -84,6 +84,10 @@ main(argc, argv) */ nargs = 5000; nline = ARG_MAX - 4 * 1024; + while (*ep) { + /* 1 byte for each '\0' */ + nline -= strlen(*ep++) + 1 + sizeof(*ep); + } nflag = xflag = 0; while ((ch = getopt(argc, argv, "n:s:tx")) != EOF) switch(ch) {