summaryrefslogtreecommitdiff
path: root/gutils.c
diff options
context:
space:
mode:
authorTim Janik <timj@gtk.org>1999-02-10 08:06:26 +0000
committerTim Janik <timj@src.gnome.org>1999-02-10 08:06:26 +0000
commita8ff1b4fcef1e2c53603b30b918304f7be9f27b4 (patch)
treede53f40d1b3978c7bc1dbdf0e0a6c60ac0f20dcb /gutils.c
parent6c7994772297281730071874e609b62e68c211be (diff)
downloadglib-a8ff1b4fcef1e2c53603b30b918304f7be9f27b4.tar.gz
fixed errernerous code wrt to thread specific error string allocation
Wed Feb 10 07:56:33 1999 Tim Janik <timj@gtk.org> * gmodule.c (g_module_error): fixed errernerous code wrt to thread specific error string allocation handling. Wed Feb 10 06:20:30 1999 Tim Janik <timj@gtk.org> * gmutex.c (g_static_private_set): invoke destroy notifier when overwriting values, initialize new array fields with NULL. (g_static_private_free_data): do not skip destroy notification for data == NULL. * gutils.c (g_direct_equal): compare pointer values directly instead of just their guint values which is a loosing conversion for sizeof(gpointer)==8 systems. (g_get_any_init): restructured code so we don't use endless loops like while (1), which boil down to an ugly alias for goto. strip ,.* from the real name.
Diffstat (limited to 'gutils.c')
-rw-r--r--gutils.c84
1 files changed, 49 insertions, 35 deletions
diff --git a/gutils.c b/gutils.c
index 04771cc79..8e4d1f9aa 100644
--- a/gutils.c
+++ b/gutils.c
@@ -401,7 +401,7 @@ g_get_any_init (void)
g_tmp_dir[k-1] = '\0';
}
#endif
-
+
if (!g_tmp_dir)
{
#ifndef NATIVE_WIN32
@@ -442,18 +442,18 @@ g_get_any_init (void)
{
struct passwd *pw = NULL;
gpointer buffer = NULL;
-
+
# ifdef HAVE_GETPWUID_R
struct passwd pwd;
guint bufsize = 64;
gint error;
-
- while (1)
+
+ do
{
g_free (buffer);
buffer = g_malloc (bufsize);
errno = 0;
-
+
# ifdef HAVE_GETPWUID_R_POSIX
error = getpwuid_r (getuid (), &pwd, buffer, bufsize, &pw);
error = error < 0 ? errno : error;
@@ -461,33 +461,33 @@ g_get_any_init (void)
pw = getpwuid_r (getuid (), &pwd, buffer, bufsize);
error = pw ? 0 : errno;
# endif /* !HAVE_GETPWUID_R_POSIX */
-
- /* Now there are actually only 3 cases to leave the loop:
- 1. pw != NULL -> all went fine.
- 2. pw == NULL && ( error == 0 || error == ENOENT )
- -> no such user (unlikely in the case of getuid ())
- 3. bufsize > 32k -> the problem can't be of ERANGE type */
- if (pw)
- break;
-
- if (pw == NULL && ( error == 0 || error == ENOENT))
+
+ if (!pw)
{
- g_warning ("getpwuid_r(): failed due to: No such user %d.",
- getuid ());
- break;
- }
-
- if (bufsize > 32 * 1024)
- {
- g_warning ("getpwuid_r(): failed due to: %s.",
- g_strerror (error));
- break;
+ /* we bail out prematurely if the user id can't be found
+ * (should be pretty rare case actually), or if the buffer
+ * should be sufficiently big and lookups are still not
+ * successfull.
+ */
+ if (error == 0 || error == ENOENT)
+ {
+ g_warning ("getpwuid_r(): failed due to: No such user %d.",
+ getuid ());
+ break;
+ }
+ if (bufsize > 32 * 1024)
+ {
+ g_warning ("getpwuid_r(): failed due to: %s.",
+ g_strerror (error));
+ break;
+ }
+
+ bufsize *= 2;
}
-
- bufsize *= 2;
- }
+ }
+ while (!pw);
# endif /* !HAVE_GETPWUID_R */
-
+
if (!pw)
{
setpwent ();
@@ -503,9 +503,9 @@ g_get_any_init (void)
}
g_free (buffer);
}
-
+
#else /* !HAVE_PWD_H */
-
+
# ifdef NATIVE_WIN32
{
guint len = 17;
@@ -518,14 +518,28 @@ g_get_any_init (void)
}
}
# endif /* NATIVE_WIN32 */
-
+
#endif /* !HAVE_PWD_H */
-
+
if (!g_user_name)
g_user_name = g_strdup ("somebody");
if (!g_real_name)
g_real_name = g_strdup ("Unknown");
- }
+ else
+ {
+ gchar *p;
+
+ for (p = g_real_name; *p; p++)
+ if (*p == ',')
+ {
+ *p = 0;
+ p = g_strdup (g_real_name);
+ g_free (g_real_name);
+ g_real_name = p;
+ break;
+ }
+ }
+ }
}
gchar*
@@ -621,7 +635,7 @@ gint
g_direct_equal (gconstpointer v1,
gconstpointer v2)
{
- return GPOINTER_TO_UINT (v1) == GPOINTER_TO_UINT (v2);
+ return v1 == v2;
}
gint