# HG changeset patch # User Sadrul Habib Chowdhury # Date 1182052227 0 # Node ID 88dc7c826752291498eca257283051a15f3dcf30 # Parent 4bd4756dc72796d539024153cd5700f5f9100179# Parent 5d10587689702094cc2314379695d22f434a7a7a merge of '96e4fe7ca94dcb0c455414bd266f9953e2aea59a' and 'dcf2ead9f63be6b4b902706a962d67327ae5230e' diff -r 5d1058768970 -r 88dc7c826752 libpurple/core.c --- a/libpurple/core.c Sun Jun 17 03:42:10 2007 +0000 +++ b/libpurple/core.c Sun Jun 17 03:50:27 2007 +0000 @@ -489,13 +489,33 @@ /* We're only going to duplicate a logs symlink. */ if (!strcmp(entry, "logs")) { + char *link; +#if GLIB_CHECK_VERSION(2,4,0) + GError *err = NULL; + + if ((link = g_file_read_link(name, &err)) == NULL) + { + char *name_utf8 = g_filename_to_utf8(name, -1, NULL, NULL, NULL); + purple_debug_error("core", "Error reading symlink %s: %s. Please report this at http://developer.pidgin.im\n", + name_utf8 ? name_utf8 : name, err->message); + g_free(name_utf8); + g_error_free(err); + g_free(name); + g_dir_close(dir); + g_free(status_file); + g_free(old_user_dir); + return FALSE; + } +#else char buf[MAXPATHLEN]; size_t linklen; if ((linklen = readlink(name, buf, sizeof(buf) - 1) == -1)) { + char *name_utf8 = g_filename_to_utf8(name); purple_debug_error("core", "Error reading symlink %s: %s. Please report this at http://developer.pidgin.im\n", - name, strerror(errno)); + name_utf8, strerror(errno)); + g_free(name_utf8); g_free(name); g_dir_close(dir); g_free(status_file); @@ -504,13 +524,18 @@ } buf[linklen] = '\0'; - logs_dir = g_strconcat(user_dir, G_DIR_SEPARATOR_S "logs", NULL); + /* This way we don't have to GLIB_VERSION_CHECK every g_free(link) below. */ + link = g_strdup(buf); +#endif - if (!strcmp(buf, "../.purple/logs") || !strcmp(buf, logs_dir)) + logs_dir = g_build_filename(user_dir, "logs", NULL); + + if (!strcmp(link, "../.purple/logs") || !strcmp(link, logs_dir)) { /* If the symlink points to the new directory, we're * likely just trying again after a failed migration, * so there's no need to fail here. */ + g_free(link); g_free(logs_dir); continue; } @@ -522,12 +547,13 @@ g_unlink(logs_dir); /* Relative links will most likely still be - * valid from ~/.purple, though not it's not + * valid from ~/.purple, though it's not * guaranteed. Oh well. */ - if (symlink(buf, logs_dir)) + if (symlink(link, logs_dir)) { purple_debug_error("core", "Error symlinking %s to %s: %s. Please report this at http://developer.pidgin.im\n", - logs_dir, buf, strerror(errno)); + logs_dir, link, strerror(errno)); + g_free(link); g_free(name); g_free(logs_dir); g_dir_close(dir); @@ -536,6 +562,7 @@ return FALSE; } + g_free(link); g_free(logs_dir); continue; } diff -r 5d1058768970 -r 88dc7c826752 libpurple/internal.h --- a/libpurple/internal.h Sun Jun 17 03:42:10 2007 +0000 +++ b/libpurple/internal.h Sun Jun 17 03:50:27 2007 +0000 @@ -111,16 +111,10 @@ # include #endif -#ifndef MAXPATHLEN -# define MAXPATHLEN 1024 -#endif - #ifndef HOST_NAME_MAX # define HOST_NAME_MAX 255 #endif -#define PATHSIZE 1024 - #include #if !GLIB_CHECK_VERSION(2,4,0) # define G_MAXUINT32 ((guint32) 0xffffffff) diff -r 5d1058768970 -r 88dc7c826752 libpurple/protocols/zephyr/ZLocations.c --- a/libpurple/protocols/zephyr/ZLocations.c Sun Jun 17 03:42:10 2007 +0000 +++ b/libpurple/protocols/zephyr/ZLocations.c Sun Jun 17 03:50:27 2007 +0000 @@ -36,7 +36,8 @@ return (Z_SendLocation(LOGIN_CLASS, LOGIN_USER_FLUSH, ZAUTH, "")); } -static char host[MAXHOSTNAMELEN], mytty[MAXPATHLEN]; +static char host[MAXHOSTNAMELEN]; +static char *mytty = NULL; static int reenter = 0; Code_t Z_SendLocation(class, opcode, auth, format) @@ -87,21 +88,20 @@ } #ifndef X_DISPLAY_MISSING if ((display = getenv("DISPLAY")) && *display) { - (void) strncpy(mytty, display, sizeof(mytty)); + mytty = g_strdup(display); } else { #endif #ifdef WIN32 - strncpy(mytty, "WinPurple", sizeof(mytty)); + mytty = g_strdup("WinPurple"); #else ttyp = ttyname(0); if (ttyp && *ttyp) { p = strchr(ttyp + 1, '/'); - strcpy(mytty, (p) ? p + 1 : ttyp); + mytty = g_strdup((p) ? p + 1 : ttyp); } else { - strncpy(mytty, "unknown", sizeof(mytty)); + mytty = g_strdup("unknown"); } #endif - mytty[sizeof(mytty)-1] = '\0'; #ifndef X_DISPLAY_MISSING } #endif @@ -114,7 +114,6 @@ bptr[1][strlen(bptr[1])-1] = '\0'; bptr[2] = mytty; - if ((retval = ZSendList(¬ice, bptr, 3, auth)) != ZERR_NONE) return (retval); diff -r 5d1058768970 -r 88dc7c826752 libpurple/util.c --- a/libpurple/util.c Sun Jun 17 03:42:10 2007 +0000 +++ b/libpurple/util.c Sun Jun 17 03:50:27 2007 +0000 @@ -66,8 +66,8 @@ unsigned long data_len; }; -static char custom_home_dir[MAXPATHLEN]; -static char home_dir[MAXPATHLEN] = ""; +static char *custom_user_dir = NULL; +static char *home_dir = NULL; PurpleMenuAction * purple_menu_action_new(const char *label, PurpleCallback callback, gpointer data, @@ -2396,27 +2396,22 @@ const char * purple_user_dir(void) { - if (custom_home_dir != NULL && *custom_home_dir) { - strcpy ((char*) &home_dir, (char*) &custom_home_dir); - } else if (!*home_dir) { - const gchar *hd = purple_home_dir(); - - if (hd) { - g_strlcpy((char*) &home_dir, hd, sizeof(home_dir)); - g_strlcat((char*) &home_dir, G_DIR_SEPARATOR_S ".purple", - sizeof(home_dir)); - } - } + if (custom_user_dir != NULL) + return custom_user_dir; + else if (!home_dir) + home_dir = g_build_filename(purple_home_dir(), ".purple", NULL); return home_dir; } void purple_util_set_user_dir(const char *dir) { - if (dir != NULL && strlen(dir) > 0) { - g_strlcpy((char*) &custom_home_dir, dir, - sizeof(custom_home_dir)); - } + g_free(custom_user_dir); + + if (dir != NULL && *dir) + custom_user_dir = g_strdup(dir); + else + custom_user_dir = NULL; } int purple_build_dir (const char *path, int mode)