mirror of
https://codeberg.org/scip/pcp.git
synced 2025-12-17 03:50:57 +01:00
added Buffer "class" based on openssh/buffer.c, which is a really beautiful idea. I'll use this for file i/o and data handling
This commit is contained in:
@@ -20,7 +20,7 @@
|
||||
#
|
||||
|
||||
AM_CFLAGS = -I../include/pcp -I../src -I../libpcp/scrypt/crypto -Wall -g
|
||||
check_PROGRAMS = col invalidkeys pwhashes gencheader statictest cpptest
|
||||
check_PROGRAMS = col invalidkeys pwhashes gencheader statictest cpptest buffertest
|
||||
|
||||
gencheader_LDADD = ../libpcp/.libs/libpcp1.a
|
||||
gencheader_SOURCES = gencheader.c
|
||||
@@ -28,6 +28,9 @@ gencheader_SOURCES = gencheader.c
|
||||
statictest_LDADD = ../libpcp/.libs/libpcp1.a
|
||||
statictest_SOURCES = statictest.c
|
||||
|
||||
buffertest_LDADD = ../libpcp/.libs/libpcp1.a
|
||||
buffertest_SOURCES = buffertest.c
|
||||
|
||||
|
||||
|
||||
col_LDADD = ../libpcp/.libs/libpcp1.a
|
||||
|
||||
58
tests/buffertest.c
Normal file
58
tests/buffertest.c
Normal file
@@ -0,0 +1,58 @@
|
||||
#include "buffertest.h"
|
||||
|
||||
int main() {
|
||||
Buffer *test = buffer_new(16, "test");
|
||||
|
||||
byte *a = ucmalloc(32);
|
||||
byte *b = ucmalloc(32);
|
||||
memset(a, 'A', 32);
|
||||
memset(b, 'B', 32);
|
||||
|
||||
fprintf(stderr, "initial\n");
|
||||
buffer_info(test);
|
||||
|
||||
int i;
|
||||
for(i=0; i<2; i++) {
|
||||
fprintf(stderr, "\nadding As\n");
|
||||
buffer_add(test, a, 32);
|
||||
buffer_info(test);
|
||||
buffer_dump(test);
|
||||
|
||||
fprintf(stderr, "\nadding Bs\n");
|
||||
buffer_add(test, b, 32);
|
||||
buffer_info(test);
|
||||
buffer_dump(test);
|
||||
}
|
||||
|
||||
free(a);
|
||||
free(b);
|
||||
|
||||
|
||||
size_t x;
|
||||
size_t bs = buffer_size(test);
|
||||
void *g = ucmalloc(32);
|
||||
for(x=0; x < bs; x+=32) {
|
||||
fprintf(stderr, "before get\n");
|
||||
buffer_info(test);
|
||||
if(buffer_get(test, g, 32) > 0) {
|
||||
fprintf(stderr, "after get\n");
|
||||
buffer_info(test);
|
||||
_dump("got", g, 32);
|
||||
}
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
|
||||
buffer_extract(test, g, 28, 38);
|
||||
_dump("extracted", g, 10);
|
||||
|
||||
uint8_t c = buffer_last8(test);
|
||||
fprintf(stderr, "last byte: %c\n", c);
|
||||
|
||||
free(g);
|
||||
|
||||
buffer_free(test);
|
||||
|
||||
fatals_ifany();
|
||||
|
||||
return 0;
|
||||
}
|
||||
6
tests/buffertest.h
Normal file
6
tests/buffertest.h
Normal file
@@ -0,0 +1,6 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <limits.h>
|
||||
|
||||
#include "buffer.h"
|
||||
|
||||
Reference in New Issue
Block a user