From: Alejandro Colomar Date: Tue, 2 Jul 2024 14:16:29 +0000 (+0200) Subject: lib/port.c: getttyuser(): Use pointer arithmetic to simplify X-Git-Tag: 4.17.0-rc1~135 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b4b4ff633a5c1dec33a9dadaa21731b7609cb256;p=thirdparty%2Fshadow.git lib/port.c: getttyuser(): Use pointer arithmetic to simplify Signed-off-by: Alejandro Colomar --- diff --git a/lib/port.c b/lib/port.c index 5cf34ddc9..60ec920bd 100644 --- a/lib/port.c +++ b/lib/port.c @@ -320,33 +320,33 @@ next: * entries are treated as an ordered list. */ -static struct port *getttyuser (const char *tty, const char *user) +static struct port * +getttyuser(const char *tty, const char *user) { - int i, j; - struct port *port; + struct port *port; + + setportent(); - setportent (); + while ((port = getportent()) != NULL) { + char **ptn; + char **ptu; - while ((port = getportent ()) != NULL) { - for (i = 0; NULL != port->pt_names[i]; i++) { - if (portcmp (port->pt_names[i], tty) == 0) { + for (ptn = port->pt_names; *ptn != NULL; ptn++) { + if (portcmp(*ptn, tty) == 0) break; - } } - if (port->pt_names[i] == 0) { + if (*ptn == NULL) continue; - } - for (j = 0; NULL != port->pt_users[j]; j++) { - if ( (strcmp (user, port->pt_users[j]) == 0) - || (strcmp (port->pt_users[j], "*") == 0)) - { + for (ptu = port->pt_users; *ptu != NULL; ptu++) { + if (strcmp(*ptu, user) == 0) + goto end; + if (strcmp(*ptu, "*") == 0) goto end; - } } } end: - endportent (); + endportent(); return port; }