diff --git a/client/http_socket.c b/client/http_socket.c index 68f3179..4e18bf5 100644 --- a/client/http_socket.c +++ b/client/http_socket.c @@ -1,5 +1,6 @@ #include "http_socket.h" #include "../common/socket_helper.h" +#include "../common/buffer_helper.h" #include #include #include @@ -10,23 +11,6 @@ #include #include -/** - * Gets the buffer size to allocate based on the given components. - * - * @param components An array of null-terminated C strings to measure the length of - * @param num_components The number of items in the components array. - * - * @return The buffer size to allocate, excluding the null terminator - */ -static size_t get_buffer_size(const char **components, int num_components) { - size_t buffer_size = 0; - for (int i = 0; i < num_components; i++) { - buffer_size += strlen(components[i]); - } - - return buffer_size; -} - /** * Build a basic request into an http_message * diff --git a/common/buffer_helper.c b/common/buffer_helper.c new file mode 100644 index 0000000..261d76b --- /dev/null +++ b/common/buffer_helper.c @@ -0,0 +1,18 @@ +#include + +/** + * Gets the buffer size to allocate based on the given components. + * + * @param components An array of null-terminated C strings to measure the length of + * @param num_components The number of items in the components array. + * + * @return The buffer size to allocate, excluding the null terminator + */ +size_t get_buffer_size(const char **components, int num_components) { + size_t buffer_size = 0; + for (int i = 0; i < num_components; i++) { + buffer_size += strlen(components[i]); + } + + return buffer_size; +} diff --git a/common/buffer_helper.h b/common/buffer_helper.h new file mode 100644 index 0000000..0e3feeb --- /dev/null +++ b/common/buffer_helper.h @@ -0,0 +1,8 @@ +#ifndef BUFFER_HELPER_H +#define BUFFER_HELPER_H + +#include + +size_t get_buffer_size(const char **components, int num_components); + +#endif