ports/databases/pxlib/files/patch-src-px_io.c

85 lines
2.2 KiB
C

--- src/px_io.c.orig Sun Dec 11 13:12:58 2005
+++ src/px_io.c Sun Dec 11 13:13:26 2005
@@ -346,82 +346,6 @@
*/
size_t px_mb_write(pxblob_t *p, pxstream_t *dummy, size_t len, void *buffer) {
return(p->mb_stream->write(p->pxdoc, p->mb_stream, len, buffer));
- pxdoc_t *pxdoc;
- pxhead_t *pxh;
- pxstream_t *pxs;
- long pos;
- int ret;
- unsigned char *tmpbuf = NULL;
- unsigned int blockslen, blockoffset;
-
- pxdoc = p->pxdoc;
- pxh = pxdoc->px_head;
- pxs = p->mb_stream;
-
- if (pxh->px_encryption == 0)
- return pxs->write(pxdoc, pxs, len, buffer);
-
- pos = pxs->tell(pxdoc, pxs);
- if (pos < 0) {
- return pos;
- }
-
- blockoffset = (pos >> BLOCKSIZEEXP) << BLOCKSIZEEXP;
- /* We need to read at least chunk from the blockoffset till the
- * desired postion and the data itself which has len bytes.
- * e.g. if we want to read 20 bytes starting at position 300 in the
- * file, we will need to read 44+20 bytes starting at position 256.
- */
- blockslen = len + pos - blockoffset;
- /* Check if the end of the data is within a 2^BLOCKSIZEEXP bytes block.
- * If that is the case, we will need to read the remainder of the
- * 2^BLOCKSIZEEXP bytes block as well. In the above example, we
- * will have to read 256 bytes instead of just 64.
- */
- if(blockslen & 0xff)
- blockslen = ((blockslen >> BLOCKSIZEEXP) + 1) << BLOCKSIZEEXP;
-
- assert(blockslen >= len);
- assert(blockoffset <= (unsigned long)pos);
- assert((blockoffset+blockslen) >= (pos+len));
-
- ret = pxs->seek(pxdoc, pxs, blockoffset, SEEK_SET);
- if (ret < 0) {
- return ret;
- }
-
- tmpbuf = (unsigned char *) malloc(blockslen);
- if (tmpbuf == NULL) {
- return -ENOMEM;
- }
-
- ret = pxs->read(pxdoc, pxs, blockslen, tmpbuf);
- if (ret < 0) {
- goto end;
- }
-
- px_decrypt_mb_block(tmpbuf, tmpbuf, pxh->px_encryption, blockslen);
- memcpy(tmpbuf + (pos - blockoffset), buffer, len);
- px_encrypt_mb_block(tmpbuf, tmpbuf, pxh->px_encryption, blockslen);
-
- ret = pxs->seek(pxdoc, pxs, blockoffset, SEEK_SET);
- if (ret < 0) {
- return ret;
- }
- ret = pxs->write(pxdoc, pxs, blockslen, tmpbuf);
- if (ret < 0) {
- goto end;
- }
-
- ret = pxs->seek(pxdoc, pxs, pos + len, SEEK_SET);
- if (ret < 0) {
- goto end;
- }
-
- ret = len;
-end:
- free(tmpbuf);
- return ret;
}
/* }}} */