]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lib/utmp.c: ttyname_ra(): Add macro
authorAlejandro Colomar <alx@kernel.org>
Fri, 24 Oct 2025 10:09:55 +0000 (12:09 +0200)
committerAlejandro Colomar <foss+github@alejandro-colomar.es>
Tue, 4 Nov 2025 01:56:30 +0000 (02:56 +0100)
And use it instead of its pattern.

This macro enforces correct use of ttyname_r(3) with arrays.

Reviewed-by: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
lib/utmp.c

index 98348583e028e843b4c48c391dfca877b0ef9be2..6074de3d5ef1dbfd4d959754e2d390558bbe9cb0 100644 (file)
@@ -44,6 +44,9 @@
 
 #define UTX_LINESIZE  countof(memberof(struct utmpx, ut_line))
 
+// ttyname_ra - tty name re-entrant array
+#define ttyname_ra(fd, buf)  ttyname_r(fd, buf, countof(buf))
+
 
 /*
  * is_my_tty -- determine if "tty" is the same TTY stdin is using
@@ -59,7 +62,7 @@ is_my_tty(const char tty[UTX_LINESIZE])
                strcpy (full_tty, "/dev/");
        strncat(full_tty, tty, UTX_LINESIZE);
 
-       if (ttyname_r(STDIN_FILENO, my_tty, countof(my_tty)) != 0) {
+       if (ttyname_ra(STDIN_FILENO, my_tty) != 0) {
                (void) puts (_("Unable to determine your tty name."));
                exit (EXIT_FAILURE);
        }