summaryrefslogtreecommitdiffstats
path: root/llvm/lib/System/Unix
diff options
context:
space:
mode:
authorMatthijs Kooijman <matthijs@stdin.nl>2008-06-12 10:47:18 +0000
committerMatthijs Kooijman <matthijs@stdin.nl>2008-06-12 10:47:18 +0000
commit616e484be4996f3f54e35f39196457893a70f99e (patch)
treee5df03ee1ba8128727e3bc77fdfda3c55e05533d /llvm/lib/System/Unix
parent39a53910797432bcd44ae548edcad54f7f7e0a33 (diff)
downloadbcm5719-llvm-616e484be4996f3f54e35f39196457893a70f99e.tar.gz
bcm5719-llvm-616e484be4996f3f54e35f39196457893a70f99e.zip
Make I/O redirection handling in sys::Program a bit more consistent. No
functional changes. Win32 code is untested, but should work fine. In the unix variant, rename RedirectFD to RedirectIO and let that function handle empty and null paths instead of doing that in the caller 3 times. This is the same as win32 already does it. In the win32 variant, use Path::isEmpty() instead of checking the resulting c_str() manually. This is the same as unix already does it. llvm-svn: 52230
Diffstat (limited to 'llvm/lib/System/Unix')
-rw-r--r--llvm/lib/System/Unix/Program.inc34
1 files changed, 13 insertions, 21 deletions
diff --git a/llvm/lib/System/Unix/Program.inc b/llvm/lib/System/Unix/Program.inc
index d0dade1f8ca..6ff69ca133e 100644
--- a/llvm/lib/System/Unix/Program.inc
+++ b/llvm/lib/System/Unix/Program.inc
@@ -84,8 +84,16 @@ Program::FindProgramByName(const std::string& progName) {
return Path();
}
-static bool RedirectFD(const std::string &File, int FD, std::string* ErrMsg) {
- if (File.empty()) return false; // Noop
+static bool RedirectIO(const Path *Path, int FD, std::string* ErrMsg) {
+ if (Path == 0)
+ // Noop
+ return false;
+ std::string File;
+ if (Path->isEmpty())
+ // Redirect empty paths to /dev/null
+ File = "/dev/null";
+ else
+ File = Path->toString();
// Open the file
int InFD = open(File.c_str(), FD == 0 ? O_RDONLY : O_WRONLY|O_CREAT, 0666);
@@ -162,27 +170,11 @@ Program::ExecuteAndWait(const Path& path,
case 0: {
// Redirect file descriptors...
if (redirects) {
- if (redirects[0]) {
- if (redirects[0]->isEmpty()) {
- if (RedirectFD("/dev/null",0,ErrMsg)) { return -1; }
- } else {
- if (RedirectFD(redirects[0]->toString(), 0,ErrMsg)) { return -1; }
- }
- }
- if (redirects[1]) {
- if (redirects[1]->isEmpty()) {
- if (RedirectFD("/dev/null",1,ErrMsg)) { return -1; }
- } else {
- if (RedirectFD(redirects[1]->toString(),1,ErrMsg)) { return -1; }
- }
- }
+ if (RedirectIO(redirects[0], 0, ErrMsg)) { return -1; }
+ if (RedirectIO(redirects[1], 1, ErrMsg)) { return -1; }
if (redirects[1] && redirects[2] &&
*(redirects[1]) != *(redirects[2])) {
- if (redirects[2]->isEmpty()) {
- if (RedirectFD("/dev/null",2,ErrMsg)) { return -1; }
- } else {
- if (RedirectFD(redirects[2]->toString(), 2,ErrMsg)) { return -1; }
- }
+ if (RedirectIO(redirects[2], 2, ErrMsg)) { return -1; }
} else if (-1 == dup2(1,2)) {
MakeErrMsg(ErrMsg, "Can't redirect");
return -1;
OpenPOWER on IntegriCloud