Make thing build with macOS clang #1

Merged
nazar merged 1 commits from fix/macos-clang-doesnt-compile into main 2025-09-17 10:00:06 +03:00
4 changed files with 22 additions and 20 deletions

View File

@@ -64,7 +64,7 @@ void start_http_server(http_server_t* http_server, const char *addr, const short
sa.sa_handler = handle_sigint; sa.sa_handler = handle_sigint;
sigemptyset(&sa.sa_mask); sigemptyset(&sa.sa_mask);
sa.sa_flags = 0; sa.sa_flags = 0;
sigaction(SIGINT, &sa, nullptr); sigaction(SIGINT, &sa, NULL);
printf("Server is listening on %s:%d...\n", addr, port); 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); char *header_val = malloc(1024);
size_t header_val_length = 0; size_t header_val_length = 0;
http_request.http_content = nullptr; http_request.http_content = NULL;
http_request.http_content_len = 0; http_request.http_content_len = 0;
// TODO: Needs functionality to continue reading the request if didn't receive the whole thing, // 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++) for (int i = 0; i < http_response->http_headers->cap; i++)
{ {
const pair_t* iter = http_response->http_headers->list[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); append_fmt(response_sb, "%s: %s\r\n", iter->key, iter->val);
iter = iter->next; iter = iter->next;

View File

@@ -7,6 +7,8 @@
#define SIMPLEHTTPSERVER_H #define SIMPLEHTTPSERVER_H
#include <netdb.h> #include <netdb.h>
#include <stdbool.h>
#include <stddef.h>
#include <signal.h> #include <signal.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>

View File

@@ -28,13 +28,13 @@ char* get(const hashmap_t* this, const char* key)
const unsigned hash = hashcode(this, key); const unsigned hash = hashcode(this, key);
const pair_t* existing_pair = this->list[hash]; const pair_t* existing_pair = this->list[hash];
if (existing_pair == nullptr) if (existing_pair == NULL)
return nullptr; return NULL;
while (strcmp(existing_pair->key, key) != 0) while (strcmp(existing_pair->key, key) != 0)
{ {
if (existing_pair->next == nullptr) if (existing_pair->next == NULL)
return nullptr; return NULL;
existing_pair = existing_pair->next; 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); pair_t* new_pair = malloc(sizeof *new_pair);
new_pair->key = key; new_pair->key = key;
new_pair->val = val; new_pair->val = val;
new_pair->next = nullptr; new_pair->next = NULL;
pair_t* existing_pair = this->list[hash]; pair_t* existing_pair = this->list[hash];
if (existing_pair == nullptr) if (existing_pair == NULL)
{ {
this->list[hash] = new_pair; this->list[hash] = new_pair;
this->len++; this->len++;
@@ -63,7 +63,7 @@ void set(hashmap_t* this, char* key, char* val)
return; return;
} }
while (existing_pair->next != nullptr) while (existing_pair->next != NULL)
{ {
if (strcmp(existing_pair->key, key) == 0) 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++) for (int i = 0; i < old_cap; i++)
{ {
pair_t* iter = old_list[i]; pair_t* iter = old_list[i];
while (iter != nullptr) while (iter != NULL)
{ {
set(this, iter->key, iter->val); set(this, iter->key, iter->val);
pair_t* prev_iter = iter; 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++) for (int i = 0; i < this->cap; i++)
{ {
pair_t* iter = this->list[i]; pair_t* iter = this->list[i];
while (iter != nullptr) while (iter != NULL)
{ {
pair_t* prev_iter = iter; pair_t* prev_iter = iter;
iter = iter->next; iter = iter->next;

View File

@@ -10,8 +10,8 @@
string_builder_t* new_string_builder() string_builder_t* new_string_builder()
{ {
string_builder_t* sb = malloc(sizeof *sb); string_builder_t* sb = malloc(sizeof *sb);
sb->first = nullptr; sb->first = NULL;
sb->last = nullptr; sb->last = NULL;
sb->char_count = 0; sb->char_count = 0;
return sb; return sb;
} }
@@ -19,7 +19,7 @@ string_builder_t* new_string_builder()
char* string_builder_to_string(const string_builder_t* sb) char* string_builder_to_string(const string_builder_t* sb)
{ {
char* str = malloc(sb->char_count + 1); char* str = malloc(sb->char_count + 1);
if (!str) return nullptr; if (!str) return NULL;
char* p = str; 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) void free_string_builder(string_builder_t* sb)
{ {
string_builder_part_t* iter = sb->first; string_builder_part_t* iter = sb->first;
while (iter != nullptr) while (iter != NULL)
{ {
string_builder_part_t* prev = iter; string_builder_part_t* prev = iter;
iter = iter->next; iter = iter->next;
@@ -43,15 +43,15 @@ void free_string_builder(string_builder_t* sb)
free(prev); free(prev);
} }
sb->first = nullptr; sb->first = NULL;
sb->last = nullptr; sb->last = NULL;
free(sb); free(sb);
} }
void append_part(string_builder_t* sb, string_builder_part_t* part) void append_part(string_builder_t* sb, string_builder_part_t* part)
{ {
sb->char_count += part->len; sb->char_count += part->len;
if (sb->last == nullptr) if (sb->last == NULL)
{ {
sb->first = part; sb->first = part;
sb->last = part; sb->last = part;
@@ -106,7 +106,7 @@ void append_fmt(string_builder_t* sb, const char* fmt, ...) {
va_list args_copy; va_list args_copy;
va_copy(args_copy, args); 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); va_end(args_copy);
if (len < 0) { if (len < 0) {