Skip to content
Open
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
11 changes: 7 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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()
5 changes: 4 additions & 1 deletion libc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions libc/include/fslc/fslc_string.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

Expand All @@ -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" */
Expand Down
23 changes: 23 additions & 0 deletions libc/src/fslc_strcat.c
Original file line number Diff line number Diff line change
@@ -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;
}

35 changes: 35 additions & 0 deletions libc/src/fslc_strrstr.c
Original file line number Diff line number Diff line change
@@ -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;
}
1 change: 1 addition & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
Expand Down