From dda645e188d6740a50f7b9b86ffca20979bc6875 Mon Sep 17 00:00:00 2001 From: Andrew Kesterson Date: Tue, 12 May 2026 21:29:20 -0400 Subject: [PATCH 1/2] Fix builds when in a submodule --- CMakeLists.txt | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b906197..3a724cd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,12 +1,20 @@ cmake_minimum_required(VERSION 3.10) project(akstdlib LANGUAGES C) +if(TARGET akerror::akerror) + message(STATUS "FOUND akerror::akerror") +else() + message(STATUS "MISSING akerror::akerror") +endif() + include(CTest) include(GNUInstallDirs) include(CMakePackageConfigHelpers) -find_package(PkgConfig REQUIRED) -find_package(akerror REQUIRED) +if(NOT TARGET akerror::akerror) + find_package(PkgConfig REQUIRED) + find_package(akerror REQUIRED) +endif() set(akstdlib_install_cmakedir "${CMAKE_INSTALL_LIBDIR}/cmake/akstdlib") set(prefix ${CMAKE_INSTALL_PREFIX}) @@ -19,6 +27,8 @@ add_library(akstdlib SHARED src/stdlib.c ) +add_library(akstdlib::akstdlib ALIAS akstdlib) + # Specify include directories for the library's headers (if applicable) target_include_directories(akstdlib PUBLIC $ @@ -28,7 +38,6 @@ target_include_directories(akstdlib PUBLIC target_link_libraries(akstdlib PUBLIC akerror::akerror) set(main_lib_dest "lib/my_library-${MY_LIBRARY_VERSION}") -install(TARGETS akstdlib EXPORT akstdlib DESTINATION "lib/") install(TARGETS akstdlib EXPORT akstdlibTargets ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} @@ -37,13 +46,11 @@ install(TARGETS akstdlib INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ) -install(EXPORT akstdlib FILE akstdlibTargets.cmake DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/akstdlib) - install(FILES "include/akstdlib.h" DESTINATION "include/") install(FILES ${CMAKE_CURRENT_BINARY_DIR}/akstdlib.pc DESTINATION "lib/pkgconfig/") -install(EXPORT akstdlib +install(EXPORT akstdlibTargets FILE akstdlibTargets.cmake NAMESPACE akstdlib:: DESTINATION ${akstdlib_install_cmakedir} From 36f161a9cce7b6f460b3884dc825240891b40d5b Mon Sep 17 00:00:00 2001 From: Andrew Kesterson Date: Sun, 24 May 2026 09:52:24 -0400 Subject: [PATCH 2/2] Added atol, atoi, atoll, and realpath --- include/akstdlib.h | 5 +++++ src/stdlib.c | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/include/akstdlib.h b/include/akstdlib.h index a61c5da..a2aec1a 100644 --- a/include/akstdlib.h +++ b/include/akstdlib.h @@ -21,5 +21,10 @@ akerr_ErrorContext AKERR_NOIGNORE *aksl_printf(int *count, const char *restrict akerr_ErrorContext AKERR_NOIGNORE *aksl_fprintf(int *count, FILE *restrict stream, const char *restrict format, ...); akerr_ErrorContext AKERR_NOIGNORE *aksl_sprintf(int *count, char *restrict str, const char *restrict format, ...); +akerr_ErrorContext AKERR_NOIGNORE *aksl_atoi(const char *nptr, int *dest); +akerr_ErrorContext AKERR_NOIGNORE *aksl_atol(const char *nptr, long *dest); +akerr_ErrorContext AKERR_NOIGNORE *aksl_atoll(const char *nptr, long long *dest); + +akerr_ErrorContext AKERR_NOIGNORE *aksl_realpath(const char *restrict path, char *restrict resolved_path); #endif diff --git a/src/stdlib.c b/src/stdlib.c index fcd6f4d..3d2507f 100644 --- a/src/stdlib.c +++ b/src/stdlib.c @@ -126,3 +126,40 @@ akerr_ErrorContext AKERR_NOIGNORE *aksl_sprintf(int *count, char *restrict str, FAIL_NONZERO_RETURN(e, (*count == -1), errno, "Short write"); SUCCEED_RETURN(e); } + +akerr_ErrorContext AKERR_NOIGNORE *aksl_atoi(const char *nptr, int *dest) +{ + PREPARE_ERROR(e); + FAIL_ZERO_RETURN(e, nptr, AKERR_NULLPOINTER, "nptr=%p, dest=%p", (void *)nptr, (void *)dest); + FAIL_ZERO_RETURN(e, dest, AKERR_NULLPOINTER, "nptr=%p, dest=%p", (void *)nptr, (void *)dest); + *dest = atoi(nptr); + SUCCEED_RETURN(e); +} + +akerr_ErrorContext AKERR_NOIGNORE *aksl_atol(const char *nptr, long *dest) +{ + PREPARE_ERROR(e); + FAIL_ZERO_RETURN(e, nptr, AKERR_NULLPOINTER, "nptr=%p, dest=%p", (void *)nptr, (void *)dest); + FAIL_ZERO_RETURN(e, dest, AKERR_NULLPOINTER, "nptr=%p, dest=%p", (void *)nptr, (void *)dest); + *dest = atol(nptr); + SUCCEED_RETURN(e); +} + +akerr_ErrorContext AKERR_NOIGNORE *aksl_atoll(const char *nptr, long long *dest) +{ + PREPARE_ERROR(e); + FAIL_ZERO_RETURN(e, nptr, AKERR_NULLPOINTER, "nptr=%p, dest=%p", (void *)nptr, (void *)dest); + FAIL_ZERO_RETURN(e, dest, AKERR_NULLPOINTER, "nptr=%p, dest=%p", (void *)nptr, (void *)dest); + *dest = atoll(nptr); + SUCCEED_RETURN(e); +} + +akerr_ErrorContext AKERR_NOIGNORE *aksl_realpath(const char *restrict path, char *restrict resolved_path) +{ + char *result = NULL; + PREPARE_ERROR(e); + FAIL_ZERO_RETURN(e, path, AKERR_NULLPOINTER, "path=%p, dest=%p", (void *)path, (void *)resolved_path); + result = realpath(path, resolved_path); + FAIL_ZERO_RETURN(e, result, errno, "Error"); + SUCCEED_RETURN(e); +}