68 #include <config_auto.h>
72 #include "allheaders.h"
76 static const l_uint32 MaxArraySize = 1000000000;
102 if (nbytes <= 0 || nbytes > MaxArraySize)
105 ba->
data = (l_uint8 *)LEPT_CALLOC(nbytes + 1,
sizeof(l_uint8));
108 return (
L_BYTEA *)ERROR_PTR(
"ba array not made", __func__, NULL);
130 return (
L_BYTEA *)ERROR_PTR(
"data not defined", __func__, NULL);
132 return (
L_BYTEA *)ERROR_PTR(
"no bytes to initialize", __func__, NULL);
133 if (size > MaxArraySize)
134 return (
L_BYTEA *)ERROR_PTR(
"size is too big", __func__, NULL);
137 return (
L_BYTEA *)ERROR_PTR(
"ba not made", __func__, NULL);
138 memcpy(ba->
data, data, size);
157 return (
L_BYTEA *)ERROR_PTR(
"fname not defined", __func__, NULL);
160 return (
L_BYTEA *)ERROR_PTR(
"file stream not opened", __func__, NULL);
164 return (
L_BYTEA *)ERROR_PTR(
"ba not made", __func__, NULL);
183 return (
L_BYTEA *)ERROR_PTR(
"stream not defined", __func__, NULL);
186 return (
L_BYTEA *)ERROR_PTR(
"data not read", __func__, NULL);
189 return (
L_BYTEA *)ERROR_PTR(
"ba not made", __func__, NULL);
191 memcpy(ba->
data, data, nbytes);
215 return (
L_BYTEA *)ERROR_PTR(
"bas not defined", __func__, NULL);
246 L_WARNING(
"ptr address is null!\n", __func__);
250 if ((ba = *pba) == NULL)
275 return ERROR_INT(
"ba not defined", __func__, 0);
297 return (l_uint8 *)ERROR_PTR(
"ba not defined", __func__, NULL);
299 return (l_uint8 *)ERROR_PTR(
"&size not defined", __func__, NULL);
326 return (l_uint8 *)ERROR_PTR(
"&size not defined", __func__, NULL);
329 return (l_uint8 *)ERROR_PTR(
"ba not defined", __func__, NULL);
349 const l_uint8 *newdata,
352 size_t size, nalloc, reqsize;
355 return ERROR_INT(
"ba not defined", __func__, 1);
357 return ERROR_INT(
"newdata not defined", __func__, 1);
360 reqsize = size + newbytes + 1;
362 if (nalloc < reqsize) {
364 return ERROR_INT(
"extension failed", __func__, 1);
367 memcpy(ba->
data + size, newdata, newbytes);
368 ba->
size += newbytes;
384 size_t size, len, nalloc, reqsize;
387 return ERROR_INT(
"ba not defined", __func__, 1);
389 return ERROR_INT(
"str not defined", __func__, 1);
393 reqsize = size + len + 1;
395 if (nalloc < reqsize) {
397 return ERROR_INT(
"extension failed", __func__, 1);
400 memcpy(ba->
data + size, str, len);
424 return ERROR_INT(
"ba not defined", __func__, 1);
425 if (ba->
nalloc > MaxArraySize)
426 return ERROR_INT(
"ba has too many ptrs", __func__, 1);
427 if (size > MaxArraySize)
428 return ERROR_INT(
"size > 1 GB; too large", __func__, 1);
429 if (size <= ba->nalloc) {
430 L_INFO(
"size too small; no extension\n", __func__);
436 return ERROR_INT(
"new array not returned", __func__, 1);
467 return ERROR_INT(
"ba1 not defined", __func__, 1);
469 return ERROR_INT(
"&ba2 not defined", __func__, 1);
470 if ((ba2 = *pba2) == NULL)
return 0;
494 size_t nbytes1, nbytes2;
497 return ERROR_INT(
"&ba2 not defined", __func__, 1);
500 return ERROR_INT(
"ba1 not defined", __func__, 1);
503 if (splitloc >= nbytes1)
504 return ERROR_INT(
"splitloc invalid", __func__, 1);
505 nbytes2 = nbytes1 - splitloc;
511 memset(data1 + splitloc, 0, nbytes2);
512 ba1->
size = splitloc;
531 const l_uint8 *sequence,
539 return ERROR_INT(
"&da not defined", __func__, 1);
542 return ERROR_INT(
"ba not defined", __func__, 1);
544 return ERROR_INT(
"sequence not defined", __func__, 1);
575 return ERROR_INT(
"fname not defined", __func__, 1);
577 return ERROR_INT(
"ba not defined", __func__, 1);
580 return ERROR_INT(
"stream not opened", __func__, 1);
604 size_t size, maxbytes;
607 return ERROR_INT(
"stream not defined", __func__, 1);
609 return ERROR_INT(
"ba not defined", __func__, 1);
612 if (startloc >= size)
613 return ERROR_INT(
"invalid startloc", __func__, 1);
614 maxbytes = size - startloc;
615 nbytes = (nbytes == 0) ? maxbytes : L_MIN(nbytes, maxbytes);
617 fwrite(data + startloc, 1, nbytes, fp);
l_uint8 * l_byteaCopyData(L_BYTEA *ba, size_t *psize)
l_byteaCopyData()
size_t l_byteaGetSize(L_BYTEA *ba)
l_byteaGetSize()
l_ok l_byteaFindEachSequence(L_BYTEA *ba, const l_uint8 *sequence, size_t seqlen, L_DNA **pda)
l_byteaFindEachSequence()
l_uint8 * l_byteaGetData(L_BYTEA *ba, size_t *psize)
l_byteaGetData()
L_BYTEA * l_byteaCopy(L_BYTEA *bas, l_int32 copyflag)
l_byteaCopy()
l_ok l_byteaSplit(L_BYTEA *ba1, size_t splitloc, L_BYTEA **pba2)
l_byteaSplit()
static l_int32 l_byteaExtendArrayToSize(L_BYTEA *ba, size_t size)
l_byteaExtendArrayToSize()
l_ok l_byteaWrite(const char *fname, L_BYTEA *ba, size_t startloc, size_t nbytes)
l_byteaWrite()
L_BYTEA * l_byteaCreate(size_t nbytes)
l_byteaCreate()
void l_byteaDestroy(L_BYTEA **pba)
l_byteaDestroy()
L_BYTEA * l_byteaInitFromMem(const l_uint8 *data, size_t size)
l_byteaInitFromMem()
l_ok l_byteaWriteStream(FILE *fp, L_BYTEA *ba, size_t startloc, size_t nbytes)
l_byteaWriteStream()
l_ok l_byteaAppendString(L_BYTEA *ba, const char *str)
l_byteaAppendString()
static const l_int32 InitialArraySize
L_BYTEA * l_byteaInitFromStream(FILE *fp)
l_byteaInitFromStream()
L_BYTEA * l_byteaInitFromFile(const char *fname)
l_byteaInitFromFile()
l_ok l_byteaJoin(L_BYTEA *ba1, L_BYTEA **pba2)
l_byteaJoin()
l_ok l_byteaAppendData(L_BYTEA *ba, const l_uint8 *newdata, size_t newbytes)
l_byteaAppendData()
l_uint8 * l_binaryReadStream(FILE *fp, size_t *pnbytes)
l_binaryReadStream()
FILE * fopenWriteStream(const char *filename, const char *modestring)
fopenWriteStream()
L_DNA * arrayFindEachSequence(const l_uint8 *data, size_t datalen, const l_uint8 *sequence, size_t seqlen)
arrayFindEachSequence()
void * reallocNew(void **pindata, size_t oldsize, size_t newsize)
reallocNew()
FILE * fopenReadStream(const char *filename)
fopenReadStream()
l_uint8 * l_binaryCopy(const l_uint8 *datas, size_t size)
l_binaryCopy()