MWCC/command_line/CmdLine/Src/OSLib/StringExtras.c

50 lines
829 B
C
Raw Normal View History

#include "oslib.h"
char *strcatn(char *d, const char *s, SInt32 max) {
2022-10-12 17:07:57 +00:00
char *p;
2022-10-12 17:07:57 +00:00
p = d + strlen(d);
while (*s && (p - d) + 1 < max)
*(p++) = *(s++);
*p = 0;
return d;
}
char *strcpyn(char *d, const char *s, SInt32 len, SInt32 max) {
2022-10-12 17:07:57 +00:00
char *p;
p = d;
while (len-- && *s && (p - d) + 1 < max)
*(p++) = *(s++);
2022-10-12 17:07:57 +00:00
*p = 0;
return d;
}
int ustrcmp(const char *src, const char *dst) {
2022-10-12 17:07:57 +00:00
int x;
2022-10-12 17:07:57 +00:00
do {
x = tolower(*src) - tolower(*(dst++));
if (x)
return x;
} while (*(src++));
return 0;
}
int ustrncmp(const char *src, const char *dst, UInt32 len) {
2022-10-12 17:07:57 +00:00
int x;
while (len--) {
x = tolower(*src) - tolower(*(dst++));
if (x)
return x;
if (!*(src++))
return 0;
}
2022-10-12 17:07:57 +00:00
return 0;
}