From aa45f148926e3461a1fd8b10c990f0a51a908cc9 Mon Sep 17 00:00:00 2001 From: dim Date: Mon, 10 Jun 2013 20:36:52 +0000 Subject: Vendor import of llvm tags/RELEASE_33/final r183502 (effectively, 3.3 release): http://llvm.org/svn/llvm-project/llvm/tags/RELEASE_33/final@183502 --- lib/Support/Unix/Program.inc | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'lib/Support/Unix/Program.inc') diff --git a/lib/Support/Unix/Program.inc b/lib/Support/Unix/Program.inc index 117151c..aa03d48 100644 --- a/lib/Support/Unix/Program.inc +++ b/lib/Support/Unix/Program.inc @@ -32,6 +32,9 @@ #if HAVE_FCNTL_H #include #endif +#if HAVE_UNISTD_H +#include +#endif #ifdef HAVE_POSIX_SPAWN #include #if !defined(__APPLE__) @@ -409,4 +412,25 @@ error_code Program::ChangeStderrToBinary(){ return make_error_code(errc::success); } +bool llvm::sys::argumentsFitWithinSystemLimits(ArrayRef Args) { + static long ArgMax = sysconf(_SC_ARG_MAX); + + // System says no practical limit. + if (ArgMax == -1) + return true; + + // Conservatively account for space required by environment variables. + ArgMax /= 2; + + size_t ArgLength = 0; + for (ArrayRef::iterator I = Args.begin(), E = Args.end(); + I != E; ++I) { + ArgLength += strlen(*I) + 1; + if (ArgLength > size_t(ArgMax)) { + return false; + } + } + return true; +} + } -- cgit v1.1