]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lib/port.c: getttyuser(): Use pointer arithmetic to simplify
authorAlejandro Colomar <alx@kernel.org>
Tue, 2 Jul 2024 14:16:29 +0000 (16:16 +0200)
committerSerge Hallyn <serge@hallyn.com>
Sat, 6 Jul 2024 12:44:02 +0000 (07:44 -0500)
Signed-off-by: Alejandro Colomar <alx@kernel.org>
lib/port.c

index 5cf34ddc973e996291193a306ddf7642d3bbb8a2..60ec920bda5e985457cd90f9226344ad297fcbab 100644 (file)
@@ -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;
 }