[glib/glib-2-70: 1/2] Do not try to access errno after calling getpwnam_r.
- From: Sebastian Dröge <sdroege src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/glib-2-70: 1/2] Do not try to access errno after calling getpwnam_r.
- Date: Tue, 19 Oct 2021 06:25:08 +0000 (UTC)
commit 881b4c215f1e4fbbe21778a9748f87c48babe95d
Author: Gleb Popov <6yearold gmail com>
Date: Tue Sep 28 10:36:42 2021 +0000
Do not try to access errno after calling getpwnam_r.
glib/glib-unix.c | 16 ++++++----------
1 file changed, 6 insertions(+), 10 deletions(-)
---
diff --git a/glib/glib-unix.c b/glib/glib-unix.c
index 9d2877c66..83726da73 100644
--- a/glib/glib-unix.c
+++ b/glib/glib-unix.c
@@ -463,7 +463,6 @@ g_unix_get_passwd_entry (const gchar *user_name,
} *buffer = NULL;
gsize string_buffer_size = 0;
GError *local_error = NULL;
- int errsv = 0;
g_return_val_if_fail (user_name != NULL, NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
@@ -493,10 +492,8 @@ g_unix_get_passwd_entry (const gchar *user_name,
*/
buffer = g_malloc0 (sizeof (*buffer) + string_buffer_size + 6);
- errno = 0;
retval = getpwnam_r (user_name, &buffer->pwd, buffer->string_buffer,
string_buffer_size, &passwd_file_entry);
- errsv = errno;
/* Bail out if: the lookup was successful, or if the user id can't be
* found (should be pretty rare case actually), or if the buffer should be
@@ -508,19 +505,19 @@ g_unix_get_passwd_entry (const gchar *user_name,
break;
}
else if (retval == 0 ||
- errsv == ENOENT || errsv == ESRCH ||
- errsv == EBADF || errsv == EPERM)
+ retval == ENOENT || retval == ESRCH ||
+ retval == EBADF || retval == EPERM)
{
/* Username not found. */
- g_unix_set_error_from_errno (&local_error, errsv);
+ g_unix_set_error_from_errno (&local_error, retval);
break;
}
- else if (errsv == ERANGE)
+ else if (retval == ERANGE)
{
/* Can’t allocate enough string buffer space. */
if (string_buffer_size > 32 * 1024)
{
- g_unix_set_error_from_errno (&local_error, errsv);
+ g_unix_set_error_from_errno (&local_error, retval);
break;
}
@@ -529,7 +526,7 @@ g_unix_get_passwd_entry (const gchar *user_name,
}
else
{
- g_unix_set_error_from_errno (&local_error, errsv);
+ g_unix_set_error_from_errno (&local_error, retval);
break;
}
}
@@ -543,7 +540,6 @@ g_unix_get_passwd_entry (const gchar *user_name,
{
g_clear_pointer (&buffer, g_free);
g_propagate_error (error, g_steal_pointer (&local_error));
- errno = errsv;
}
return (struct passwd *) g_steal_pointer (&buffer);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]