]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lib/port.c: getportent(): Remove obvious comments
authorAlejandro Colomar <alx@kernel.org>
Tue, 2 Jul 2024 12:26:19 +0000 (14:26 +0200)
committerAlejandro Colomar <alx@kernel.org>
Sun, 14 Jul 2024 22:55:59 +0000 (00:55 +0200)
And do some style changes on the corresponding code.

For fixing cherry-pick conflicts, this also includes (minimal) changes
from:

-  964df6ed6ed6 ("lib/, src/: Use strchrnul(3) instead of its pattern")
   <https://github.com/shadow-maint/shadow/pull/991>

-  59e5eef38f89 ("contrib, lib/, src/, tests/: Use stpcpy(3) instead of its pattern")
   <https://github.com/shadow-maint/shadow/pull/1035>

Signed-off-by: Alejandro Colomar <alx@kernel.org>
Cherry-picked-from: f1f82c21054b ("lib/port.c: getportent(): Remove obvious comments")
Link: <https://github.com/shadow-maint/shadow/pull/1037>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
lib/port.c

index 4b933333e1e8604c13c772c1d346494712a1c2bc..bda194446b399bea53e2fa669632ceb6be2b6293 100644 (file)
@@ -128,19 +128,14 @@ static struct port *getportent (void)
         */
 
 next:
-
-       /*
-        * Get the next line and remove optional trailing '\n'.
-        * Lines which begin with '#' are all ignored.
-        */
-
-       if (fgets (buf, sizeof buf, ports) == 0) {
+       if (fgets(buf, sizeof(buf), ports) == NULL) {
                errno = saveerr;
-               return 0;
+               return NULL;
        }
-       if ('#' == buf[0]) {
+       if ('#' == buf[0])
                goto next;
-       }
+
+       stpcpy(strchrnul(buf, '\n'), "");
 
        /*
         * Get the name of the TTY device.  It is the first colon
@@ -149,8 +144,6 @@ next:
         * TTY devices.
         */
 
-       buf[strcspn (buf, "\n")] = 0;
-
        port.pt_names = ttys;
        for (cp = buf, j = 0; j < PORT_TTY; j++) {
                port.pt_names[j] = cp;