Remove src/buffer.c
This commit is contained in:
parent
112fca0df4
commit
2eacce6f09
3 changed files with 2 additions and 93 deletions
|
@ -1,20 +0,0 @@
|
||||||
#ifndef _PATTY_BUFFER_H
|
|
||||||
#define _PATTY_BUFFER_H
|
|
||||||
|
|
||||||
#include <sys/types.h>
|
|
||||||
|
|
||||||
typedef struct _patty_buffer {
|
|
||||||
void * data;
|
|
||||||
size_t size;
|
|
||||||
size_t len;
|
|
||||||
} patty_buffer;
|
|
||||||
|
|
||||||
patty_buffer *patty_buffer_new(size_t size);
|
|
||||||
|
|
||||||
void patty_buffer_destroy(patty_buffer *buffer);
|
|
||||||
|
|
||||||
ssize_t patty_buffer_fill(patty_buffer *buffer, void *data, size_t len);
|
|
||||||
|
|
||||||
void patty_buffer_flush(patty_buffer *buffer, size_t len);
|
|
||||||
|
|
||||||
#endif /* _PATTY_BUFFER_H */
|
|
|
@ -7,10 +7,10 @@ CC = $(CROSS)cc
|
||||||
CFLAGS = $(CGFLAGS) -fPIC -Wall -O2 -I$(INCLUDE_PATH)
|
CFLAGS = $(CGFLAGS) -fPIC -Wall -O2 -I$(INCLUDE_PATH)
|
||||||
LDFLAGS =
|
LDFLAGS =
|
||||||
|
|
||||||
HEADERS = buffer.h kiss.h ax25.h ax25/if.h ax25/macros.h ax25/proto.h \
|
HEADERS = kiss.h ax25.h ax25/if.h ax25/macros.h ax25/proto.h \
|
||||||
ax25/address.h ax25/frame.h list.h hash.h dict.h
|
ax25/address.h ax25/frame.h list.h hash.h dict.h
|
||||||
|
|
||||||
OBJS = buffer.o kiss.o ax25.o if.o address.o frame.o \
|
OBJS = kiss.o ax25.o if.o address.o frame.o \
|
||||||
list.o hash.o dict.o
|
list.o hash.o dict.o
|
||||||
|
|
||||||
EXAMPLES = iflist decode ptmx
|
EXAMPLES = iflist decode ptmx
|
||||||
|
|
71
src/buffer.c
71
src/buffer.c
|
@ -1,71 +0,0 @@
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <errno.h>
|
|
||||||
|
|
||||||
#include <patty/buffer.h>
|
|
||||||
|
|
||||||
patty_buffer *patty_buffer_new(size_t size) {
|
|
||||||
patty_buffer *buffer;
|
|
||||||
|
|
||||||
if ((buffer = malloc(sizeof(*buffer))) == NULL) {
|
|
||||||
goto error_malloc_buffer;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((buffer->data = malloc(size)) == NULL) {
|
|
||||||
goto error_malloc_buffer_data;
|
|
||||||
}
|
|
||||||
|
|
||||||
buffer->size = size;
|
|
||||||
buffer->len = 0;
|
|
||||||
|
|
||||||
return buffer;
|
|
||||||
|
|
||||||
error_malloc_buffer_data:
|
|
||||||
free(buffer);
|
|
||||||
|
|
||||||
error_malloc_buffer:
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
void patty_buffer_destroy(patty_buffer *buffer) {
|
|
||||||
free(buffer->data);
|
|
||||||
free(buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
ssize_t patty_buffer_fill(patty_buffer *buffer, void *data, size_t len) {
|
|
||||||
if (len == 0) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (len > buffer->size - buffer->len) {
|
|
||||||
errno = EIO;
|
|
||||||
|
|
||||||
goto error_io;
|
|
||||||
}
|
|
||||||
|
|
||||||
memcpy((unsigned char *)buffer->data + buffer->len, data, len);
|
|
||||||
|
|
||||||
buffer->len += len;
|
|
||||||
|
|
||||||
return len;
|
|
||||||
|
|
||||||
error_io:
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
void patty_buffer_flush(patty_buffer *buffer, size_t len) {
|
|
||||||
/*
|
|
||||||
* Move everything from the buffer not processed up to this point, to the
|
|
||||||
* beginning of the buffer.
|
|
||||||
*/
|
|
||||||
memmove(buffer->data,
|
|
||||||
((unsigned char *)buffer->data) + len,
|
|
||||||
buffer->len - len);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Then, decrement the buffer length by the number of bytes already
|
|
||||||
* processed.
|
|
||||||
*/
|
|
||||||
buffer->len -= len;
|
|
||||||
}
|
|
Loading…
Add table
Reference in a new issue