diff --git a/CMakeLists.txt b/CMakeLists.txt index 6e7c804..d1abb7c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,14 +1,17 @@ cmake_minimum_required (VERSION 2.6) project (FsLibc) -enable_testing() +option(ENABLE_TESTS "Enable Testings" OFF) +option(ENABLE_STANDARD_SYMNAMES "Enable Standard Symbol Names" OFF) set (FsLibc_VERSION_MAJOR 0) set (FsLibc_VERSION_MINOR 8) -set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -Wall -Wextra -fprofile-arcs -ftest-coverage -DALT_FSLC_NAMES") set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -Wall -Wextra") -set(CMAKE_C_FLAGS_RELCHECK "${CMAKE_C_FLAGS_RELEASE} -DALT_FSLC_NAMES") add_subdirectory(libc) -add_subdirectory(tests) + +if(ENABLE_TESTS) + enable_testing() + add_subdirectory(tests) +endif() diff --git a/libc/CMakeLists.txt b/libc/CMakeLists.txt index d91db9d..3162033 100644 --- a/libc/CMakeLists.txt +++ b/libc/CMakeLists.txt @@ -2,8 +2,11 @@ file(GLOB fslc_SRC src/*.c) file(GLOB fslc_INC include/fslc/*.h) file(GLOB fslc_SINC include/*.h) -include_directories(include/fslc) add_library(fslc ${fslc_SRC}) +target_include_directories(fslc PUBLIC include/fslc) +if(NOT ENABLE_STANDARD_SYMNAMES) + target_compile_definitions(fslc PUBLIC ALT_FSLC_NAMES) +endif() install(TARGETS fslc DESTINATION lib) install(FILES ${fslc_SINC} DESTINATION include) diff --git a/libc/include/fslc/fslc_string.h b/libc/include/fslc/fslc_string.h index a869054..c678b6d 100644 --- a/libc/include/fslc/fslc_string.h +++ b/libc/include/fslc/fslc_string.h @@ -16,9 +16,11 @@ #define fslc_strncmp strncmp #define fslc_strchr strchr #define fslc_strstr strstr +#define fslc_strrstr strrstr #define fslc_strpbrk strpbrk #define fslc_strspn strspn #define fslc_strtok_r strtok_r +#define fslc_strcat strcat #endif /* ALT_FSLC_NAMES */ @@ -38,9 +40,11 @@ extern "C" { int fslc_strncmp(const char *str1, const char *str2, size_t num); char *fslc_strchr(const char *str, int c); char *fslc_strstr(const char *search_in, const char *search_for); + char *fslc_strrstr(const char *search_in, const char *search_for); char *fslc_strpbrk(const char *str, const char *delim); size_t fslc_strspn(const char *str, const char *delim); char *fslc_strtok_r(char *str, const char *delim, char **save_p); + char* fslc_strcat(char* destination, const char* source); #ifdef __cplusplus } /* extern "C" */ diff --git a/libc/src/fslc_strcat.c b/libc/src/fslc_strcat.c new file mode 100644 index 0000000..a539a39 --- /dev/null +++ b/libc/src/fslc_strcat.c @@ -0,0 +1,23 @@ +#include "fslc_string.h" + +char* fslc_strcat(char* destination, const char* source) { + char* dest = destination; + + // Move the pointer to the end of the destination string + while (*dest) { + dest++; + } + + // Copy the source string to the end of the destination string + while (*source) { + *dest = *source; + dest++; + source++; + } + + // Null-terminate the concatenated string + *dest = '\0'; + + return destination; +} + diff --git a/libc/src/fslc_strrstr.c b/libc/src/fslc_strrstr.c new file mode 100644 index 0000000..4f450d2 --- /dev/null +++ b/libc/src/fslc_strrstr.c @@ -0,0 +1,35 @@ +#include "fslc_string.h" + +char* fslc_strrstr(const char* search_in, const char* search_for) +{ + size_t len_in = fslc_strlen(search_in); + size_t len_for = fslc_strlen(search_for); + + if (len_for > len_in) + return NULL; + + if (len_for == 0) + return (char*)search_in + len_in; + + for (const char* current = search_in + len_in - len_for; current >= search_in; current--) + { + const char* ptr1 = current; + const char* ptr2 = search_for; + + // Check if search_for matches starting from current position + while (*ptr1 != '\0' && *ptr2 != '\0' && *ptr1 == *ptr2) + { + ptr1++; + ptr2++; + } + + if (*ptr2 != '\0') + continue; + + // Found a match + + return (char*)current; + } + + return NULL; +} \ No newline at end of file diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 09bac4f..2ef4a25 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,5 +1,6 @@ file(GLOB tests_SRC *.cpp) +set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -Wall -Wextra -fprofile-arcs -ftest-coverage -DALT_FSLC_NAMES") add_definitions(-std=c++11) find_package(PkgConfig)