changeset 14269:d1cb45dec12f

[gaim-migrate @ 16951] Use lazy initialization for wgaim_data_dir() to allow it to be used before the core is initialized. Make win32 debug printing not allocate memory when it doesn't need to. committer: Tailor Script <tailor@pidgin.im>
author Daniel Atallah <daniel.atallah@gmail.com>
date Mon, 21 Aug 2006 15:17:22 +0000
parents e6892c0050ad
children 4c82afb76534
files libgaim/win32/win32dep.c
diffstat 1 files changed, 28 insertions(+), 34 deletions(-) [+]
line wrap: on
line diff
--- a/libgaim/win32/win32dep.c	Mon Aug 21 08:20:11 2006 +0000
+++ b/libgaim/win32/win32dep.c	Mon Aug 21 15:17:22 2006 +0000
@@ -45,10 +45,6 @@
  */
 #define _(x) gettext(x)
 
-/*
- * DATA STRUCTS
- */
-
 /* For shfolder.dll */
 typedef HRESULT (CALLBACK* LPFNSHGETFOLDERPATHA)(HWND, int, HANDLE, DWORD, LPSTR);
 typedef HRESULT (CALLBACK* LPFNSHGETFOLDERPATHW)(HWND, int, HANDLE, DWORD, LPWSTR);
@@ -56,32 +52,25 @@
 /*
  * LOCALS
  */
-static char *app_data_dir, *install_dir, *lib_dir, *locale_dir;
-
-/*
- *  GLOBALS
- */
-HINSTANCE libgaimdll_hInstance = 0;
+static char *app_data_dir = NULL, *install_dir = NULL,
+	*lib_dir = NULL, *locale_dir = NULL;
 
-/*
- *  PROTOS
- */
+static HINSTANCE libgaimdll_hInstance = 0;
 
-FARPROC wgaim_find_and_loadproc(char*, char*);
-char* wgaim_data_dir(void);
 
 /*
  *  STATIC CODE
  */
 
-static void wgaim_debug_print(GaimDebugLevel level, const char *category, const char *format, va_list args) {
+static void wgaim_debug_print(GaimDebugLevel level, const char *category,
+		const char *format, va_list args) {
 	char *str = NULL;
-	if (args != NULL) {
+	if (args != NULL)
 		str = g_strdup_vprintf(format, args);
-	} else {
-		str = g_strdup(format);
-	}
-	printf("%s%s%s", category ? category : "", category ? ": " : "", str);
+	printf("%s%s%s",
+		category ? category : "",
+		category ? ": " : "",
+		str ? str : format);
 	g_free(str);
 }
 
@@ -263,6 +252,21 @@
 }
 
 char* wgaim_data_dir(void) {
+
+	if (!app_data_dir) {
+		/* Set app data dir, used by gaim_home_dir */
+		const char *newenv = g_getenv("GAIMHOME");
+		if (newenv)
+			app_data_dir = g_strdup(newenv);
+		else {
+			app_data_dir = wgaim_get_special_folder(CSIDL_APPDATA);
+			if (!app_data_dir)
+				app_data_dir = g_strdup("C:");
+		}
+		gaim_debug(GAIM_DEBUG_INFO, "wgaim", "Gaim settings dir: %s\n",
+			app_data_dir);
+	}
+
 	return app_data_dir;
 }
 
@@ -318,19 +322,6 @@
 		gaim_debug(GAIM_DEBUG_WARNING, "wgaim", "putenv failed\n");
 	g_free(newenv);
 
-	/* Set app data dir, used by gaim_home_dir */
-	newenv = (char*) g_getenv("GAIMHOME");
-	if (newenv) {
-		app_data_dir = g_strdup(newenv);
-	} else {
-		app_data_dir = wgaim_get_special_folder(CSIDL_APPDATA);
-		if (!app_data_dir) {
-			app_data_dir = g_strdup("C:");
-		}
-	}
-
-	gaim_debug(GAIM_DEBUG_INFO, "wgaim", "Gaim settings dir: %s\n", app_data_dir);
-
 	gaim_debug(GAIM_DEBUG_INFO, "wgaim", "wgaim_init end\n");
 }
 
@@ -343,6 +334,9 @@
 	WSACleanup();
 
 	g_free(app_data_dir);
+	app_data_dir = NULL;
+
+	libgaimdll_hInstance = NULL;
 }
 
 /* DLL initializer */