From 3e187c094f12ef41ea6de2f55d128c3e037b5c12 Mon Sep 17 00:00:00 2001 From: FreeArtMan Date: Wed, 25 Sep 2019 19:17:09 +0100 Subject: Untested version, recompiled with new buf library and with c+ --- buf.c | 122 ------------------------------------------------------------------ 1 file changed, 122 deletions(-) delete mode 100644 buf.c (limited to 'buf.c') diff --git a/buf.c b/buf.c deleted file mode 100644 index d0519e5..0000000 --- a/buf.c +++ /dev/null @@ -1,122 +0,0 @@ -#include "buf.h" - -buf_t* buf_init() -{ - buf_t *ret = NULL; - - ret = malloc( sizeof(buf_t) ); - memset(ret, 0, sizeof(buf_t)); - - return ret; -} - - -int buf_not_null( buf_t *bf ) -{ - - if ( bf == NULL ) - return 0; - - if ( bf->buf == NULL ) - return 0; - - if ( bf->buf_size < 0 ) - return 0; - - return 1; -} - -int buf_size( buf_t *bf, int size ) -{ - if (bf->buf != NULL) - { - printf("Buffer should be empty\n"); - return -1; - } - - bf->buf = malloc( size ); - bf->size = size; - bf->buf_size = size; - - return 0; -} - - -int buf_used_size( buf_t *bf, int size ) -{ - if ( size > bf->buf_size ) - { - printf("Cannot set buffer size more then buffer itself\n"); - return -1; - } - - if ( size < 0) - { - printf("Cannot set buffer less then zero\n"); - return -1; - } - - bf->size = size; - - return 0; -} - - -int buf_resize( buf_t *bf, int size ) -{ - uint8_t *n=NULL; - - if ( size < 1) - { - printf("Cannot set buffer size less then 1\n"); - return -1; - } - - n = realloc( bf->buf, size ); //resized data is not nullified at the end? - if ( n == NULL ) - { - printf("Buffer realloc failed\n"); - return -1; - } - - if ( size > bf->buf_size ) - { - memset(bf->buf+bf->buf_size-1, 0, size-(bf->buf_size)); //hope its correct - } - - bf->buf_size = size; - bf->buf = n; - if (bf->size > bf->buf_size) - { - bf->size = bf->buf_size; - } - - return 0; -} - - -int buf_zero( buf_t *bf ) -{ - if ( bf->buf == NULL ) - return -1; - - memset( bf->buf, 0, bf->buf_size ); - - return 0; -} - - -void buf_free( buf_t *bf ) -{ - if ( bf == NULL ) - return; - - if ( bf->buf != NULL ) - { - free( bf->buf ); - bf->buf = NULL; - } - - free( bf ); - bf = NULL; -} -- cgit v1.2.3