]> Savannah Git Hosting - gnulib.git/commitdiff
readutmp: Trivial simplification.
authorBruno Haible <bruno@clisp.org>
Tue, 1 Aug 2023 10:58:20 +0000 (12:58 +0200)
committerBruno Haible <bruno@clisp.org>
Tue, 1 Aug 2023 19:19:51 +0000 (21:19 +0200)
* lib/readutmp.c (extract_trimmed_name): Use constant UT_USER_SIZE.

ChangeLog
lib/readutmp.c

index 48dbeae60bea0820b4fc60eebde9fac7e5927861..a96252f2a0b1c14eef05cc179d89cc5e6958d62a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2023-08-01  Bruno Haible  <bruno@clisp.org>
+
+       readutmp: Trivial simplification.
+       * lib/readutmp.c (extract_trimmed_name): Use constant UT_USER_SIZE.
+
 2023-07-31  Bruno Haible  <bruno@clisp.org>
 
        readutmp tests: Show also the ut_line field.
index 6a5509054e001fef98af840cc40d6fed00aefc41..34b96d999e7f4b9f79da3c4043b8902f5c88212b 100644 (file)
@@ -48,12 +48,12 @@ extract_trimmed_name (const STRUCT_UTMP *ut)
 {
   char *p, *trimmed_name;
 
-  trimmed_name = xmalloc (sizeof (UT_USER (ut)) + 1);
-  strncpy (trimmed_name, UT_USER (ut), sizeof (UT_USER (ut)));
+  trimmed_name = xmalloc (UT_USER_SIZE + 1);
+  strncpy (trimmed_name, UT_USER (ut), UT_USER_SIZE);
   /* Append a trailing NUL.  Some systems pad names shorter than the
      maximum with spaces, others pad with NULs.  Remove any trailing
      spaces.  */
-  trimmed_name[sizeof (UT_USER (ut))] = '\0';
+  trimmed_name[UT_USER_SIZE] = '\0';
   for (p = trimmed_name + strlen (trimmed_name);
        trimmed_name < p && p[-1] == ' ';
        *--p = '\0')