[review v2] Use getpwuid_r instead of getpwuid when available
Tom Tromey (Code Review)
gerrit@gnutoolchain-gerrit.osci.io
Mon Nov 11 14:57:00 GMT 2019
Tom Tromey has posted comments on this change.
Change URL: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/485
......................................................................
Patch Set 2:
(1 comment)
Thank you for this and the other "_r" patches.
I think this one can be hugely simplified, see below.
| --- gdb/nat/linux-osdata.c
| +++ gdb/nat/linux-osdata.c
| @@ -204,11 +204,18 @@ /* Finds the user name for the user UID and copies it into USER. At
|
| static void
| user_from_uid (char *user, int maxlen, uid_t uid)
| {
| - struct passwd *pwentry = getpwuid (uid);
| + struct passwd *pwentry;
| +#ifdef HAVE_GETPWUID_R
| + char buf[1024];
| + struct passwd pwd;
| + getpwuid_r (uid, &pwd, buf, sizeof (buf), &pwentry);
PS2, Line 212:
I think that, because the only use is in a "nat" file,
and because we know this is always available on Linux,
then there's no need for the configury. We can just call
this unconditionally.
| +#else
| + pwentry = getpwuid (uid);
| +#endif
|
| if (pwentry)
| {
| strncpy (user, pwentry->pw_name, maxlen);
| /* Ensure that the user name is null-terminated. */
| user[maxlen - 1] = '\0';
--
Gerrit-Project: binutils-gdb
Gerrit-Branch: master
Gerrit-Change-Id: I587359267f8963ef1da6ba0223a1525807a721de
Gerrit-Change-Number: 485
Gerrit-PatchSet: 2
Gerrit-Owner: Christian Biesinger <cbiesinger@google.com>
Gerrit-CC: Tom Tromey <tromey@sourceware.org>
Gerrit-Comment-Date: Mon, 11 Nov 2019 14:57:19 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Gerrit-MessageType: comment
More information about the Gdb-patches
mailing list