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>
*/
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
* 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;