aboutsummaryrefslogtreecommitdiffstats
path: root/String.c
diff options
context:
space:
mode:
authorEugene V. Lyubimkin <jackyf@debian.org>2014-05-01 13:16:56 +0300
committerDaniel Lange <DLange@git.local>2016-04-11 13:00:34 +0200
commit43997d37137cc1e4a1a5be654aa16d4992045e34 (patch)
treeb89a3360498e310adb64b337d849ea25aa0e51f0 /String.c
parent51516557d375ac91e0a1a6f0525c3def1d3d79b0 (diff)
parentf75ab6d2c11e8a8e18191b087564aedebbeb96c5 (diff)
downloaddebian_htop-43997d37137cc1e4a1a5be654aa16d4992045e34.tar.gz
debian_htop-43997d37137cc1e4a1a5be654aa16d4992045e34.tar.bz2
debian_htop-43997d37137cc1e4a1a5be654aa16d4992045e34.zip
Imported Debian patch 1.0.3-1debian/1.0.3-1
Diffstat (limited to 'String.c')
-rw-r--r--String.c25
1 files changed, 12 insertions, 13 deletions
diff --git a/String.c b/String.c
index 173932c..cbfd687 100644
--- a/String.c
+++ b/String.c
@@ -16,6 +16,7 @@ in the source distribution for its full text.
/*{
#define String_startsWith(s, match) (strstr((s), (match)) == (s))
+#define String_contains_i(s1, s2) (strcasestr(s1, s2) != NULL)
}*/
char* String_cat(const char* s1, const char* s2) {
@@ -67,7 +68,13 @@ char** String_split(const char* s, char sep, int* n) {
ctr++;
if (ctr == blocks) {
blocks += rate;
- out = (char**) realloc(out, sizeof(char*) * blocks);
+ char** newOut = (char**) realloc(out, sizeof(char*) * blocks);
+ if (newOut) {
+ out = newOut;
+ } else {
+ blocks -= rate;
+ break;
+ }
}
s += size + 1;
}
@@ -78,7 +85,10 @@ char** String_split(const char* s, char sep, int* n) {
out[ctr] = token;
ctr++;
}
- out = realloc(out, sizeof(char*) * (ctr + 1));
+ char** newOut = realloc(out, sizeof(char*) * (ctr + 1));
+ if (newOut) {
+ out = newOut;
+ }
out[ctr] = NULL;
*n = ctr;
return out;
@@ -91,17 +101,6 @@ void String_freeArray(char** s) {
free(s);
}
-int String_contains_i(const char* s, const char* match) {
- int lens = strlen(s);
- int lenmatch = strlen(match);
- for (int i = 0; i < lens-lenmatch; i++) {
- if (strncasecmp(s, match, strlen(match)) == 0)
- return 1;
- s++;
- }
- return 0;
-}
-
char* String_getToken(const char* line, const unsigned short int numMatch) {
const unsigned short int len = strlen(line);
char inWord = 0;

© 2014-2024 Faster IT GmbH | imprint | privacy policy