Move get_buffer_size into buffer_helper

master
Nick Krichevsky 2018-09-09 16:48:01 -04:00
parent 4200b4a6d6
commit 85254e21cb
3 changed files with 27 additions and 17 deletions

View File

@ -1,5 +1,6 @@
#include "http_socket.h"
#include "../common/socket_helper.h"
#include "../common/buffer_helper.h"
#include <math.h>
#include <netdb.h>
#include <netinet/in.h>
@ -10,23 +11,6 @@
#include <sys/time.h>
#include <unistd.h>
/**
* 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
*

18
common/buffer_helper.c Normal file
View File

@ -0,0 +1,18 @@
#include <string.h>
/**
* 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;
}

8
common/buffer_helper.h Normal file
View File

@ -0,0 +1,8 @@
#ifndef BUFFER_HELPER_H
#define BUFFER_HELPER_H
#include <string.h>
size_t get_buffer_size(const char **components, int num_components);
#endif