mirror of
https://github.com/xzeldon/htop.git
synced 2024-12-24 15:15:44 +00:00
XUtils: move implementation of String_contains_i out of header file
The function strcasestr(3) is only available if _GNU_SOURCE is defined. If any file includes <string.h> before declaring _GNU_SOURCE, e.g by including "config.h", compilation fails with the following error: In file included from ColumnsPanel.c:8: In file included from ./ColumnsPanel.h:12: In file included from ./Panel.h:13: In file included from ./CRT.h:16: In file included from ./Settings.h:17: In file included from ./Process.h:15: In file included from ./Object.h:17: ./XUtils.h:42:11: error: implicit declaration of function 'strcasestr' is invalid in C99 [-Werror,-Wimplicit-function-declaration] return strcasestr(s1, s2) != NULL; ^ ./XUtils.h:42:11: note: did you mean 'strcasecmp'? /usr/include/strings.h:116:12: note: 'strcasecmp' declared here extern int strcasecmp (const char *__s1, const char *__s2) ^ Move the implementation to avoid unnecessary includes. Since LTO is quite common and stable performance should not be impacted if used.
This commit is contained in:
parent
a18018ed48
commit
c243db0b2c
4
XUtils.c
4
XUtils.c
@ -78,6 +78,10 @@ void* xReallocArray(void* ptr, size_t nmemb, size_t size) {
|
||||
return xRealloc(ptr, nmemb * size);
|
||||
}
|
||||
|
||||
inline bool String_contains_i(const char* s1, const char* s2) {
|
||||
return strcasestr(s1, s2) != NULL;
|
||||
}
|
||||
|
||||
char* String_cat(const char* s1, const char* s2) {
|
||||
const size_t l1 = strlen(s1);
|
||||
const size_t l2 = strlen(s2);
|
||||
|
5
XUtils.h
5
XUtils.h
@ -13,7 +13,6 @@ in the source distribution for its full text.
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h> // IWYU pragma: keep
|
||||
#include <string.h> // IWYU pragma: keep
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "Compat.h"
|
||||
#include "Macros.h"
|
||||
@ -39,9 +38,7 @@ static inline bool String_startsWith(const char* s, const char* match) {
|
||||
return strncmp(s, match, strlen(match)) == 0;
|
||||
}
|
||||
|
||||
static inline bool String_contains_i(const char* s1, const char* s2) {
|
||||
return strcasestr(s1, s2) != NULL;
|
||||
}
|
||||
bool String_contains_i(const char* s1, const char* s2);
|
||||
|
||||
static inline bool String_eq(const char* s1, const char* s2) {
|
||||
return strcmp(s1, s2) == 0;
|
||||
|
Loading…
Reference in New Issue
Block a user