From: Alejandro Colomar Date: Fri, 24 Oct 2025 10:09:55 +0000 (+0200) Subject: lib/utmp.c: ttyname_ra(): Add macro X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9bf3ddc8df3cf8a05af07e53d9777b1dbf222783;p=thirdparty%2Fshadow.git lib/utmp.c: ttyname_ra(): Add macro And use it instead of its pattern. This macro enforces correct use of ttyname_r(3) with arrays. Reviewed-by: Serge Hallyn Signed-off-by: Alejandro Colomar --- diff --git a/lib/utmp.c b/lib/utmp.c index 98348583e..6074de3d5 100644 --- a/lib/utmp.c +++ b/lib/utmp.c @@ -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); }