From: Bastian Dehn Date: Tue, 10 Feb 2026 18:08:14 +0000 (+0100) Subject: change to c99 std X-Git-Tag: 1.3.10^2~3 X-Git-Url: https://gitweb.hhaalo.de/?a=commitdiff_plain;h=d2a84490101d384f2000518bd7b836f77d71c597;p=feierabend.git change to c99 std --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 90cd150..c41be2f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,9 +3,9 @@ CMAKE_MINIMUM_REQUIRED(VERSION 3.25.1) SET(CMAKE_BUILD_TYPE "Debug" CACHE STRING "build type") IF(${CMAKE_BUILD_TYPE} STREQUAL "Debug") - SET(CMAKE_C_FLAGS "-std=gnu99 -Wall -Wextra -pedantic -g -fsanitize=address") + SET(CMAKE_C_FLAGS "-std=c99 -Wall -Wextra -pedantic -g -fsanitize=address") else() - SET(CMAKE_C_FLAGS "-std=gnu99 -Werror -Wextra -pedantic") + SET(CMAKE_C_FLAGS "-std=c99 -Werror -Wextra -pedantic") ENDIF() MESSAGE(STATUS "CMAKE_C_FLAGS: ${CMAKE_C_FLAGS}") diff --git a/src/feierabend.c b/src/feierabend.c index e3541ab..5d2ebdd 100644 --- a/src/feierabend.c +++ b/src/feierabend.c @@ -28,7 +28,7 @@ time_t _set_time(time_t value, struct tm* tm_value, int hour, int minutes) { time(&value); - localtime_r(&value, tm_value); + tm_value = localtime(&value); tm_value->tm_hour = hour; tm_value->tm_min = minutes; @@ -172,15 +172,15 @@ int main(int argc, const char* argv[]) fabend->begin = _set_time(fabend->begin, fabend->begin_tm, atoi(argv[1]), atoi(argv[2])); time(&fabend->now); - localtime_r(&fabend->now, fabend->now_tm); + fabend->now_tm = localtime(&fabend->now); if (argc == 5) fabend->now = _set_time(fabend->now, fabend->now_tm, atoi(argv[3]), atoi(argv[4])); fabend->worktime = get_eight_hour_end_worktime(fabend->begin); - localtime_r(&fabend->worktime, fabend->work_end_tm); + fabend->work_end_tm = localtime(&fabend->worktime); fabend->worktime = get_ten_hour_end_worktime(fabend->begin); - localtime_r(&fabend->worktime, fabend->max_work_end_tm); + fabend->max_work_end_tm = localtime(&fabend->worktime); _print_time_now(fabend); printf("\n"); diff --git a/src/time_format.c b/src/time_format.c index d526127..993cc38 100644 --- a/src/time_format.c +++ b/src/time_format.c @@ -8,6 +8,18 @@ #define MAX_TIME_STR_LENGTH 7 +char* strdup(const char* str) +{ + size_t size = strlen(str) + 1; + char* new_str = malloc(sizeof(char) * size); + + if (new_str == NULL) + return NULL; + + strncpy(new_str, str, size); + return new_str; +} + void get_time_str(time_t timediff, char* timestr) { memset(timestr, 0, MAX_TIME_STR_LENGTH); diff --git a/src/xml.c b/src/xml.c index e8cbf27..693cc42 100644 --- a/src/xml.c +++ b/src/xml.c @@ -35,6 +35,30 @@ void free_memFile(memFile* mem) { mem->size = NULL; } +void allocChunk(memFile* mem) +{ + *mem->size = 32; + char* tmpmem = realloc(mem->data, sizeof(mem->data) + (sizeof(char) * *mem->size)); + if (tmpmem == NULL) { + free(mem); + return; + } + + *mem->data = tmpmem; +} + +void shrinkMem(size_t readed, memFile* mem) +{ + char* tmpmem = realloc(mem->data, sizeof(mem->data) + (sizeof(char) * readed + 1)); + if (tmpmem == NULL) { + free(mem); + return; + } + + tmpmem[readed + 1] = '\0'; + *mem->data = tmpmem; +} + void readStdInIntoMemory(memFile* mem) { char* buf = malloc(sizeof(char)); @@ -42,14 +66,16 @@ void readStdInIntoMemory(memFile* mem) if (buf == NULL) return; - FILE* memstream = open_memstream(mem->data, mem->size); - FILE* file = fdopen(0, "r"); - - while(fread(buf, sizeof(char), 1, file) != 0) { - fwrite(buf, sizeof(char), 1, memstream); + allocChunk(mem); + size_t read_size = 0; + while(fread(buf, sizeof(char), 1, stdin) != 0) { + mem->data[read_size] = buf; + mem->size--; + read_size++; + if (mem->size == 0) + allocChunk(mem); } - fclose(file); - fclose(memstream); + shrinkMem(read_size, mem); free(buf); buf = NULL;