Imported Upstream version 4.5.14
[platform/upstream/findutils.git] / lib / buildcmd.c
index 44adb41..2616ed6 100644 (file)
@@ -1,6 +1,6 @@
 /* buildcmd.c -- build command lines from a list of arguments.
-   Copyright (C) 1990, 91, 92, 93, 94, 2000, 2003, 2005, 2006,
-                 2007, 2008, 2010 Free Software Foundation, Inc.
+   Copyright (C) 1990, 1991, 1992, 1993, 1994, 2000, 2003, 2005, 2006,
+   2007, 2008, 2010, 2011 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
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
-
+/* config.h must be included first. */
 #include <config.h>
 
+/* system headers. */
+#include <assert.h>
+#include <errno.h>
+#include <error.h>
+#include <limits.h>
+#include <locale.h>
+#include <openat.h>
+#include <stdbool.h>
 #include <stdlib.h>
 #include <string.h>
+#ifndef _POSIX_SOURCE
+# include <sys/param.h>
+#endif
+#include <unistd.h>
 #include <wchar.h>
-#include <locale.h>
-#include <stdbool.h>
+#include <xalloc.h>
+
+/* gnulib headers. */
+#include "gettext.h"
+#include "xstrtol.h"
+
+/* find headers. */
+#include "buildcmd.h"
 
 #if ENABLE_NLS
 # include <libintl.h>
 # define N_(String) String
 #endif
 
-#ifndef _POSIX_SOURCE
-#include <sys/param.h>
-#endif
-
-#ifdef HAVE_LIMITS_H
-#include <limits.h>
-#endif
-
-/* The presence of unistd.h is assumed by gnulib these days, so we
- * might as well assume it too.
- */
-/* for sysconf() */
-#include <unistd.h>
-
-#include <assert.h>
-
 /* COMPAT:  SYSV version defaults size (and has a max value of) to 470.
    We try to make it as large as possible.  See bc_get_arg_max() below. */
-#if !defined(ARG_MAX) && defined(NCARGS)
-#error "You have an unusual system.  Once you remove this error message from buildcmd.c, it should work, but please make sure that DejaGnu is installed on your system and that 'make check' passes before using the findutils programs"
+#if defined NCARGS && !defined ARG_MAX
+/* We include sys/param.h in order to detect this case. */
+#error "You have an unusual system.  Once you remove this error message from buildcmd.c, it should work, but please make sure that DejaGnu is installed on your system and that 'make check' passes before using the findutils programs.  Please mail bug-findutils@gnu.org to tell us about your system."
 #define ARG_MAX NCARGS
 #endif
 
 
-
-#include <xalloc.h>
-#include <errno.h>
-#include <error.h>
-#include <openat.h>
-
-#include "xstrtol.h"
-#include "buildcmd.h"
-#include "arg-max.h"           /* must include after unistd.h. */
-
-
-extern char **environ;
-
-static char *special_terminating_arg = "do_not_care";
+static const char *special_terminating_arg = "do_not_care";
 
 
 
@@ -374,7 +364,7 @@ bc_push_arg (struct buildcmd_control *ctl,
 
   if (!terminate)
     {
-      if (state->cmd_argv_chars + len > ctl->arg_max)
+      if (state->cmd_argv_chars + len + pfxlen > ctl->arg_max)
         {
           if (initial_args || state->cmd_argc == ctl->initial_argc)
             error (EXIT_FAILURE, 0,
@@ -461,10 +451,9 @@ bc_get_arg_max (void)
    */
 #ifdef ARG_MAX
   val = ARG_MAX;
-#endif
-
   if (val > 0)
     return val;
+#endif
 
   /* The value returned by this function bounds the
    * value applied as the ceiling for the -s option.
@@ -646,9 +635,12 @@ exceeds (const char *env_var_name, size_t quantity)
   return 0;
 }
 
-/* Return nonzero if the indicated argument list exceeds a testing limit. */
+/* Return nonzero if the indicated argument list exceeds a testing limit.
+ * NOTE: argv could be declared 'const char *const *argv', but it works as
+ * expected only with C++ compilers <http://c-faq.com/ansi/constmismatch.html>.
+ */
 bool
-bc_args_exceed_testing_limit (const char **argv)
+bc_args_exceed_testing_limit (char **argv)
 {
   size_t chars, args;