Skip to content

Commit 4947448

Browse files
committed
Refactor logfile creation code in tst_output
Move all logfile related code in tst_output_init to one place and simplify logfile name creation by using snprintf. Signed-off-by: Christoph Niethammer <[email protected]>
1 parent b7cb4f9 commit 4947448

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

tst_output.c

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,16 +72,6 @@ tst_output_types tst_output_init(tst_output_stream * output, int rank,
7272
}
7373
#endif
7474

75-
/* Check if stream type uses a file and get the name of this file */
76-
if (type == TST_OUTPUT_TYPE_LOGFILE) {
77-
va_start(arglist, type);
78-
fname = va_arg (arglist, char *);
79-
sprintf (output->filename,"R%d_", tst_output_global_rank);
80-
freelen = TST_OUTPUT_FILENAME_MAX - (1 + strlen(output->filename));
81-
strncat (output->filename, fname, freelen);
82-
va_end (arglist);
83-
}
84-
8575
/* Now do the initialisation for the different stream types */
8676
switch (type) {
8777
case TST_OUTPUT_TYPE_STDERR:
@@ -91,6 +81,11 @@ tst_output_types tst_output_init(tst_output_stream * output, int rank,
9181
output->streamptr = stdout;
9282
break;
9383
case TST_OUTPUT_TYPE_LOGFILE:
84+
va_start(arglist, type);
85+
fname = va_arg (arglist, char *);
86+
snprintf(output->filename, TST_OUTPUT_FILENAME_MAX, "R%d_%s",
87+
tst_output_global_rank, fname);
88+
va_end (arglist);
9489
output->streamptr = fopen(output->filename, "w+");
9590
if (output->streamptr == NULL) {
9691
fprintf (stderr, "Error opening stream: Could not open output file.");

0 commit comments

Comments
 (0)