diff options
author | Rafael Espindola <rafael.espindola@gmail.com> | 2013-04-11 14:06:34 +0000 |
---|---|---|
committer | Rafael Espindola <rafael.espindola@gmail.com> | 2013-04-11 14:06:34 +0000 |
commit | cd848c0866cffc70f97b65689b269a1441ee48d0 (patch) | |
tree | 8b3ac5ae15ba65d78b72e370190b8c177d5a9ddb /llvm/lib/Support/Unix/Program.inc | |
parent | 9643a313ac976716f0893159f7d9d8c0bde7da63 (diff) | |
download | bcm5719-llvm-cd848c0866cffc70f97b65689b269a1441ee48d0.tar.gz bcm5719-llvm-cd848c0866cffc70f97b65689b269a1441ee48d0.zip |
Add a function to check if an argument list is too long.
This will be used in clang to decide if it should create an @file or not. It
will be tested on the clang side.
Patch by Nathan Froyd.
llvm-svn: 179285
Diffstat (limited to 'llvm/lib/Support/Unix/Program.inc')
-rw-r--r-- | llvm/lib/Support/Unix/Program.inc | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/llvm/lib/Support/Unix/Program.inc b/llvm/lib/Support/Unix/Program.inc index 117151c91d8..aa03d48438e 100644 --- a/llvm/lib/Support/Unix/Program.inc +++ b/llvm/lib/Support/Unix/Program.inc @@ -32,6 +32,9 @@ #if HAVE_FCNTL_H #include <fcntl.h> #endif +#if HAVE_UNISTD_H +#include <unistd.h> +#endif #ifdef HAVE_POSIX_SPAWN #include <spawn.h> #if !defined(__APPLE__) @@ -409,4 +412,25 @@ error_code Program::ChangeStderrToBinary(){ return make_error_code(errc::success); } +bool llvm::sys::argumentsFitWithinSystemLimits(ArrayRef<const char*> 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<const char*>::iterator I = Args.begin(), E = Args.end(); + I != E; ++I) { + ArgLength += strlen(*I) + 1; + if (ArgLength > size_t(ArgMax)) { + return false; + } + } + return true; +} + } |