Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 18 additions & 11 deletions cmake/re-config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,19 @@ if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
FORCE)
endif()

if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
list(APPEND RE_DEFINITIONS DARWIN)
elseif(${CMAKE_SYSTEM_NAME} MATCHES "iOS")
list(APPEND RE_DEFINITIONS DARWIN)
elseif(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
list(APPEND RE_DEFINITIONS FREEBSD)
elseif(${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD")
list(APPEND RE_DEFINITIONS OPENBSD)
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
list(APPEND RE_DEFINITIONS LINUX)
SET(CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS} -D_GNU_SOURCE")
endif()

check_symbol_exists(LIBRESSL_VERSION_NUMBER "${OPENSSL_INCLUDE_DIR}/openssl/opensslv.h" HAVE_LIBRESSL)
if(USE_TLS1_3_PHA AND NOT HAVE_LIBRESSL AND NOT USE_MBEDTLS AND OPENSSL_FOUND)
list(APPEND RE_DEFINITIONS HAVE_TLS1_3_POST_HANDSHAKE_AUTH)
Expand Down Expand Up @@ -80,6 +93,11 @@ else()
set(Backtrace_LIBRARIES)
endif()

check_symbol_exists(memrchr "string.h" HAVE_MEMRCHR)
if(HAVE_MEMRCHR)
list(APPEND RE_DEFINITIONS HAVE_MEMRCHR)
endif()

check_function_exists(thrd_create HAVE_THREADS_FUN)
check_include_file(threads.h HAVE_THREADS_H)
if(HAVE_THREADS_FUN AND HAVE_THREADS_H)
Expand Down Expand Up @@ -215,17 +233,6 @@ if(USE_TRACE)
)
endif()

if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
list(APPEND RE_DEFINITIONS DARWIN)
elseif(${CMAKE_SYSTEM_NAME} MATCHES "iOS")
list(APPEND RE_DEFINITIONS DARWIN)
elseif(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
list(APPEND RE_DEFINITIONS FREEBSD)
elseif(${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD")
list(APPEND RE_DEFINITIONS OPENBSD)
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
list(APPEND RE_DEFINITIONS LINUX)
endif()


list(APPEND RE_DEFINITIONS
Expand Down
30 changes: 14 additions & 16 deletions src/fmt/pl.c
Original file line number Diff line number Diff line change
Expand Up @@ -761,18 +761,10 @@ int pl_casecmp(const struct pl *pl1, const struct pl *pl2)
*/
const char *pl_strchr(const struct pl *pl, char c)
{
const char *p, *end;

if (!pl)
if (!pl_isset(pl))
return NULL;

end = pl->p + pl->l;
for (p = pl->p; p < end; p++) {
if (*p == c)
return p;
}

return NULL;
return memchr(pl->p, c, pl->l);
}


Expand All @@ -786,6 +778,11 @@ const char *pl_strchr(const struct pl *pl, char c)
*/
const char *pl_strrchr(const struct pl *pl, char c)
{
if (!pl_isset(pl))
return NULL;
#if HAVE_MEMRCHR
return memrchr(pl->p, c, pl->l);
#else
const char *p, *end;

if (!pl_isset(pl))
Expand All @@ -798,6 +795,7 @@ const char *pl_strrchr(const struct pl *pl, char c)
}

return NULL;
#endif
}


Expand All @@ -821,13 +819,13 @@ const char *pl_strstr(const struct pl *pl, const char *str)
if (!len)
return pl->p;

for (size_t i = 0; i < pl->l; ++i) {
/*case rest of pl is not long enough*/
if (pl->l - i < len)
return NULL;
const char *p = pl->p;
const char *end = pl->p + pl->l - len;

if (!memcmp(pl->p + i, str, len))
return pl->p + i;
while ((p = memchr(p, *str, (size_t)(end - p) + 1)) != NULL) {
if (!memcmp(p, str, len))
return p;
++p;
}

return NULL;
Expand Down
Loading