summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoreschnett <eschnett@17b73243-c579-4c4c-a9d2-2d5706c11dac>2012-03-03 22:27:37 +0000
committereschnett <eschnett@17b73243-c579-4c4c-a9d2-2d5706c11dac>2012-03-03 22:27:37 +0000
commit8e432a5ba1dfde17e8b3f11cc64aa5baf8c8363b (patch)
tree2929ebcd5fa47bbc54993203f298c15a8377a690 /src
parent2672757b563ebb42d16e8a872c4ea60e1901863d (diff)
Set file buffering for stdout after redirecting I/O
Set file buffering for stdout (Cactus option -l) after redirecting I/O (Cactus option -r), so that the buffering applies also for redirected I/O. git-svn-id: http://svn.cactuscode.org/flesh/trunk@4793 17b73243-c579-4c4c-a9d2-2d5706c11dac
Diffstat (limited to 'src')
-rw-r--r--src/main/CommandLine.c28
1 files changed, 25 insertions, 3 deletions
diff --git a/src/main/CommandLine.c b/src/main/CommandLine.c
index fac58368..cffc9fbf 100644
--- a/src/main/CommandLine.c
+++ b/src/main/CommandLine.c
@@ -51,6 +51,8 @@ static void CommandLinePrintParameter (const cParamData *properties);
static char* logdir = NULL;
static int requested_stdout_redirection = 0;
static int requested_stderr_redirection = 0;
+static int buffering_type = 0;
+/* buffering: 0=default, 1=unbuffered, 2=line, 3=fully */
static int paramchecking = 0;
@@ -497,17 +499,17 @@ void CCTKi_CommandLineSetBuffering (const char *argument)
if (! strcmp (argument, "no"))
{
/* Switch to unbuffered mode (best for debugging) */
- setvbuf (stdout, NULL, _IONBF, 0);
+ buffering_type = 1;
}
else if (! strcmp (argument, "line"))
{
/* Switch to line buffered mode (good for screen output) */
- setvbuf (stdout, NULL, _IOLBF, 0);
+ buffering_type = 2;
}
else if (! strcmp (argument, "full"))
{
/* Switch to fully buffered mode (fastest) */
- setvbuf (stdout, NULL, _IOFBF, 0);
+ buffering_type = 3;
}
else
{
@@ -747,6 +749,26 @@ void CCTKi_CommandLineFinished (void)
free (logfilename);
}
free (logdir);
+
+ /* if requested, change buffering mode of stdout */
+ switch (buffering_type)
+ {
+ case 0:
+ /* Keep default */
+ break;
+ case 1:
+ /* Switch to unbuffered mode (best for debugging) */
+ setvbuf (stdout, NULL, _IONBF, 0);
+ break;
+ case 2:
+ /* Switch to line buffered mode (good for screen output) */
+ setvbuf (stdout, NULL, _IOLBF, 0);
+ break;
+ case 3:
+ /* Switch to fully buffered mode (fastest) */
+ setvbuf (stdout, NULL, _IOFBF, 0);
+ break;
+ }
}