68#include <config_auto.h>
72#include "allheaders.h"
76static 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);
159 if ((fp = fopenReadStream(fname)) == NULL)
160 return (
L_BYTEA *)ERROR_PTR_1(
"file stream not opened",
161 fname, __func__, NULL);
165 return (
L_BYTEA *)ERROR_PTR_1(
"ba not made", fname, __func__, NULL);
184 return (
L_BYTEA *)ERROR_PTR(
"stream not defined", __func__, NULL);
186 if ((data = l_binaryReadStream(fp, &nbytes)) == NULL)
187 return (
L_BYTEA *)ERROR_PTR(
"data not read", __func__, NULL);
190 return (
L_BYTEA *)ERROR_PTR(
"ba not made", __func__, NULL);
192 memcpy(ba->
data, data, nbytes);
216 return (
L_BYTEA *)ERROR_PTR(
"bas not defined", __func__, NULL);
247 L_WARNING(
"ptr address is null!\n", __func__);
251 if ((ba = *pba) == NULL)
276 return ERROR_INT(
"ba not defined", __func__, 0);
298 return (l_uint8 *)ERROR_PTR(
"ba not defined", __func__, NULL);
300 return (l_uint8 *)ERROR_PTR(
"&size not defined", __func__, NULL);
327 return (l_uint8 *)ERROR_PTR(
"&size not defined", __func__, NULL);
330 return (l_uint8 *)ERROR_PTR(
"ba not defined", __func__, NULL);
333 return l_binaryCopy(data, *psize);
350 const l_uint8 *newdata,
353size_t size, nalloc, reqsize;
356 return ERROR_INT(
"ba not defined", __func__, 1);
358 return ERROR_INT(
"newdata not defined", __func__, 1);
361 reqsize = size + newbytes + 1;
363 if (nalloc < reqsize) {
365 return ERROR_INT(
"extension failed", __func__, 1);
368 memcpy(ba->
data + size, newdata, newbytes);
369 ba->
size += newbytes;
385size_t size, len, nalloc, reqsize;
388 return ERROR_INT(
"ba not defined", __func__, 1);
390 return ERROR_INT(
"str not defined", __func__, 1);
394 reqsize = size + len + 1;
396 if (nalloc < reqsize) {
398 return ERROR_INT(
"extension failed", __func__, 1);
401 memcpy(ba->
data + size, str, len);
425 return ERROR_INT(
"ba not defined", __func__, 1);
426 if (ba->
nalloc > MaxArraySize)
427 return ERROR_INT(
"ba has too many ptrs", __func__, 1);
428 if (size > MaxArraySize)
429 return ERROR_INT(
"size > 1 GB; too large", __func__, 1);
430 if (size <= ba->nalloc) {
431 L_INFO(
"size too small; no extension\n", __func__);
436 (l_uint8 *)reallocNew((
void **)&ba->
data, ba->
nalloc, size)) == NULL)
437 return ERROR_INT(
"new array not returned", __func__, 1);
468 return ERROR_INT(
"ba1 not defined", __func__, 1);
470 return ERROR_INT(
"&ba2 not defined", __func__, 1);
471 if ((ba2 = *pba2) == NULL)
return 0;
495size_t nbytes1, nbytes2;
498 return ERROR_INT(
"&ba2 not defined", __func__, 1);
501 return ERROR_INT(
"ba1 not defined", __func__, 1);
504 if (splitloc >= nbytes1)
505 return ERROR_INT(
"splitloc invalid", __func__, 1);
506 nbytes2 = nbytes1 - splitloc;
512 memset(data1 + splitloc, 0, nbytes2);
513 ba1->
size = splitloc;
532 const l_uint8 *sequence,
540 return ERROR_INT(
"&da not defined", __func__, 1);
543 return ERROR_INT(
"ba not defined", __func__, 1);
545 return ERROR_INT(
"sequence not defined", __func__, 1);
548 *pda = arrayFindEachSequence(data, size, sequence, seqlen);
576 return ERROR_INT(
"fname not defined", __func__, 1);
578 return ERROR_INT(
"ba not defined", __func__, 1);
580 if ((fp = fopenWriteStream(fname,
"wb")) == NULL)
581 return ERROR_INT_1(
"stream not opened", fname, __func__, 1);
605size_t size, maxbytes;
608 return ERROR_INT(
"stream not defined", __func__, 1);
610 return ERROR_INT(
"ba not defined", __func__, 1);
613 if (startloc >= size)
614 return ERROR_INT(
"invalid startloc", __func__, 1);
615 maxbytes = size - startloc;
616 nbytes = (nbytes == 0) ? maxbytes : L_MIN(nbytes, maxbytes);
618 fwrite(data + startloc, 1, nbytes, fp);
L_BYTEA * l_byteaInitFromMem(const l_uint8 *data, size_t size)
l_byteaInitFromMem()
L_BYTEA * l_byteaCreate(size_t nbytes)
l_byteaCreate()
size_t l_byteaGetSize(L_BYTEA *ba)
l_byteaGetSize()
L_BYTEA * l_byteaInitFromFile(const char *fname)
l_byteaInitFromFile()
l_ok l_byteaFindEachSequence(L_BYTEA *ba, const l_uint8 *sequence, size_t seqlen, L_DNA **pda)
l_byteaFindEachSequence()
l_ok l_byteaSplit(L_BYTEA *ba1, size_t splitloc, L_BYTEA **pba2)
l_byteaSplit()
L_BYTEA * l_byteaInitFromStream(FILE *fp)
l_byteaInitFromStream()
l_uint8 * l_byteaCopyData(L_BYTEA *ba, size_t *psize)
l_byteaCopyData()
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()
void l_byteaDestroy(L_BYTEA **pba)
l_byteaDestroy()
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_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_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()