Skip to content

Commit 464bea6

Browse files
lib/, src/: Use str[n]cmp(3) instead of explicit byte comparisons
This is simpler to read, IMO. Signed-off-by: Alejandro Colomar <[email protected]>
1 parent bcc306e commit 464bea6

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

lib/utmp.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -410,12 +410,12 @@ active_sessions_count(const char *name, unsigned long limit)
410410
if (USER_PROCESS != ut->ut_type) {
411411
continue;
412412
}
413-
if ('\0' == ut->ut_user[0]) {
413+
if (strncmp(ut->ut_user, "", NITEMS(ut->ut_user)) == 0)
414414
continue;
415-
}
416-
if (strncmp (name, ut->ut_user, sizeof (ut->ut_user)) != 0) {
415+
416+
if (strncmp(ut->ut_user, name, NITEMS(ut->ut_user)) != 0)
417417
continue;
418-
}
418+
419419
count++;
420420
if (count > limit) {
421421
break;

src/logoutd.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <fcntl.h>
1414
#include <signal.h>
1515
#include <stdio.h>
16+
#include <string.h>
1617
#include <sys/stat.h>
1718
#include <sys/types.h>
1819
#include <utmpx.h>
@@ -178,9 +179,9 @@ main(int argc, char **argv)
178179
if (ut->ut_type != USER_PROCESS) {
179180
continue;
180181
}
181-
if (ut->ut_user[0] == '\0') {
182+
if (strncmp(ut->ut_user, "", NITEMS(ut->ut_user)) == 0)
182183
continue;
183-
}
184+
184185
if (check_login (ut)) {
185186
continue;
186187
}

0 commit comments

Comments
 (0)