hirc

IRC client
Log | Files | Refs

commit 0240d7f79459102562713d0e2fdb8f1355fdf44b
parent 9392dc9bac45d517228ff8d806a36608aa7c1e7f
Author: hhvn <dev@hhvn.uk>
Date:   Wed, 13 Apr 2022 12:24:32 +0100

strcmp_n as an actual function

Diffstat:
Msrc/hirc.h | 2+-
Msrc/str.c | 13+++++++++++++
2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/src/hirc.h b/src/hirc.h @@ -27,7 +27,6 @@ #define INPUT_HIST_MAX 64 #define HIST_MAX 8192 /* real maximum = HIST_MAX * (channels + servers + queries) */ -#define strcmp_n(s1, s2) (s1 == s2 ? 0 : (s1 ? s2 ? strcmp(s1, s2) : -1 : -1)) #define CONSTLEN(str) ((size_t)((sizeof(str) - sizeof(str[0])) / sizeof(str[0]))) /* compile-time char/wchar_t literals */ @@ -53,6 +52,7 @@ int ircprintf(struct Server *server, char *format, ...); /* str.c */ char * homepath(char *path); +int strcmp_n(const char *s1, const char *s2); char * struntil(char *str, char until); int strisnum(char *str, int allowneg); char * strntok(char *str, char *sep, int n); diff --git a/src/str.c b/src/str.c @@ -19,6 +19,7 @@ #include <string.h> #include <stdlib.h> +#include <limits.h> #include "hirc.h" char * @@ -33,6 +34,18 @@ homepath(char *path) { return path; } +int +strcmp_n(const char *s1, const char *s2) { + if (!s1 && !s2) + return 0; + else if (!s1) + return INT_MIN; + else if (!s2) + return INT_MAX; + else + return strcmp(s1, s2); +} + char * struntil(char *str, char until) { static char ret[1024];