summaryrefslogtreecommitdiff
path: root/misc.c
diff options
context:
space:
mode:
authorivmai <ivmai>2011-04-03 21:29:08 +0200
committerIvan Maidanski <ivmai@mail.ru>2011-07-26 19:06:57 +0200
commit2f9f31a6feb731f07aecebbb31c592f7eb7e35f5 (patch)
treeca7932d5996f5bd1a4cfbc8fa67ec9a0594185bb /misc.c
parent2dd6fcb8eb83cebc86640afbbdacacff5e45a6b3 (diff)
2011-04-03 Ivan Maidanski <ivmai@mail.ru>
* misc.c (GC_stdout, GC_stderr): Move the definition to the place where GC_log is defined (Unix only). * misc.c (GC_init): Recognize "GC_ONLY_LOG_TO_FILE" environment variable and the similar macro; redirect GC_stdout and GC_stderr to GC_log if "GC_LOG_FILE" environment variable is set unless prohibited by GC_ONLY_LOG_TO_FILE (Unix only). * doc/README.environment (GC_ONLY_LOG_TO_FILE): Document. * doc/README.macros (GC_ONLY_LOG_TO_FILE): Ditto.
Diffstat (limited to 'misc.c')
-rw-r--r--misc.c23
1 files changed, 19 insertions, 4 deletions
diff --git a/misc.c b/misc.c
index 22f2ba0..a27d9aa 100644
--- a/misc.c
+++ b/misc.c
@@ -627,7 +627,9 @@ STATIC void GC_exit_check(void)
#endif
#if !defined(OS2) && !defined(MACOS) && !defined(MSWIN32) && !defined(MSWINCE)
- STATIC int GC_log = 2;
+ STATIC int GC_stdout = 1;
+ STATIC int GC_stderr = 2;
+ STATIC int GC_log = 2; /* stderr */
#endif
GC_INNER void GC_initialize_offsets(void); /* defined in obj_map.c */
@@ -713,7 +715,23 @@ GC_API void GC_CALL GC_init(void)
if (log_d < 0) {
GC_err_printf("Failed to open %s as log file\n", file_name);
} else {
+ char *str;
GC_log = log_d;
+ str = GETENV("GC_ONLY_LOG_TO_FILE");
+# ifdef GC_ONLY_LOG_TO_FILE
+ /* The similar environment variable set to "0" */
+ /* overrides the effect of the macro defined. */
+ if (str != NULL && *str == '0' && *(str + 1) == '\0')
+# else
+ /* Otherwise setting the environment variable */
+ /* to anything other than "0" will prevent from */
+ /* redirecting stdout/err to the log file. */
+ if (str == NULL || (*str == '0' && *(str + 1) == '\0'))
+# endif
+ {
+ GC_stdout = log_d;
+ GC_stderr = log_d;
+ }
}
}
}
@@ -1192,9 +1210,6 @@ GC_API void GC_CALL GC_enable_incremental(void)
# define WRITE(f, buf, len) (GC_set_files(), GC_write(f, buf, len))
#else
- STATIC int GC_stdout = 1;
- STATIC int GC_stderr = 2;
- /* GC_log is defined above. */
# if !defined(AMIGA)
# include <unistd.h>
# endif