1 | /* Copyright 2009, UCAR/Unidata and OPeNDAP, Inc. |
---|
2 | See the COPYRIGHT file for more information. */ |
---|
3 | |
---|
4 | #ifndef NCBYTES_H |
---|
5 | #define NCBYTES_H 1 |
---|
6 | |
---|
7 | typedef struct NCbytes { |
---|
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 | } NCbytes; |
---|
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 NCbytes* ncbytesnew(void); |
---|
21 | EXTERNC void ncbytesfree(NCbytes*); |
---|
22 | EXTERNC int ncbytessetalloc(NCbytes*,unsigned int); |
---|
23 | EXTERNC int ncbytessetlength(NCbytes*,unsigned int); |
---|
24 | EXTERNC int ncbytesfill(NCbytes*, char fill); |
---|
25 | |
---|
26 | /* Produce a duplicate of the contents*/ |
---|
27 | EXTERNC char* ncbytesdup(NCbytes*); |
---|
28 | /* Extract the contents and leave buffer empty */ |
---|
29 | EXTERNC char* ncbytesextract(NCbytes*); |
---|
30 | |
---|
31 | /* Return the ith byte; -1 if no such index */ |
---|
32 | EXTERNC int ncbytesget(NCbytes*,unsigned int); |
---|
33 | /* Set the ith byte */ |
---|
34 | EXTERNC int ncbytesset(NCbytes*,unsigned int,char); |
---|
35 | |
---|
36 | /* Append one byte */ |
---|
37 | EXTERNC int ncbytesappend(NCbytes*,char); /* Add at Tail */ |
---|
38 | /* Append n bytes */ |
---|
39 | EXTERNC int ncbytesappendn(NCbytes*,void*,unsigned int); /* Add at Tail */ |
---|
40 | |
---|
41 | /* Null terminate the byte string without extending its length (for debugging) */ |
---|
42 | EXTERNC int ncbytesnull(NCbytes*); |
---|
43 | |
---|
44 | /* Concatenate a null-terminated string to the end of the buffer */ |
---|
45 | EXTERNC int ncbytescat(NCbytes*,char*); |
---|
46 | |
---|
47 | /* Set the contents of the buffer; mark the buffer as non-extendible */ |
---|
48 | EXTERNC int ncbytessetcontents(NCbytes*, char*, unsigned int); |
---|
49 | |
---|
50 | /* Following are always "in-lined"*/ |
---|
51 | #define ncbyteslength(bb) ((bb)?(bb)->length:0U) |
---|
52 | #define ncbytesalloc(bb) ((bb)?(bb)->alloc:0U) |
---|
53 | #define ncbytescontents(bb) ((bb && bb->content)?(bb)->content:(char*)"") |
---|
54 | #define ncbytesextend(bb,len) ncbytessetalloc((bb),(len)+(bb->alloc)) |
---|
55 | #define ncbytesclear(bb) ((bb)?(bb)->length=0:0U) |
---|
56 | #define ncbytesavail(bb,n) ((bb)?((bb)->alloc - (bb)->length) >= (n):0U) |
---|
57 | |
---|
58 | #endif /*NCBYTES_H*/ |
---|