From 0221263645002c662415b59283ba79b1830ef20f Mon Sep 17 00:00:00 2001 From: Tor Lillqvist Date: Tue, 2 Feb 1999 01:24:34 +0000 Subject: Don't call ensure_stdout_valid (which would open an unneeded console * gmessages.c (g_log_default_handler): (Win32:) Don't call ensure_stdout_valid (which would open an unneeded console window) if we're calling a logging function. Define ensure_stdout_valid as an empty macro on Unix. * gutils.c (g_get_any_init): (Win32:) Trust HOME first if defined, then try HOMEDRIVE and HOMEPATH. --- glib/gmessages.c | 14 ++++++++++---- glib/gutils.c | 42 ++++++++++++++++++++++-------------------- 2 files changed, 32 insertions(+), 24 deletions(-) (limited to 'glib') diff --git a/glib/gmessages.c b/glib/gmessages.c index 1ef33445d..404e953eb 100644 --- a/glib/gmessages.c +++ b/glib/gmessages.c @@ -50,12 +50,10 @@ write (FILE *fd, return len; } -#endif /* NATIVE_WIN32 */ static void ensure_stdout_valid (void) { -#ifdef NATIVE_WIN32 HANDLE handle; handle = GetStdHandle (STD_OUTPUT_HANDLE); @@ -65,8 +63,10 @@ ensure_stdout_valid (void) AllocConsole (); freopen ("CONOUT$", "w", stdout); } -#endif } +#else +#define ensure_stdout_valid() /* Define as empty */ +#endif /* --- structures --- */ @@ -429,7 +429,6 @@ g_log_default_handler (const gchar *log_domain, * DOS prompt. */ fd = stdout; - ensure_stdout_valid (); #else fd = (log_level >= G_LOG_LEVEL_MESSAGE) ? 1 : 2; #endif @@ -450,6 +449,7 @@ g_log_default_handler (const gchar *log_domain, return; } /* use write(2) for output, in case we are out of memeory */ + ensure_stdout_valid (); if (log_domain) { write (fd, "\n", 1); @@ -469,6 +469,7 @@ g_log_default_handler (const gchar *log_domain, write (fd, "\n", 1); break; case G_LOG_LEVEL_CRITICAL: + ensure_stdout_valid (); if (log_domain) { write (fd, "\n", 1); @@ -494,6 +495,7 @@ g_log_default_handler (const gchar *log_domain, local_glib_warning_func (message); return; } + ensure_stdout_valid (); if (log_domain) { write (fd, "\n", 1); @@ -519,6 +521,7 @@ g_log_default_handler (const gchar *log_domain, local_glib_message_func (message); return; } + ensure_stdout_valid (); if (log_domain) { write (fd, log_domain, strlen (log_domain)); @@ -535,6 +538,7 @@ g_log_default_handler (const gchar *log_domain, write (fd, "\n", 1); break; case G_LOG_LEVEL_INFO: + ensure_stdout_valid (); if (log_domain) { write (fd, log_domain, strlen (log_domain)); @@ -551,6 +555,7 @@ g_log_default_handler (const gchar *log_domain, write (fd, "\n", 1); break; case G_LOG_LEVEL_DEBUG: + ensure_stdout_valid (); if (log_domain) { write (fd, log_domain, strlen (log_domain)); @@ -570,6 +575,7 @@ g_log_default_handler (const gchar *log_domain, /* we are used for a log level that is not defined by GLib itself, * try to make the best out of it. */ + ensure_stdout_valid (); if (log_domain) { write (fd, log_domain, strlen (log_domain)); diff --git a/glib/gutils.c b/glib/gutils.c index 50e7c361c..321a1311f 100644 --- a/glib/gutils.c +++ b/glib/gutils.c @@ -411,31 +411,33 @@ g_get_any_init (void) #endif /* NATIVE_WIN32 */ } -#ifdef NATIVE_WIN32 - /* The official way to specify a home directory on NT is - * the HOMEDRIVE and HOMEPATH environment variables. - * - * This is inside #ifdef NATIVE_WIN32 because with the cygwin dll, - * HOME should be a POSIX style pathname. - */ + if (!g_home_dir) + g_home_dir = g_strdup (g_getenv ("HOME")); - if (getenv ("HOMEDRIVE") != NULL && getenv ("HOMEPATH") != NULL) +#ifdef NATIVE_WIN32 + if (!g_home_dir) { - gchar *homedrive, *homepath; - - homedrive = g_strdup (g_getenv ("HOMEDRIVE")); - homepath = g_strdup (g_getenv ("HOMEPATH")); - - g_home_dir = g_strconcat (homedrive, homepath, NULL); - g_free (homedrive); - g_free (homepath); + /* The official way to specify a home directory on NT is + * the HOMEDRIVE and HOMEPATH environment variables. + * + * This is inside #ifdef NATIVE_WIN32 because with the cygwin dll, + * HOME should be a POSIX style pathname. + */ + + if (getenv ("HOMEDRIVE") != NULL && getenv ("HOMEPATH") != NULL) + { + gchar *homedrive, *homepath; + + homedrive = g_strdup (g_getenv ("HOMEDRIVE")); + homepath = g_strdup (g_getenv ("HOMEPATH")); + + g_home_dir = g_strconcat (homedrive, homepath, NULL); + g_free (homedrive); + g_free (homepath); + } } #endif /* !NATIVE_WIN32 */ - if (!g_home_dir) - g_home_dir = g_strdup (g_getenv ("HOME")); - - #ifdef HAVE_PWD_H { struct passwd *pw = NULL; -- cgit v1.2.3