From: Raja R Harinath Date: Sun, 24 Jan 1999 03:18:36 +0000 (+0000) Subject: Rewrite not to look at `errno' if library call succeeds, since `errno' is X-Git-Tag: GLIB_1_1_14~15 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c9e92e124e97a12492f7968da91ece6cb9425ed0;p=platform%2Fupstream%2Fglib.git Rewrite not to look at `errno' if library call succeeds, since `errno' is * gutils.c (g_get_any_init) [HAVE_GETPWUID_R]: Rewrite not to look at `errno' if library call succeeds, since `errno' is not reset to 0. --- diff --git a/ChangeLog b/ChangeLog index 4afded5..8e3d620 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +1999-01-23 Raja R Harinath + + * gutils.c (g_get_any_init) [HAVE_GETPWUID_R]: + Rewrite not to look at `errno' if library call succeeds, since + `errno' is not reset to 0. + Sat Jan 23 16:17:04 1999 Tor Lillqvist * glibconfig.h.win32: Update the magic values for diff --git a/ChangeLog.pre-2-0 b/ChangeLog.pre-2-0 index 4afded5..8e3d620 100644 --- a/ChangeLog.pre-2-0 +++ b/ChangeLog.pre-2-0 @@ -1,3 +1,9 @@ +1999-01-23 Raja R Harinath + + * gutils.c (g_get_any_init) [HAVE_GETPWUID_R]: + Rewrite not to look at `errno' if library call succeeds, since + `errno' is not reset to 0. + Sat Jan 23 16:17:04 1999 Tor Lillqvist * glibconfig.h.win32: Update the magic values for diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 4afded5..8e3d620 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,9 @@ +1999-01-23 Raja R Harinath + + * gutils.c (g_get_any_init) [HAVE_GETPWUID_R]: + Rewrite not to look at `errno' if library call succeeds, since + `errno' is not reset to 0. + Sat Jan 23 16:17:04 1999 Tor Lillqvist * glibconfig.h.win32: Update the magic values for diff --git a/ChangeLog.pre-2-12 b/ChangeLog.pre-2-12 index 4afded5..8e3d620 100644 --- a/ChangeLog.pre-2-12 +++ b/ChangeLog.pre-2-12 @@ -1,3 +1,9 @@ +1999-01-23 Raja R Harinath + + * gutils.c (g_get_any_init) [HAVE_GETPWUID_R]: + Rewrite not to look at `errno' if library call succeeds, since + `errno' is not reset to 0. + Sat Jan 23 16:17:04 1999 Tor Lillqvist * glibconfig.h.win32: Update the magic values for diff --git a/ChangeLog.pre-2-2 b/ChangeLog.pre-2-2 index 4afded5..8e3d620 100644 --- a/ChangeLog.pre-2-2 +++ b/ChangeLog.pre-2-2 @@ -1,3 +1,9 @@ +1999-01-23 Raja R Harinath + + * gutils.c (g_get_any_init) [HAVE_GETPWUID_R]: + Rewrite not to look at `errno' if library call succeeds, since + `errno' is not reset to 0. + Sat Jan 23 16:17:04 1999 Tor Lillqvist * glibconfig.h.win32: Update the magic values for diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index 4afded5..8e3d620 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,3 +1,9 @@ +1999-01-23 Raja R Harinath + + * gutils.c (g_get_any_init) [HAVE_GETPWUID_R]: + Rewrite not to look at `errno' if library call succeeds, since + `errno' is not reset to 0. + Sat Jan 23 16:17:04 1999 Tor Lillqvist * glibconfig.h.win32: Update the magic values for diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index 4afded5..8e3d620 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,9 @@ +1999-01-23 Raja R Harinath + + * gutils.c (g_get_any_init) [HAVE_GETPWUID_R]: + Rewrite not to look at `errno' if library call succeeds, since + `errno' is not reset to 0. + Sat Jan 23 16:17:04 1999 Tor Lillqvist * glibconfig.h.win32: Update the magic values for diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index 4afded5..8e3d620 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,9 @@ +1999-01-23 Raja R Harinath + + * gutils.c (g_get_any_init) [HAVE_GETPWUID_R]: + Rewrite not to look at `errno' if library call succeeds, since + `errno' is not reset to 0. + Sat Jan 23 16:17:04 1999 Tor Lillqvist * glibconfig.h.win32: Update the magic values for diff --git a/glib/gutils.c b/glib/gutils.c index 1a5fad8..36ab275 100644 --- a/glib/gutils.c +++ b/glib/gutils.c @@ -443,29 +443,42 @@ g_get_any_init (void) # ifdef HAVE_GETPWUID_R struct passwd pwd; - guint bufsize = 1; // sizeof (struct passwd); + guint bufsize = 1; /* sizeof (struct passwd); */ gint error; - do - { - g_free (buffer); - buffer = g_malloc (bufsize); - + pw_retry: + buffer = g_malloc (bufsize); + # ifdef HAVE_GETPWUID_R_POSIX - error = getpwuid_r (getuid (), &pwd, buffer, bufsize, &pw); - error = error ? errno : 0; + error = getpwuid_r (getuid (), &pwd, buffer, bufsize, &pw); + if (!error) + goto pw_out; + /* error = errno; According to the Solaris man page, + this is not necessary. */ + # else /* !HAVE_GETPWUID_R_POSIX */ - pw = getpwuid_r (getuid (), &pwd, buffer, bufsize); - error = errno; + pw = getpwuid_r (getuid (), &pwd, buffer, bufsize); + if (pw == NULL) + goto pw_out; + error = errno; # endif /* !HAVE_GETPWUID_R_POSIX */ + /* If it came here, there's some kind of error. */ + g_free (buffer); + + if (error == ERANGE) + { bufsize *= 2; + goto pw_retry; } - while (error == ERANGE); - - if (error) - g_warning ("getpwuid_r(): failed due to: %s", g_strerror (error)); + g_warning ("getpwuid_r(): failed due to: %s", g_strerror (error)); + /* Make any subsequent g_free (buffer) a no-op. */ + buffer = NULL; + + pw_out: + ; + # else /* !HAVE_GETPWUID_R */ # ifdef G_THREADS_ENABLED diff --git a/gutils.c b/gutils.c index 1a5fad8..36ab275 100644 --- a/gutils.c +++ b/gutils.c @@ -443,29 +443,42 @@ g_get_any_init (void) # ifdef HAVE_GETPWUID_R struct passwd pwd; - guint bufsize = 1; // sizeof (struct passwd); + guint bufsize = 1; /* sizeof (struct passwd); */ gint error; - do - { - g_free (buffer); - buffer = g_malloc (bufsize); - + pw_retry: + buffer = g_malloc (bufsize); + # ifdef HAVE_GETPWUID_R_POSIX - error = getpwuid_r (getuid (), &pwd, buffer, bufsize, &pw); - error = error ? errno : 0; + error = getpwuid_r (getuid (), &pwd, buffer, bufsize, &pw); + if (!error) + goto pw_out; + /* error = errno; According to the Solaris man page, + this is not necessary. */ + # else /* !HAVE_GETPWUID_R_POSIX */ - pw = getpwuid_r (getuid (), &pwd, buffer, bufsize); - error = errno; + pw = getpwuid_r (getuid (), &pwd, buffer, bufsize); + if (pw == NULL) + goto pw_out; + error = errno; # endif /* !HAVE_GETPWUID_R_POSIX */ + /* If it came here, there's some kind of error. */ + g_free (buffer); + + if (error == ERANGE) + { bufsize *= 2; + goto pw_retry; } - while (error == ERANGE); - - if (error) - g_warning ("getpwuid_r(): failed due to: %s", g_strerror (error)); + g_warning ("getpwuid_r(): failed due to: %s", g_strerror (error)); + /* Make any subsequent g_free (buffer) a no-op. */ + buffer = NULL; + + pw_out: + ; + # else /* !HAVE_GETPWUID_R */ # ifdef G_THREADS_ENABLED