]> gitweb.hhaalo.de Git - feierabend.git/commitdiff
change to c99 std
authorBastian Dehn <hhaalo@arcor.de>
Tue, 10 Feb 2026 18:08:14 +0000 (19:08 +0100)
committerBastian Dehn <hhaalo@arcor.de>
Tue, 10 Feb 2026 18:08:14 +0000 (19:08 +0100)
CMakeLists.txt
src/feierabend.c
src/time_format.c
src/xml.c

index 90cd150179e05ff3e7f605ebd2d4e7f3a8d5d82c..c41be2f1fe7469758e79fa2f20729870081e4af2 100644 (file)
@@ -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}")
index e3541ab8bd000c08d304cd5228a2ad21ebfdf03a..5d2ebdd06d240af3510c4ff6984ac77bcc197d15 100644 (file)
@@ -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");
index d5261271a2715aad79d2953f184ea815bb5a6f02..993cc38db85a82579f755c2f8e6db0c6c1b0e4bc 100644 (file)
@@ -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);
index e8cbf27df78c539297369260d5ec934fab587e41..693cc42e43003580ec50677d500910ce01674a2a 100644 (file)
--- 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;