From 11ea0ea133a75f0b7280ce89e3a223ca17be542c Mon Sep 17 00:00:00 2001 From: Sebastian Wilhelmi Date: Thu, 21 Jan 1999 09:06:28 +0000 Subject: [PATCH] Changed error handling again, as the error is not always set in errno, it 1999-01-21 Sebastian Wilhelmi * gutils.c (g_get_any_init): Changed error handling again, as the error is not always set in errno, it is the return value on some systems. What an evil world. --- ChangeLog | 6 ++++++ ChangeLog.pre-2-0 | 6 ++++++ ChangeLog.pre-2-10 | 6 ++++++ ChangeLog.pre-2-12 | 6 ++++++ ChangeLog.pre-2-2 | 6 ++++++ ChangeLog.pre-2-4 | 6 ++++++ ChangeLog.pre-2-6 | 6 ++++++ ChangeLog.pre-2-8 | 6 ++++++ glib/gutils.c | 20 ++++++++++++-------- gutils.c | 20 ++++++++++++-------- 10 files changed, 72 insertions(+), 16 deletions(-) diff --git a/ChangeLog b/ChangeLog index 35e46c7..d483b2c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +1999-01-21 Sebastian Wilhelmi + + * gutils.c (g_get_any_init): Changed error handling again, as the + error is not always set in errno, it is the return value on some + systems. What an evil world. + Thu Jan 21 05:35:20 1999 Tor Lillqvist * gstrfuncs.c: Include signal.h only when the signal names will be diff --git a/ChangeLog.pre-2-0 b/ChangeLog.pre-2-0 index 35e46c7..d483b2c 100644 --- a/ChangeLog.pre-2-0 +++ b/ChangeLog.pre-2-0 @@ -1,3 +1,9 @@ +1999-01-21 Sebastian Wilhelmi + + * gutils.c (g_get_any_init): Changed error handling again, as the + error is not always set in errno, it is the return value on some + systems. What an evil world. + Thu Jan 21 05:35:20 1999 Tor Lillqvist * gstrfuncs.c: Include signal.h only when the signal names will be diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 35e46c7..d483b2c 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,9 @@ +1999-01-21 Sebastian Wilhelmi + + * gutils.c (g_get_any_init): Changed error handling again, as the + error is not always set in errno, it is the return value on some + systems. What an evil world. + Thu Jan 21 05:35:20 1999 Tor Lillqvist * gstrfuncs.c: Include signal.h only when the signal names will be diff --git a/ChangeLog.pre-2-12 b/ChangeLog.pre-2-12 index 35e46c7..d483b2c 100644 --- a/ChangeLog.pre-2-12 +++ b/ChangeLog.pre-2-12 @@ -1,3 +1,9 @@ +1999-01-21 Sebastian Wilhelmi + + * gutils.c (g_get_any_init): Changed error handling again, as the + error is not always set in errno, it is the return value on some + systems. What an evil world. + Thu Jan 21 05:35:20 1999 Tor Lillqvist * gstrfuncs.c: Include signal.h only when the signal names will be diff --git a/ChangeLog.pre-2-2 b/ChangeLog.pre-2-2 index 35e46c7..d483b2c 100644 --- a/ChangeLog.pre-2-2 +++ b/ChangeLog.pre-2-2 @@ -1,3 +1,9 @@ +1999-01-21 Sebastian Wilhelmi + + * gutils.c (g_get_any_init): Changed error handling again, as the + error is not always set in errno, it is the return value on some + systems. What an evil world. + Thu Jan 21 05:35:20 1999 Tor Lillqvist * gstrfuncs.c: Include signal.h only when the signal names will be diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index 35e46c7..d483b2c 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,3 +1,9 @@ +1999-01-21 Sebastian Wilhelmi + + * gutils.c (g_get_any_init): Changed error handling again, as the + error is not always set in errno, it is the return value on some + systems. What an evil world. + Thu Jan 21 05:35:20 1999 Tor Lillqvist * gstrfuncs.c: Include signal.h only when the signal names will be diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index 35e46c7..d483b2c 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,9 @@ +1999-01-21 Sebastian Wilhelmi + + * gutils.c (g_get_any_init): Changed error handling again, as the + error is not always set in errno, it is the return value on some + systems. What an evil world. + Thu Jan 21 05:35:20 1999 Tor Lillqvist * gstrfuncs.c: Include signal.h only when the signal names will be diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index 35e46c7..d483b2c 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,9 @@ +1999-01-21 Sebastian Wilhelmi + + * gutils.c (g_get_any_init): Changed error handling again, as the + error is not always set in errno, it is the return value on some + systems. What an evil world. + Thu Jan 21 05:35:20 1999 Tor Lillqvist * gstrfuncs.c: Include signal.h only when the signal names will be diff --git a/glib/gutils.c b/glib/gutils.c index c5b7e24..5ca27b7 100644 --- a/glib/gutils.c +++ b/glib/gutils.c @@ -443,26 +443,30 @@ g_get_any_init (void) while (TRUE) { int error = 0; + errno = 0; buffer = g_realloc (buffer, bufsize); # ifdef HAVE_GETPWUID_R_POSIX error = getpwuid_r (getuid (), &pwd, buffer, bufsize, &pw); - if (error == 0) - break; + if (errno == 0) /* The errorcode is in error (might be 0, too) */ + errno = error; # else /* HAVE_GETPWUID_R_POSIX */ pw = getpwuid_r (getuid (), &pwd, buffer, bufsize); - if (pw) - break; # endif /* HAVE_GETPWUID_R_POSIX */ - error = errno; - if (error != ERANGE) + if (errno == 0) + { + g_assert (pw); + break; + } + + if (errno != ERANGE) g_error ("Could not read account information: %s", - g_strerror (error)); + g_strerror (errno)); bufsize *= 2; } # else /* HAVE_GETPWUID_R */ # if defined(G_THREADS_ENABLED) && defined(__GNUC__) # warning "the `g_get_(user_name|real_name|home_dir|tmp_dir)'" -# warning "functions will not be MT-safe at their first call" +# warning "functions will not be MT-safe during their first call" # warning "because there is no `getpwuid_r' on your system." # endif setpwent (); diff --git a/gutils.c b/gutils.c index c5b7e24..5ca27b7 100644 --- a/gutils.c +++ b/gutils.c @@ -443,26 +443,30 @@ g_get_any_init (void) while (TRUE) { int error = 0; + errno = 0; buffer = g_realloc (buffer, bufsize); # ifdef HAVE_GETPWUID_R_POSIX error = getpwuid_r (getuid (), &pwd, buffer, bufsize, &pw); - if (error == 0) - break; + if (errno == 0) /* The errorcode is in error (might be 0, too) */ + errno = error; # else /* HAVE_GETPWUID_R_POSIX */ pw = getpwuid_r (getuid (), &pwd, buffer, bufsize); - if (pw) - break; # endif /* HAVE_GETPWUID_R_POSIX */ - error = errno; - if (error != ERANGE) + if (errno == 0) + { + g_assert (pw); + break; + } + + if (errno != ERANGE) g_error ("Could not read account information: %s", - g_strerror (error)); + g_strerror (errno)); bufsize *= 2; } # else /* HAVE_GETPWUID_R */ # if defined(G_THREADS_ENABLED) && defined(__GNUC__) # warning "the `g_get_(user_name|real_name|home_dir|tmp_dir)'" -# warning "functions will not be MT-safe at their first call" +# warning "functions will not be MT-safe during their first call" # warning "because there is no `getpwuid_r' on your system." # endif setpwent (); -- 2.7.4