2010-06-03 21:24:43 +08:00
|
|
|
/* Copyright 2009, UCAR/Unidata and OPeNDAP, Inc.
|
|
|
|
See the COPYRIGHT file for more information. */
|
|
|
|
|
|
|
|
#ifndef NCBYTES_H
|
|
|
|
#define NCBYTES_H 1
|
|
|
|
|
|
|
|
typedef struct NCbytes {
|
|
|
|
int nonextendible; /* 1 => fail if an attempt is made to extend this buffer*/
|
2014-03-11 00:01:44 +08:00
|
|
|
unsigned long alloc;
|
|
|
|
unsigned long length;
|
2010-06-03 21:24:43 +08:00
|
|
|
char* content;
|
|
|
|
} NCbytes;
|
|
|
|
|
|
|
|
#if defined(_CPLUSPLUS_) || defined(__CPLUSPLUS__) || defined(__CPLUSPLUS)
|
|
|
|
#define EXTERNC extern "C"
|
|
|
|
#else
|
|
|
|
#define EXTERNC extern
|
|
|
|
#endif
|
|
|
|
|
|
|
|
EXTERNC NCbytes* ncbytesnew(void);
|
|
|
|
EXTERNC void ncbytesfree(NCbytes*);
|
2014-03-11 00:01:44 +08:00
|
|
|
EXTERNC int ncbytessetalloc(NCbytes*,unsigned long);
|
|
|
|
EXTERNC int ncbytessetlength(NCbytes*,unsigned long);
|
2010-06-03 21:24:43 +08:00
|
|
|
EXTERNC int ncbytesfill(NCbytes*, char fill);
|
|
|
|
|
|
|
|
/* Produce a duplicate of the contents*/
|
|
|
|
EXTERNC char* ncbytesdup(NCbytes*);
|
|
|
|
/* Extract the contents and leave buffer empty */
|
|
|
|
EXTERNC char* ncbytesextract(NCbytes*);
|
|
|
|
|
|
|
|
/* Return the ith byte; -1 if no such index */
|
2014-03-11 00:01:44 +08:00
|
|
|
EXTERNC int ncbytesget(NCbytes*,unsigned long);
|
2010-06-03 21:24:43 +08:00
|
|
|
/* Set the ith byte */
|
2014-03-11 00:01:44 +08:00
|
|
|
EXTERNC int ncbytesset(NCbytes*,unsigned long,char);
|
2010-06-03 21:24:43 +08:00
|
|
|
|
|
|
|
/* Append one byte */
|
2014-03-11 00:01:44 +08:00
|
|
|
EXTERNC int ncbytesappend(NCbytes*,char); /* Add at Tail */
|
2010-06-03 21:24:43 +08:00
|
|
|
/* Append n bytes */
|
2014-03-11 00:01:44 +08:00
|
|
|
EXTERNC int ncbytesappendn(NCbytes*,const void*,unsigned long); /* Add at Tail */
|
2010-06-03 21:24:43 +08:00
|
|
|
|
2010-10-15 06:34:52 +08:00
|
|
|
/* Null terminate the byte string without extending its length (for debugging) */
|
|
|
|
EXTERNC int ncbytesnull(NCbytes*);
|
|
|
|
|
2010-06-03 21:24:43 +08:00
|
|
|
/* Concatenate a null-terminated string to the end of the buffer */
|
2012-08-01 04:34:13 +08:00
|
|
|
EXTERNC int ncbytescat(NCbytes*,const char*);
|
2010-10-15 06:34:52 +08:00
|
|
|
|
2010-06-03 21:24:43 +08:00
|
|
|
/* Set the contents of the buffer; mark the buffer as non-extendible */
|
2014-03-11 00:01:44 +08:00
|
|
|
EXTERNC int ncbytessetcontents(NCbytes*, char*, unsigned long);
|
2010-06-03 21:24:43 +08:00
|
|
|
|
|
|
|
/* Following are always "in-lined"*/
|
2012-08-20 05:12:35 +08:00
|
|
|
#define ncbyteslength(bb) ((bb)!=NULL?(bb)->length:0)
|
|
|
|
#define ncbytesalloc(bb) ((bb)!=NULL?(bb)->alloc:0)
|
2012-08-09 07:15:18 +08:00
|
|
|
#define ncbytescontents(bb) (((bb)!=NULL && (bb)->content!=NULL)?(bb)->content:(char*)"")
|
2010-06-03 21:24:43 +08:00
|
|
|
#define ncbytesextend(bb,len) ncbytessetalloc((bb),(len)+(bb->alloc))
|
2012-08-20 05:12:35 +08:00
|
|
|
#define ncbytesclear(bb) ((bb)!=NULL?(bb)->length=0:0)
|
|
|
|
#define ncbytesavail(bb,n) ((bb)!=NULL?((bb)->alloc - (bb)->length) >= (n):0)
|
2010-06-03 21:24:43 +08:00
|
|
|
|
|
|
|
#endif /*NCBYTES_H*/
|