strcmp(3) would be legitimate for sorting strings.
strncmp(3)
- Use STRNEQ(), or strpfx(), or else, depending on what you want.
+ Use strneq_a(), or strpfx(), or else,
+ depending on what you want.
The return value of strncmp(3) is confusing,
and it is unclear the purpose of its use when you read it.
n/
strneq()
Return true if a [[gnu::nonstring]] is equal to a string.
- STRNEQ()
+ strneq_a()
Like strneq(), but takes an array.
strnpfx() // Unimplemented
#include "sizeof.h"
-#define STRNEQ(strn, s) strneq(strn, s, countof(strn))
+#define strneq_a(strn, s) strneq(strn, s, countof(strn))
ATTR_STRING(2)
if (utent->ut_type != USER_PROCESS) {
continue;
}
- if (!STRNEQ(utent->ut_user, name))
+ if (!strneq_a(utent->ut_user, name))
continue;
if (kill (utent->ut_pid, 0) != 0) {
ut = get_current_utmp(main_pid);
#if defined(HAVE_STRUCT_UTMPX_UT_HOST)
- if ((ut != NULL) && !STRNEQ(ut->ut_host, "")) {
+ if ((ut != NULL) && !strneq_a(ut->ut_host, "")) {
*out = xstrndup_a(ut->ut_host);
} else {
*out = NULL;
if (NULL != host && !streq(host, ""))
hostname = xstrdup(host);
#if defined(HAVE_STRUCT_UTMPX_UT_HOST)
- else if (NULL != ut && !STRNEQ(ut->ut_host, ""))
+ else if (NULL != ut && !strneq_a(ut->ut_host, ""))
hostname = xstrndup_a(ut->ut_host);
#endif
if (USER_PROCESS != ut->ut_type) {
continue;
}
- if (STRNEQ(ut->ut_user, ""))
+ if (strneq_a(ut->ut_user, ""))
continue;
- if (!STRNEQ(ut->ut_user, name))
+ if (!strneq_a(ut->ut_user, name))
continue;
count++;
printf (_("Last login: %s on %s"),
ptime, ll.ll_line);
#ifdef HAVE_LL_HOST /* __linux__ || SUN4 */
- if (!STRNEQ(ll.ll_host, "")) {
+ if (!strneq_a(ll.ll_host, "")) {
printf (_(" from %.*s"),
(int) sizeof ll.ll_host, ll.ll_host);
}
if (ut->ut_type != USER_PROCESS) {
continue;
}
- if (STRNEQ(ut->ut_user, ""))
+ if (strneq_a(ut->ut_user, ""))
continue;
if (check_login (ut)) {