]> git.ipfire.org Git - thirdparty/shadow.git/commit
Simplify is_my_tty()
authorAlejandro Colomar <alx@kernel.org>
Sun, 12 Mar 2023 23:59:22 +0000 (00:59 +0100)
committerIker Pedrosa <ikerpedrosam@gmail.com>
Tue, 28 Mar 2023 11:00:38 +0000 (13:00 +0200)
commit1d7d94ed7dc6736b17581d625066114a93252ff5
tree173e93422f500002c31f1a6af9f16ac9894041c1
parente27ca530912c9386f2a60656b4a2b713521f82b1
Simplify is_my_tty()

This commit will serve to document why we shouldn't worry about the
truncation in the call to strlcpy(3).  Since we have one more byte in
tmptty than in full_tty, truncation will produce a string that is at
least one byte longer than full_tty.  Such a string could never compare
equal, so we're actually handling the truncation in a clever way.  Maybe
too clever, but that's why I'm documenting it here.

Now, about the simplification itself:

Since we made sure that both full_tty and tmptty are null-terminated, we
can call strcmp(3) instead of strncmp(3).  We can also simplify the
return logic avoiding one branch.

Cc: Paul Eggert <eggert@cs.ucla.edu>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
libmisc/utmp.c