From 85254e21cbc04eb5921bf62905ea98186facce45 Mon Sep 17 00:00:00 2001 From: Nick Krichevsky Date: Sun, 9 Sep 2018 16:48:01 -0400 Subject: [PATCH] Move get_buffer_size into buffer_helper --- client/http_socket.c | 18 +----------------- common/buffer_helper.c | 18 ++++++++++++++++++ common/buffer_helper.h | 8 ++++++++ 3 files changed, 27 insertions(+), 17 deletions(-) create mode 100644 common/buffer_helper.c create mode 100644 common/buffer_helper.h 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