summaryrefslogtreecommitdiff
path: root/gutils.c
diff options
context:
space:
mode:
Diffstat (limited to 'gutils.c')
-rw-r--r--gutils.c100
1 files changed, 74 insertions, 26 deletions
diff --git a/gutils.c b/gutils.c
index 321a1311f..5ac16ed10 100644
--- a/gutils.c
+++ b/gutils.c
@@ -17,6 +17,13 @@
* Boston, MA 02111-1307, USA.
*/
+/*
+ * Modified by the GLib Team and others 1997-1999. See the AUTHORS
+ * file for a list of people on the GLib Team. See the ChangeLog
+ * files for a list of changes. These files are distributed with
+ * GLib at ftp://ftp.gtk.org/pub/gtk/.
+ */
+
/*
* MT safe for the unix part, FIXME: make the win32 part MT safe as well.
*/
@@ -372,7 +379,7 @@ g_getenv (const gchar *variable)
}
-G_LOCK_DECLARE_STATIC (g_utils_global);
+G_LOCK_DEFINE_STATIC (g_utils_global);
static gchar *g_tmp_dir = NULL;
static gchar *g_user_name = NULL;
@@ -401,7 +408,7 @@ g_get_any_init (void)
g_tmp_dir[k-1] = '\0';
}
#endif
-
+
if (!g_tmp_dir)
{
#ifndef NATIVE_WIN32
@@ -442,40 +449,63 @@ g_get_any_init (void)
{
struct passwd *pw = NULL;
gpointer buffer = NULL;
-
+
# ifdef HAVE_GETPWUID_R
struct passwd pwd;
guint bufsize = 64;
gint error;
-
+
do
{
g_free (buffer);
buffer = g_malloc (bufsize);
-
+ errno = 0;
+
# ifdef HAVE_GETPWUID_R_POSIX
- error = getpwuid_r (getuid (), &pwd, buffer, bufsize, &pw);
+ error = getpwuid_r (getuid (), &pwd, buffer, bufsize, &pw);
error = error < 0 ? errno : error;
# else /* !HAVE_GETPWUID_R_POSIX */
+# ifdef _AIX
+ error = getpwuid_r (getuid (), &pwd, buffer, bufsize);
+ pw = error == 0 ? &pwd : NULL;
+# else /* !_AIX */
pw = getpwuid_r (getuid (), &pwd, buffer, bufsize);
error = pw ? 0 : errno;
+# endif /* !_AIX */
# endif /* !HAVE_GETPWUID_R_POSIX */
-
- bufsize *= 2;
- }
- while (error == ERANGE);
-
- if (error)
- g_warning ("getpwuid_r(): failed due to: %s", g_strerror (error));
-
-# else /* !HAVE_GETPWUID_R */
-
- setpwent ();
- pw = getpwuid (getuid ());
- endpwent ();
-
+
+ if (!pw)
+ {
+ /* 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;
+ }
+ }
+ while (!pw);
# endif /* !HAVE_GETPWUID_R */
+ if (!pw)
+ {
+ setpwent ();
+ pw = getpwuid (getuid ());
+ endpwent ();
+ }
if (pw)
{
g_user_name = g_strdup (pw->pw_name);
@@ -485,9 +515,9 @@ g_get_any_init (void)
}
g_free (buffer);
}
-
+
#else /* !HAVE_PWD_H */
-
+
# ifdef NATIVE_WIN32
{
guint len = 17;
@@ -500,14 +530,32 @@ g_get_any_init (void)
}
}
# endif /* NATIVE_WIN32 */
-
+
#endif /* !HAVE_PWD_H */
-
+
+#ifdef __EMX__
+ /* change '\\' in %HOME% to '/' */
+ g_strdelimit (g_home_dir, "\\",'/');
+#endif
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*
@@ -603,7 +651,7 @@ gint
g_direct_equal (gconstpointer v1,
gconstpointer v2)
{
- return GPOINTER_TO_UINT (v1) == GPOINTER_TO_UINT (v2);
+ return v1 == v2;
}
gint