From 46e2bb2ec41b8ea006aee2c93ad0286d6e912b4f Mon Sep 17 00:00:00 2001 From: Pinwhell <60289470+pinwhell@users.noreply.github.com> Date: Sun, 31 Mar 2024 16:44:56 -0400 Subject: [PATCH 1/7] strrstr Support --- libc/include/fslc/fslc_string.h | 2 ++ libc/src/fslc_strrstr.c | 35 +++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 libc/src/fslc_strrstr.c diff --git a/libc/include/fslc/fslc_string.h b/libc/include/fslc/fslc_string.h index a869054..427f199 100644 --- a/libc/include/fslc/fslc_string.h +++ b/libc/include/fslc/fslc_string.h @@ -16,6 +16,7 @@ #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 @@ -38,6 +39,7 @@ 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); 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 From 415643a3bbcb155e687f798f4bfaa0ae0f095e14 Mon Sep 17 00:00:00 2001 From: Pinwhell <60289470+pinwhell@users.noreply.github.com> Date: Sun, 31 Mar 2024 19:35:11 -0400 Subject: [PATCH 2/7] Conditional Testing Integrated --- CMakeLists.txt | 10 +++++++--- tests/CMakeLists.txt | 1 + 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6e7c804..9015f82 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,14 +1,18 @@ cmake_minimum_required (VERSION 2.6) project (FsLibc) -enable_testing() +option(ENABLE_TESTS "Enable Testings" 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/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) From 822c99a4c48bb837b8ac78e710f150643e6994b2 Mon Sep 17 00:00:00 2001 From: Pinwhell <60289470+pinwhell@users.noreply.github.com> Date: Sun, 31 Mar 2024 19:42:52 -0400 Subject: [PATCH 3/7] Includes Refactor --- libc/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libc/CMakeLists.txt b/libc/CMakeLists.txt index d91db9d..dbfa3bd 100644 --- a/libc/CMakeLists.txt +++ b/libc/CMakeLists.txt @@ -2,8 +2,8 @@ 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) install(TARGETS fslc DESTINATION lib) install(FILES ${fslc_SINC} DESTINATION include) From 9bc86d7cd742166cf13f5865edb07ae465171d8a Mon Sep 17 00:00:00 2001 From: Pinwhell <60289470+pinwhell@users.noreply.github.com> Date: Thu, 4 Apr 2024 02:36:12 -0400 Subject: [PATCH 4/7] Conditional Symbol Naming Added --- CMakeLists.txt | 3 +-- libc/CMakeLists.txt | 3 +++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9015f82..d1abb7c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,13 +2,12 @@ cmake_minimum_required (VERSION 2.6) project (FsLibc) 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_RELEASE "${CMAKE_C_FLAGS_RELEASE} -Wall -Wextra") -set(CMAKE_C_FLAGS_RELCHECK "${CMAKE_C_FLAGS_RELEASE} -DALT_FSLC_NAMES") add_subdirectory(libc) diff --git a/libc/CMakeLists.txt b/libc/CMakeLists.txt index dbfa3bd..3162033 100644 --- a/libc/CMakeLists.txt +++ b/libc/CMakeLists.txt @@ -4,6 +4,9 @@ file(GLOB fslc_SINC include/*.h) 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) From 5f3657e2cdd5b271ba083604a1534124169d9d2e Mon Sep 17 00:00:00 2001 From: Pinwhell <60289470+pinwhell@users.noreply.github.com> Date: Thu, 11 Apr 2024 21:52:05 -0400 Subject: [PATCH 5/7] Interfacing ALT_FSLC_NAMES for Consumers --- libc/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libc/CMakeLists.txt b/libc/CMakeLists.txt index 3162033..50820a8 100644 --- a/libc/CMakeLists.txt +++ b/libc/CMakeLists.txt @@ -5,7 +5,7 @@ file(GLOB fslc_SINC include/*.h) 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) + target_compile_definitions(fslc INTERFACE ALT_FSLC_NAMES) endif() install(TARGETS fslc DESTINATION lib) From 8c4f4bbca3b45935c11f1586f1fd37061d474b51 Mon Sep 17 00:00:00 2001 From: Pinwhell <60289470+pinwhell@users.noreply.github.com> Date: Sun, 14 Jul 2024 22:04:53 -0400 Subject: [PATCH 6/7] Minimal Fix --- libc/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libc/CMakeLists.txt b/libc/CMakeLists.txt index 50820a8..3162033 100644 --- a/libc/CMakeLists.txt +++ b/libc/CMakeLists.txt @@ -5,7 +5,7 @@ file(GLOB fslc_SINC include/*.h) add_library(fslc ${fslc_SRC}) target_include_directories(fslc PUBLIC include/fslc) if(NOT ENABLE_STANDARD_SYMNAMES) - target_compile_definitions(fslc INTERFACE ALT_FSLC_NAMES) + target_compile_definitions(fslc PUBLIC ALT_FSLC_NAMES) endif() install(TARGETS fslc DESTINATION lib) From f8fc780570fb32ea1e102927492c73ea474239cf Mon Sep 17 00:00:00 2001 From: Pinwhell <60289470+pinwhell@users.noreply.github.com> Date: Thu, 18 Jul 2024 02:32:34 -0400 Subject: [PATCH 7/7] Impl strcat --- libc/include/fslc/fslc_string.h | 2 ++ libc/src/fslc_strcat.c | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 libc/src/fslc_strcat.c diff --git a/libc/include/fslc/fslc_string.h b/libc/include/fslc/fslc_string.h index 427f199..c678b6d 100644 --- a/libc/include/fslc/fslc_string.h +++ b/libc/include/fslc/fslc_string.h @@ -20,6 +20,7 @@ #define fslc_strpbrk strpbrk #define fslc_strspn strspn #define fslc_strtok_r strtok_r +#define fslc_strcat strcat #endif /* ALT_FSLC_NAMES */ @@ -43,6 +44,7 @@ extern "C" { 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; +} +