Mercurial > dropbear
comparison buffer.h @ 1057:16584026a1f0 nocircbuffer
allocate buffer and data in a single allocation
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Sun, 01 Mar 2015 21:16:09 +0800 |
parents | deed0571cacc |
children | 2fa71c3b2827 aaf576b27a10 |
comparison
equal
deleted
inserted
replaced
1056:a2bfd4374878 | 1057:16584026a1f0 |
---|---|
27 #define DROPBEAR_BUFFER_H_ | 27 #define DROPBEAR_BUFFER_H_ |
28 | 28 |
29 #include "includes.h" | 29 #include "includes.h" |
30 | 30 |
31 struct buf { | 31 struct buf { |
32 | 32 /* don't manipulate data member outside of buffer.c - it |
33 is a pointer into the malloc holding buffer itself */ | |
33 unsigned char * data; | 34 unsigned char * data; |
34 unsigned int len; /* the used size */ | 35 unsigned int len; /* the used size */ |
35 unsigned int pos; | 36 unsigned int pos; |
36 unsigned int size; /* the memory size */ | 37 unsigned int size; /* the memory size */ |
37 | 38 |
38 }; | 39 }; |
39 | 40 |
40 typedef struct buf buffer; | 41 typedef struct buf buffer; |
41 | 42 |
42 buffer * buf_new(unsigned int size); | 43 buffer * buf_new(unsigned int size); |
43 void buf_resize(buffer *buf, unsigned int newsize); | 44 /* Possibly returns a new buffer*, like realloc() */ |
45 buffer * buf_resize(buffer *buf, unsigned int newsize); | |
44 void buf_free(buffer* buf); | 46 void buf_free(buffer* buf); |
45 void buf_burn(buffer* buf); | 47 void buf_burn(buffer* buf); |
46 buffer* buf_newcopy(buffer* buf); | 48 buffer* buf_newcopy(buffer* buf); |
47 void buf_setlen(buffer* buf, unsigned int len); | 49 void buf_setlen(buffer* buf, unsigned int len); |
48 void buf_incrlen(buffer* buf, unsigned int incr); | 50 void buf_incrlen(buffer* buf, unsigned int incr); |