summaryrefslogtreecommitdiff
path: root/databases/pxlib/files/patch-src-px_io.c
blob: 420df4a2f7ecdce653594d31ab5debfe38713a78 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
--- 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;
 }
 /* }}} */