From 4e820c27bc5f08c3f72ba4b5a2132277c0080383 Mon Sep 17 00:00:00 2001 From: Pekka Riikonen Date: Sat, 30 Mar 2002 17:05:58 +0000 Subject: [PATCH] updates. --- CHANGES | 15 +++++++++++++++ apps/irssi/src/core/core.c | 5 +++-- apps/irssi/src/core/misc.c | 16 +++++++++++++++- apps/irssi/src/core/misc.h | 4 ++++ apps/irssi/src/silc/core/silc-core.c | 13 ++++--------- lib/silcutil/unix/silcunixutil.c | 14 +++++--------- 6 files changed, 46 insertions(+), 21 deletions(-) diff --git a/CHANGES b/CHANGES index f355f383..ffc89f05 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,18 @@ +Sat Mar 30 18:15:55 EET 2002 Pekka Riikonen + + * Changed the silc_get_username and silc_get_real_name to + never fail. Affected file lib/silcutil/unix/silcunixutil.c. + + * Fixed the Irssi SILC Client to use the silc_get_username and + silc_get_real_name insted of glib routines since the glib + routines only corrupt stack. Fixes the Irssi SILC to work in + Cygwin. Affected file irssi/src/silc/core/silc-core.c. + + * Fixed the Irssi to not use g_get_home_dir since it crashes + or returns garbage on cygwin and corrupts stack. Added function + get_home_dir to Irssi routines. Affected files are + irssi/src/core/misc.[ch] and irssi/src/core/core.c. + Fri Mar 29 10:41:07 EET 2002 Pekka Riikonen * And yet again reverted back the config thing since Johnny diff --git a/apps/irssi/src/core/core.c b/apps/irssi/src/core/core.c index b11064cb..0deb5090 100644 --- a/apps/irssi/src/core/core.c +++ b/apps/irssi/src/core/core.c @@ -192,9 +192,10 @@ void core_init_paths(int argc, char *argv[]) args_register(options); if (irssi_dir == NULL) - irssi_dir = g_strdup_printf(IRSSI_DIR_FULL, g_get_home_dir()); + irssi_dir = g_strdup_printf(IRSSI_DIR_FULL, get_home_dir()); if (irssi_config_file == NULL) - irssi_config_file = g_strdup_printf("%s/"IRSSI_HOME_CONFIG, irssi_dir); + irssi_config_file = g_strdup_printf("%s/"IRSSI_HOME_CONFIG, + irssi_dir); session_set_binary(argv[0]); } diff --git a/apps/irssi/src/core/misc.c b/apps/irssi/src/core/misc.c index 6bf87177..93612d6b 100644 --- a/apps/irssi/src/core/misc.c +++ b/apps/irssi/src/core/misc.c @@ -26,6 +26,7 @@ #ifdef HAVE_REGEX_H # include #endif +#include typedef struct { int condition; @@ -448,11 +449,24 @@ int mkpath(const char *path, int mode) return 0; } +/* Get home directory */ +const char *get_home_dir(void) +{ + struct passwd *pw = getpwuid(getuid()); + if (!pw) { + if (g_getenv("HOME")) + return g_getenv("HOME"); + else + return "."; + } + return pw->pw_dir; +} + /* convert ~/ to $HOME */ char *convert_home(const char *path) { return *path == '~' && (*(path+1) == '/' || *(path+1) == '\0') ? - g_strconcat(g_get_home_dir(), path+1, NULL) : + g_strconcat((char *)get_home_dir, path+1, NULL) : g_strdup(path); } diff --git a/apps/irssi/src/core/misc.h b/apps/irssi/src/core/misc.h index 804cffc2..a321bdfc 100644 --- a/apps/irssi/src/core/misc.h +++ b/apps/irssi/src/core/misc.h @@ -61,6 +61,10 @@ int regexp_match(const char *str, const char *regexp); /* Create the directory and all it's parent directories */ int mkpath(const char *path, int mode); + +/* Get home directory */ +const char *get_home_dir(void); + /* convert ~/ to $HOME */ char *convert_home(const char *path); diff --git a/apps/irssi/src/silc/core/silc-core.c b/apps/irssi/src/silc/core/silc-core.c index a58a1ec3..6c9c7f2a 100644 --- a/apps/irssi/src/silc/core/silc-core.c +++ b/apps/irssi/src/silc/core/silc-core.c @@ -100,7 +100,7 @@ static void silc_init_userinfo(void) if (!str) str = g_getenv("IRCNAME"); settings_set_str("real_name", - str != NULL ? str : g_get_real_name()); + str != NULL ? str : silc_get_real_name()); } /* username */ @@ -110,8 +110,8 @@ static void silc_init_userinfo(void) if (!str) str = g_getenv("IRCUSER"); settings_set_str("user_name", - str != NULL ? str : g_get_user_name()); - + str != NULL ? str : silc_get_username()); + user_name = settings_get_str("user_name"); } @@ -129,12 +129,7 @@ static void silc_init_userinfo(void) /* alternate nick */ set = settings_get_str("alternate_nick"); if (set == NULL || *set == '\0') { - if (strlen(nick) < 9) - str = g_strconcat(nick, "_", NULL); - else { - str = g_strdup(nick); - str[strlen(str)-1] = '_'; - } + str = g_strconcat(nick, "_", NULL); settings_set_str("alternate_nick", str); g_free(str); } diff --git a/lib/silcutil/unix/silcunixutil.c b/lib/silcutil/unix/silcunixutil.c index 8cb6a723..42b6edac 100644 --- a/lib/silcutil/unix/silcunixutil.c +++ b/lib/silcutil/unix/silcunixutil.c @@ -140,11 +140,9 @@ char *silc_get_username() struct passwd *pw; pw = getpwuid(getuid()); - if (!pw) { - fprintf(stderr, "silc_get_username: %s\n", strerror(errno)); - return NULL; - } - + if (!pw) + return strdup("foo"); + logname = pw->pw_name; } } @@ -160,10 +158,8 @@ char *silc_get_real_name() struct passwd *pw; pw = getpwuid(getuid()); - if (!pw) { - fprintf(stderr, "silc_get_username: %s\n", strerror(errno)); - return NULL; - } + if (!pw) + return strdup("Foo T. Bar"); if (strchr(pw->pw_gecos, ',')) *strchr(pw->pw_gecos, ',') = 0; -- 2.24.0