From aaab4b5c74c159e038dff177e53f3fc3ad353495 Mon Sep 17 00:00:00 2001 From: Nazar Date: Tue, 16 Sep 2025 11:17:47 +0300 Subject: [PATCH] Make thing build with macOS clang --- src/httpserver.c | 6 +++--- src/httpserver.h | 2 ++ src/utils/hashmap.c | 18 +++++++++--------- src/utils/string_builder.c | 16 ++++++++-------- 4 files changed, 22 insertions(+), 20 deletions(-) diff --git a/src/httpserver.c b/src/httpserver.c index 582974b..75c066a 100644 --- a/src/httpserver.c +++ b/src/httpserver.c @@ -64,7 +64,7 @@ void start_http_server(http_server_t* http_server, const char *addr, const short sa.sa_handler = handle_sigint; sigemptyset(&sa.sa_mask); sa.sa_flags = 0; - sigaction(SIGINT, &sa, nullptr); + sigaction(SIGINT, &sa, NULL); printf("Server is listening on %s:%d...\n", addr, port); @@ -124,7 +124,7 @@ void process_conn(const http_server_t* http_server, const int server_fd, struct char *header_val = malloc(1024); size_t header_val_length = 0; - http_request.http_content = nullptr; + http_request.http_content = NULL; http_request.http_content_len = 0; // TODO: Needs functionality to continue reading the request if didn't receive the whole thing, @@ -266,7 +266,7 @@ void process_conn(const http_server_t* http_server, const int server_fd, struct for (int i = 0; i < http_response->http_headers->cap; i++) { const pair_t* iter = http_response->http_headers->list[i]; - while (iter != nullptr) + while (iter != NULL) { append_fmt(response_sb, "%s: %s\r\n", iter->key, iter->val); iter = iter->next; diff --git a/src/httpserver.h b/src/httpserver.h index 7fceda6..4ffb1e8 100644 --- a/src/httpserver.h +++ b/src/httpserver.h @@ -7,6 +7,8 @@ #define SIMPLEHTTPSERVER_H #include +#include +#include #include #include #include diff --git a/src/utils/hashmap.c b/src/utils/hashmap.c index 6d8ab38..1f7933f 100644 --- a/src/utils/hashmap.c +++ b/src/utils/hashmap.c @@ -28,13 +28,13 @@ char* get(const hashmap_t* this, const char* key) const unsigned hash = hashcode(this, key); const pair_t* existing_pair = this->list[hash]; - if (existing_pair == nullptr) - return nullptr; + if (existing_pair == NULL) + return NULL; while (strcmp(existing_pair->key, key) != 0) { - if (existing_pair->next == nullptr) - return nullptr; + if (existing_pair->next == NULL) + return NULL; existing_pair = existing_pair->next; } @@ -48,11 +48,11 @@ void set(hashmap_t* this, char* key, char* val) pair_t* new_pair = malloc(sizeof *new_pair); new_pair->key = key; new_pair->val = val; - new_pair->next = nullptr; + new_pair->next = NULL; pair_t* existing_pair = this->list[hash]; - if (existing_pair == nullptr) + if (existing_pair == NULL) { this->list[hash] = new_pair; this->len++; @@ -63,7 +63,7 @@ void set(hashmap_t* this, char* key, char* val) return; } - while (existing_pair->next != nullptr) + while (existing_pair->next != NULL) { if (strcmp(existing_pair->key, key) == 0) { @@ -94,7 +94,7 @@ void expand_hash_map(hashmap_t* this) for (int i = 0; i < old_cap; i++) { pair_t* iter = old_list[i]; - while (iter != nullptr) + while (iter != NULL) { set(this, iter->key, iter->val); pair_t* prev_iter = iter; @@ -111,7 +111,7 @@ void free_hash_map(const hashmap_t* this) for (int i = 0; i < this->cap; i++) { pair_t* iter = this->list[i]; - while (iter != nullptr) + while (iter != NULL) { pair_t* prev_iter = iter; iter = iter->next; diff --git a/src/utils/string_builder.c b/src/utils/string_builder.c index fb3f712..ed3b71a 100644 --- a/src/utils/string_builder.c +++ b/src/utils/string_builder.c @@ -10,8 +10,8 @@ string_builder_t* new_string_builder() { string_builder_t* sb = malloc(sizeof *sb); - sb->first = nullptr; - sb->last = nullptr; + sb->first = NULL; + sb->last = NULL; sb->char_count = 0; return sb; } @@ -19,7 +19,7 @@ string_builder_t* new_string_builder() char* string_builder_to_string(const string_builder_t* sb) { char* str = malloc(sb->char_count + 1); - if (!str) return nullptr; + if (!str) return NULL; char* p = str; @@ -35,7 +35,7 @@ char* string_builder_to_string(const string_builder_t* sb) void free_string_builder(string_builder_t* sb) { string_builder_part_t* iter = sb->first; - while (iter != nullptr) + while (iter != NULL) { string_builder_part_t* prev = iter; iter = iter->next; @@ -43,15 +43,15 @@ void free_string_builder(string_builder_t* sb) free(prev); } - sb->first = nullptr; - sb->last = nullptr; + sb->first = NULL; + sb->last = NULL; free(sb); } void append_part(string_builder_t* sb, string_builder_part_t* part) { sb->char_count += part->len; - if (sb->last == nullptr) + if (sb->last == NULL) { sb->first = part; sb->last = part; @@ -106,7 +106,7 @@ void append_fmt(string_builder_t* sb, const char* fmt, ...) { va_list args_copy; va_copy(args_copy, args); - const int len = vsnprintf(nullptr, 0, fmt, args_copy); + const int len = vsnprintf(NULL, 0, fmt, args_copy); va_end(args_copy); if (len < 0) {