Add get_line_terminator to socket_helper
This commit is contained in:
parent
68f769cf97
commit
20d04d8bd7
|
@ -3,6 +3,30 @@
|
|||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
/**
|
||||
* Get the next \n in a \r\n sequence within the buffer.
|
||||
*
|
||||
* @param buffer The buffer to scan.
|
||||
* @param buffer_size The max size of the buffer
|
||||
*
|
||||
* @return A pointer to the terminating \n in the \r\n sequence.
|
||||
*/
|
||||
static const char *get_line_terminator(const char *buffer, int buffer_size) {
|
||||
const char *prev_cursor = NULL;
|
||||
const char *cursor = buffer;
|
||||
for (int i = 0; i < buffer_size; (i++, cursor++)) {
|
||||
if (*cursor == '\0') {
|
||||
return NULL;
|
||||
}
|
||||
if (prev_cursor != NULL && *prev_cursor == '\r' && *cursor == '\n') {
|
||||
return cursor;
|
||||
}
|
||||
prev_cursor = cursor;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char *get_all_remote_parts(int socket_fd) {
|
||||
int current_size = BUFFER_SIZE;
|
||||
char *result = NULL;
|
||||
|
|
Loading…
Reference in a new issue