[1022] | 1 | /* Copyright 2009, UCAR/Unidata and OPeNDAP, Inc. |
---|
| 2 | See the COPYRIGHT file for more information. */ |
---|
| 3 | |
---|
| 4 | #ifndef OCBYTES_H |
---|
| 5 | #define OCBYTES_H 1 |
---|
| 6 | |
---|
| 7 | typedef struct OCbytes { |
---|
| 8 | int nonextendible; /* 1 => fail if an attempt is made to extend this buffer*/ |
---|
| 9 | unsigned int alloc; |
---|
| 10 | unsigned int length; |
---|
| 11 | char* content; |
---|
| 12 | } OCbytes; |
---|
| 13 | |
---|
| 14 | #if defined(_CPLUSPLUS_) || defined(__CPLUSPLUS__) || defined(__CPLUSPLUS) |
---|
| 15 | #define EXTERNC extern "C" |
---|
| 16 | #else |
---|
| 17 | #define EXTERNC extern |
---|
| 18 | #endif |
---|
| 19 | |
---|
| 20 | EXTERNC OCbytes* ocbytesnew(void); |
---|
| 21 | EXTERNC void ocbytesfree(OCbytes*); |
---|
| 22 | EXTERNC int ocbytessetalloc(OCbytes*,unsigned int); |
---|
| 23 | EXTERNC int ocbytessetlength(OCbytes*,unsigned int); |
---|
| 24 | EXTERNC int ocbytesfill(OCbytes*, char fill); |
---|
| 25 | |
---|
| 26 | /* Produce a duplicate of the contents*/ |
---|
| 27 | EXTERNC char* ocbytesdup(OCbytes*); |
---|
| 28 | /* Extract the contents and leave buffer empty */ |
---|
| 29 | EXTERNC char* ocbytesextract(OCbytes*); |
---|
| 30 | |
---|
| 31 | /* Return the ith byte; -1 if no such index */ |
---|
| 32 | EXTERNC int ocbytesget(OCbytes*,unsigned int); |
---|
| 33 | /* Set the ith byte */ |
---|
| 34 | EXTERNC int ocbytesset(OCbytes*,unsigned int,char); |
---|
| 35 | |
---|
| 36 | /* Append one byte */ |
---|
| 37 | EXTERNC int ocbytesappend(OCbytes*,char); /* Add at Tail */ |
---|
| 38 | /* Append n bytes */ |
---|
| 39 | EXTERNC int ocbytesappendn(OCbytes*,void*,unsigned int); /* Add at Tail */ |
---|
| 40 | |
---|
| 41 | /* Concatenate a null-terminated string to the end of the buffer */ |
---|
| 42 | EXTERNC int ocbytescat(OCbytes*,char*); |
---|
| 43 | /* Set the contents of the buffer; mark the buffer as non-extendible */ |
---|
| 44 | EXTERNC int ocbytessetcontents(OCbytes*, char*, unsigned int); |
---|
| 45 | |
---|
| 46 | /* Following are always "in-lined"*/ |
---|
| 47 | #define ocbyteslength(bb) ((bb)?(bb)->length:0U) |
---|
| 48 | #define ocbytesalloc(bb) ((bb)?(bb)->alloc:0U) |
---|
| 49 | #define ocbytescontents(bb) ((bb && bb->content)?(bb)->content:(char*)"") |
---|
| 50 | #define ocbytesextend(bb,len) ocbytessetalloc((bb),(len)+(bb->alloc)) |
---|
| 51 | #define ocbytesclear(bb) ((bb)?(bb)->length=0:0U) |
---|
| 52 | #define ocbytesavail(bb,n) ((bb)?((bb)->alloc - (bb)->length) >= (n):0U) |
---|
| 53 | |
---|
| 54 | #endif /*OCBYTES_H*/ |
---|