--- psiconv/trunk/lib/psiconv/buffer.c 2000/12/27 02:12:23 80 +++ psiconv/trunk/lib/psiconv/buffer.c 2014/10/22 19:53:40 351 @@ -1,6 +1,6 @@ /* buffer.c - Part of psiconv, a PSION 5 file formats converter - Copyright (c) 2000 Frodo Looijaard + Copyright (c) 2000-2014 Frodo Looijaard This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -27,6 +27,10 @@ #include "error.h" #include "buffer.h" +#ifdef DMALLOC +#include +#endif + typedef struct psiconv_relocation_s { psiconv_u32 offset; int id; @@ -82,7 +86,6 @@ return psiconv_list_length(buf->data); } - psiconv_u8 *psiconv_buffer_get(const psiconv_buffer buf, psiconv_u32 off) { return psiconv_list_get(buf->data,off); @@ -93,7 +96,7 @@ return psiconv_list_add(buf->data,&data); } -size_t psiconv_buffer_fread(psiconv_buffer buf,size_t size, FILE *f) +size_t psiconv_buffer_fread(psiconv_buffer buf, size_t size, FILE *f) { return psiconv_list_fread(buf->data,size,f); } @@ -108,6 +111,33 @@ return psiconv_list_fwrite_all(buf->data,f); } +int psiconv_buffer_subbuffer(psiconv_buffer *buf, const psiconv_buffer org, + psiconv_u32 offset, psiconv_u32 length) +{ + int i; + int res; + psiconv_u8 *data; + if (! (*buf = psiconv_buffer_new())) { + res = PSICONV_E_NOMEM; + goto ERROR1; + } + for (i = 0; i < length; i++) { + if (!(data = psiconv_buffer_get(org,offset+i))) { + res = PSICONV_E_OTHER; + goto ERROR2; + } + if ((res = psiconv_buffer_add(*buf,*data))) { + goto ERROR2; + } + } + return 0; + +ERROR2: + psiconv_buffer_free(*buf); +ERROR1: + return res; +} + int psiconv_buffer_concat(psiconv_buffer buf, const psiconv_buffer extra) { int res;