cleaned up the errno mess for GETPWUID. we especially don't want to
authorTim Janik <timj@gtk.org>
Sat, 23 Jan 1999 02:16:11 +0000 (02:16 +0000)
committerTim Janik <timj@src.gnome.org>
Sat, 23 Jan 1999 02:16:11 +0000 (02:16 +0000)
Sat Jan 23 02:14:28 1999  Tim Janik  <timj@gtk.org>

        * gutils.c (g_get_any_init): cleaned up the errno mess for
        GETPWUID. we especially don't want to g_error() out here!
        the warning for G_THREADS_ENABLED and !HAVE_GETPWUID_R isn't
        gcc related.
        if !HAVE_PWD_H and !NATIVE_WIN32, g_free the home dir before
        resetting it to NULL, why are we doing this anyways?
        reordered code a bit so we always provide defaults (except
        for g_home_dir).

12 files changed:
ChangeLog
ChangeLog.pre-2-0
ChangeLog.pre-2-10
ChangeLog.pre-2-12
ChangeLog.pre-2-2
ChangeLog.pre-2-4
ChangeLog.pre-2-6
ChangeLog.pre-2-8
glib/gutils.c
gutils.c
testglib.c
tests/testglib.c

index eb3ed4d..fa00202 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+Sat Jan 23 02:14:28 1999  Tim Janik  <timj@gtk.org>
+
+       * gutils.c (g_get_any_init): cleaned up the errno mess for
+       GETPWUID. we especially don't want to g_error() out here!
+       the warning for G_THREADS_ENABLED and !HAVE_GETPWUID_R isn't
+       gcc related.
+       if !HAVE_PWD_H and !NATIVE_WIN32, g_free the home dir before
+       resetting it to NULL, why are we doing this anyways?
+       reordered code a bit so we always provide defaults (except
+       for g_home_dir).
+
 Thu Jan 21 12:40:11 EST 1999  Jeff Garzik  <jgarzik@pobox.com>
 
        * tests/{Makefile.am, string-test.c, strfunc-test.c}:
index eb3ed4d..fa00202 100644 (file)
@@ -1,3 +1,14 @@
+Sat Jan 23 02:14:28 1999  Tim Janik  <timj@gtk.org>
+
+       * gutils.c (g_get_any_init): cleaned up the errno mess for
+       GETPWUID. we especially don't want to g_error() out here!
+       the warning for G_THREADS_ENABLED and !HAVE_GETPWUID_R isn't
+       gcc related.
+       if !HAVE_PWD_H and !NATIVE_WIN32, g_free the home dir before
+       resetting it to NULL, why are we doing this anyways?
+       reordered code a bit so we always provide defaults (except
+       for g_home_dir).
+
 Thu Jan 21 12:40:11 EST 1999  Jeff Garzik  <jgarzik@pobox.com>
 
        * tests/{Makefile.am, string-test.c, strfunc-test.c}:
index eb3ed4d..fa00202 100644 (file)
@@ -1,3 +1,14 @@
+Sat Jan 23 02:14:28 1999  Tim Janik  <timj@gtk.org>
+
+       * gutils.c (g_get_any_init): cleaned up the errno mess for
+       GETPWUID. we especially don't want to g_error() out here!
+       the warning for G_THREADS_ENABLED and !HAVE_GETPWUID_R isn't
+       gcc related.
+       if !HAVE_PWD_H and !NATIVE_WIN32, g_free the home dir before
+       resetting it to NULL, why are we doing this anyways?
+       reordered code a bit so we always provide defaults (except
+       for g_home_dir).
+
 Thu Jan 21 12:40:11 EST 1999  Jeff Garzik  <jgarzik@pobox.com>
 
        * tests/{Makefile.am, string-test.c, strfunc-test.c}:
index eb3ed4d..fa00202 100644 (file)
@@ -1,3 +1,14 @@
+Sat Jan 23 02:14:28 1999  Tim Janik  <timj@gtk.org>
+
+       * gutils.c (g_get_any_init): cleaned up the errno mess for
+       GETPWUID. we especially don't want to g_error() out here!
+       the warning for G_THREADS_ENABLED and !HAVE_GETPWUID_R isn't
+       gcc related.
+       if !HAVE_PWD_H and !NATIVE_WIN32, g_free the home dir before
+       resetting it to NULL, why are we doing this anyways?
+       reordered code a bit so we always provide defaults (except
+       for g_home_dir).
+
 Thu Jan 21 12:40:11 EST 1999  Jeff Garzik  <jgarzik@pobox.com>
 
        * tests/{Makefile.am, string-test.c, strfunc-test.c}:
index eb3ed4d..fa00202 100644 (file)
@@ -1,3 +1,14 @@
+Sat Jan 23 02:14:28 1999  Tim Janik  <timj@gtk.org>
+
+       * gutils.c (g_get_any_init): cleaned up the errno mess for
+       GETPWUID. we especially don't want to g_error() out here!
+       the warning for G_THREADS_ENABLED and !HAVE_GETPWUID_R isn't
+       gcc related.
+       if !HAVE_PWD_H and !NATIVE_WIN32, g_free the home dir before
+       resetting it to NULL, why are we doing this anyways?
+       reordered code a bit so we always provide defaults (except
+       for g_home_dir).
+
 Thu Jan 21 12:40:11 EST 1999  Jeff Garzik  <jgarzik@pobox.com>
 
        * tests/{Makefile.am, string-test.c, strfunc-test.c}:
index eb3ed4d..fa00202 100644 (file)
@@ -1,3 +1,14 @@
+Sat Jan 23 02:14:28 1999  Tim Janik  <timj@gtk.org>
+
+       * gutils.c (g_get_any_init): cleaned up the errno mess for
+       GETPWUID. we especially don't want to g_error() out here!
+       the warning for G_THREADS_ENABLED and !HAVE_GETPWUID_R isn't
+       gcc related.
+       if !HAVE_PWD_H and !NATIVE_WIN32, g_free the home dir before
+       resetting it to NULL, why are we doing this anyways?
+       reordered code a bit so we always provide defaults (except
+       for g_home_dir).
+
 Thu Jan 21 12:40:11 EST 1999  Jeff Garzik  <jgarzik@pobox.com>
 
        * tests/{Makefile.am, string-test.c, strfunc-test.c}:
index eb3ed4d..fa00202 100644 (file)
@@ -1,3 +1,14 @@
+Sat Jan 23 02:14:28 1999  Tim Janik  <timj@gtk.org>
+
+       * gutils.c (g_get_any_init): cleaned up the errno mess for
+       GETPWUID. we especially don't want to g_error() out here!
+       the warning for G_THREADS_ENABLED and !HAVE_GETPWUID_R isn't
+       gcc related.
+       if !HAVE_PWD_H and !NATIVE_WIN32, g_free the home dir before
+       resetting it to NULL, why are we doing this anyways?
+       reordered code a bit so we always provide defaults (except
+       for g_home_dir).
+
 Thu Jan 21 12:40:11 EST 1999  Jeff Garzik  <jgarzik@pobox.com>
 
        * tests/{Makefile.am, string-test.c, strfunc-test.c}:
index eb3ed4d..fa00202 100644 (file)
@@ -1,3 +1,14 @@
+Sat Jan 23 02:14:28 1999  Tim Janik  <timj@gtk.org>
+
+       * gutils.c (g_get_any_init): cleaned up the errno mess for
+       GETPWUID. we especially don't want to g_error() out here!
+       the warning for G_THREADS_ENABLED and !HAVE_GETPWUID_R isn't
+       gcc related.
+       if !HAVE_PWD_H and !NATIVE_WIN32, g_free the home dir before
+       resetting it to NULL, why are we doing this anyways?
+       reordered code a bit so we always provide defaults (except
+       for g_home_dir).
+
 Thu Jan 21 12:40:11 EST 1999  Jeff Garzik  <jgarzik@pobox.com>
 
        * tests/{Makefile.am, string-test.c, strfunc-test.c}:
index 5ca27b7..1a5fad8 100644 (file)
@@ -371,6 +371,7 @@ g_getenv (const gchar *variable)
 #endif
 }
 
+
 G_LOCK_DECLARE_STATIC (g_utils_global);
 
 static gchar   *g_tmp_dir = NULL;
@@ -400,6 +401,7 @@ g_get_any_init (void)
            g_tmp_dir[k-1] = '\0';
        }
 #endif
+
       if (!g_tmp_dir)
        {
 #ifndef NATIVE_WIN32
@@ -428,51 +430,55 @@ g_get_any_init (void)
          g_free (homedrive);
          g_free (homepath);
        }
+#endif /* !NATIVE_WIN32 */
+      
       if (!g_home_dir)
        g_home_dir = g_strdup (g_getenv ("HOME"));
-#else
-      g_home_dir = g_strdup (g_getenv ("HOME"));
-#endif
+      
       
 #ifdef HAVE_PWD_H
       {
-       struct passwd *pw = NULL, pwd;
+       struct passwd *pw = NULL;
        gpointer buffer = NULL;
-       guint bufsize = sizeof (struct passwd);
-#  ifdef HAVE_GETPWUID_R 
-       while (TRUE)
+
+#  ifdef HAVE_GETPWUID_R
+       struct passwd pwd;
+       guint bufsize = 1; // sizeof (struct passwd);
+       gint error;
+
+       do
          {
-           int error = 0;
-           errno = 0;
-           buffer = g_realloc (buffer, bufsize);
+           g_free (buffer);
+           buffer = g_malloc (bufsize);
+
 #    ifdef HAVE_GETPWUID_R_POSIX
            error = getpwuid_r (getuid (), &pwd, buffer, bufsize, &pw);
-           if (errno == 0) /* The errorcode is in error (might be 0, too) */
-             errno = error;
-#    else /* HAVE_GETPWUID_R_POSIX */
+           error = error ? errno : 0;
+#    else /* !HAVE_GETPWUID_R_POSIX */
            pw = getpwuid_r (getuid (), &pwd, buffer, bufsize);
-#    endif /* HAVE_GETPWUID_R_POSIX */
-           if (errno == 0)
-             {
-               g_assert (pw);
-               break;
-             }
-
-           if (errno != ERANGE)
-             g_error ("Could not read account information: %s", 
-                      g_strerror (errno));
+           error = errno;
+#    endif /* !HAVE_GETPWUID_R_POSIX */
+
            bufsize *= 2;
          }
-#  else /* HAVE_GETPWUID_R */
-#    if defined(G_THREADS_ENABLED) && defined(__GNUC__)
+       while (error == ERANGE);
+
+       if (error)
+         g_warning ("getpwuid_r(): failed due to: %s", g_strerror (error));
+
+#  else /* !HAVE_GETPWUID_R */
+
+#    ifdef G_THREADS_ENABLED
 #    warning "the `g_get_(user_name|real_name|home_dir|tmp_dir)'"
 #    warning "functions will not be MT-safe during their first call"
 #    warning "because there is no `getpwuid_r' on your system."
-#    endif
+#    endif /* G_THREADS_ENABLED */
+
        setpwent ();
        pw = getpwuid (getuid ());
        endpwent ();
-#  endif /* HAVE_GETPWUID_R */
+
+#  endif /* !HAVE_GETPWUID_R */
        
        if (pw)
          {
@@ -483,28 +489,32 @@ g_get_any_init (void)
          }
        g_free (buffer);
       }
+
 #else /* !HAVE_PWD_H */
+
 #  ifdef NATIVE_WIN32
       {
        guint len = 17;
+       gchar buffer[17];
        
-       g_user_name = g_new (gchar, len);
-       
-       if (!GetUserName (g_user_name, &len))
+       if (GetUserName (buffer, &len))
          {
-           g_free (g_user_name);
-           g_user_name = g_strdup ("somebody");
-           g_real_name = g_strdup ("Unknown");
+           g_user_name = g_strdup (buffer);
+           g_real_name = g_strdup (buffer);
          }
-       else
-         g_real_name = g_strdup (g_user_name);
       }
 #  else /* !NATIVE_WIN32 */
-      g_user_name = g_strdup ("somebody");
-      g_real_name = g_strdup ("Unknown");
+      /* why are we forcefully setting g_home_dir to NULL here? */
+      g_free (g_home_dir);
       g_home_dir = NULL;
 #  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");
     }  
 }
 
index 5ca27b7..1a5fad8 100644 (file)
--- a/gutils.c
+++ b/gutils.c
@@ -371,6 +371,7 @@ g_getenv (const gchar *variable)
 #endif
 }
 
+
 G_LOCK_DECLARE_STATIC (g_utils_global);
 
 static gchar   *g_tmp_dir = NULL;
@@ -400,6 +401,7 @@ g_get_any_init (void)
            g_tmp_dir[k-1] = '\0';
        }
 #endif
+
       if (!g_tmp_dir)
        {
 #ifndef NATIVE_WIN32
@@ -428,51 +430,55 @@ g_get_any_init (void)
          g_free (homedrive);
          g_free (homepath);
        }
+#endif /* !NATIVE_WIN32 */
+      
       if (!g_home_dir)
        g_home_dir = g_strdup (g_getenv ("HOME"));
-#else
-      g_home_dir = g_strdup (g_getenv ("HOME"));
-#endif
+      
       
 #ifdef HAVE_PWD_H
       {
-       struct passwd *pw = NULL, pwd;
+       struct passwd *pw = NULL;
        gpointer buffer = NULL;
-       guint bufsize = sizeof (struct passwd);
-#  ifdef HAVE_GETPWUID_R 
-       while (TRUE)
+
+#  ifdef HAVE_GETPWUID_R
+       struct passwd pwd;
+       guint bufsize = 1; // sizeof (struct passwd);
+       gint error;
+
+       do
          {
-           int error = 0;
-           errno = 0;
-           buffer = g_realloc (buffer, bufsize);
+           g_free (buffer);
+           buffer = g_malloc (bufsize);
+
 #    ifdef HAVE_GETPWUID_R_POSIX
            error = getpwuid_r (getuid (), &pwd, buffer, bufsize, &pw);
-           if (errno == 0) /* The errorcode is in error (might be 0, too) */
-             errno = error;
-#    else /* HAVE_GETPWUID_R_POSIX */
+           error = error ? errno : 0;
+#    else /* !HAVE_GETPWUID_R_POSIX */
            pw = getpwuid_r (getuid (), &pwd, buffer, bufsize);
-#    endif /* HAVE_GETPWUID_R_POSIX */
-           if (errno == 0)
-             {
-               g_assert (pw);
-               break;
-             }
-
-           if (errno != ERANGE)
-             g_error ("Could not read account information: %s", 
-                      g_strerror (errno));
+           error = errno;
+#    endif /* !HAVE_GETPWUID_R_POSIX */
+
            bufsize *= 2;
          }
-#  else /* HAVE_GETPWUID_R */
-#    if defined(G_THREADS_ENABLED) && defined(__GNUC__)
+       while (error == ERANGE);
+
+       if (error)
+         g_warning ("getpwuid_r(): failed due to: %s", g_strerror (error));
+
+#  else /* !HAVE_GETPWUID_R */
+
+#    ifdef G_THREADS_ENABLED
 #    warning "the `g_get_(user_name|real_name|home_dir|tmp_dir)'"
 #    warning "functions will not be MT-safe during their first call"
 #    warning "because there is no `getpwuid_r' on your system."
-#    endif
+#    endif /* G_THREADS_ENABLED */
+
        setpwent ();
        pw = getpwuid (getuid ());
        endpwent ();
-#  endif /* HAVE_GETPWUID_R */
+
+#  endif /* !HAVE_GETPWUID_R */
        
        if (pw)
          {
@@ -483,28 +489,32 @@ g_get_any_init (void)
          }
        g_free (buffer);
       }
+
 #else /* !HAVE_PWD_H */
+
 #  ifdef NATIVE_WIN32
       {
        guint len = 17;
+       gchar buffer[17];
        
-       g_user_name = g_new (gchar, len);
-       
-       if (!GetUserName (g_user_name, &len))
+       if (GetUserName (buffer, &len))
          {
-           g_free (g_user_name);
-           g_user_name = g_strdup ("somebody");
-           g_real_name = g_strdup ("Unknown");
+           g_user_name = g_strdup (buffer);
+           g_real_name = g_strdup (buffer);
          }
-       else
-         g_real_name = g_strdup (g_user_name);
       }
 #  else /* !NATIVE_WIN32 */
-      g_user_name = g_strdup ("somebody");
-      g_real_name = g_strdup ("Unknown");
+      /* why are we forcefully setting g_home_dir to NULL here? */
+      g_free (g_home_dir);
       g_home_dir = NULL;
 #  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");
     }  
 }
 
index 9601f41..3d63ebb 100644 (file)
@@ -341,6 +341,10 @@ main (int   argc,
   string = g_get_current_dir ();
   g_print ("cwd: %s\n", string);
   g_free (string);
+  g_print ("user: %s\n", g_get_user_name ());
+  g_print ("real: %s\n", g_get_real_name ());
+  g_print ("home: %s\n", g_get_home_dir ());
+  g_print ("tmp-dir: %s\n", g_get_tmp_dir ());
 
   /* type sizes */
   g_print ("checking size of gint8: %d", (int)sizeof (gint8));
index 9601f41..3d63ebb 100644 (file)
@@ -341,6 +341,10 @@ main (int   argc,
   string = g_get_current_dir ();
   g_print ("cwd: %s\n", string);
   g_free (string);
+  g_print ("user: %s\n", g_get_user_name ());
+  g_print ("real: %s\n", g_get_real_name ());
+  g_print ("home: %s\n", g_get_home_dir ());
+  g_print ("tmp-dir: %s\n", g_get_tmp_dir ());
 
   /* type sizes */
   g_print ("checking size of gint8: %d", (int)sizeof (gint8));