1 diff -urN poldek-0.18.8.org/pkgfl.c poldek-0.18.8/pkgfl.c
2 --- poldek-0.18.8.org/pkgfl.c 2004-12-30 13:05:22.000000000 +0100
3 +++ poldek-0.18.8/pkgfl.c 2005-04-21 22:06:58.126819592 +0200
11 if (fread(&size, sizeof(size), 1, stream) != 1)
14 fl = pkgfl_restore(&nbufi, dirs, include);
17 - fseek(stream, 1, SEEK_CUR); /* skip final '\n' */
18 + fread(&dummy, 1, 1, stream); /* skip final '\n' */
23 int pkgfl_skip_f(FILE *stream)
28 if (fread(&size, sizeof(size), 1, stream) != 1)
32 - fseek(stream, size + 1, SEEK_CUR);
33 + buf = malloc(size + 1);
35 + fread(buf, 1, size + 1, stream);
37 + fseek(stream, size + 1, SEEK_CUR);
42 diff -urN poldek-0.18.8.org/pkgu.c poldek-0.18.8/pkgu.c
43 --- poldek-0.18.8.org/pkgu.c 2002-05-15 17:42:48.000000000 +0200
44 +++ poldek-0.18.8/pkgu.c 2005-04-21 22:47:36.188177928 +0200
50 - if (fseek(stream, offset, SEEK_SET) != 0) {
51 - logn(LOGERR, "pkguinf_restore: fseek %ld: %m", offset);
55 + long currseek = ftell(stream);
57 + if (currseek == -1) {
58 + logn(LOGERR, "pkguinf_restore: ftell %ld: %m", currseek);
61 + if (offset >= currseek) {
62 + currseek = offset - currseek;
64 + buf = malloc(currseek);
66 + logn(LOGERR, "pkguinf_restore: malloc: %m");
69 + if (fread(buf, 1, currseek, stream) != currseek) {
70 + logn(LOGERR, "pkguinf_restore: fread error currseek: at %ld %p",
71 + ftell(stream), stream);
78 + if (fseek(stream, offset, SEEK_SET) != 0) {
79 + logn(LOGERR, "pkguinf_restore: fseek %ld: %m", offset);
85 if (fread(&nlangs, sizeof(nlangs), 1, stream) != 1) {
86 logn(LOGERR, "pkguinf_restore: read error nlangs (%m) at %ld %p",
89 uint16_t nsize, nlangs;
91 - fseek(stream, sizeof(nlangs), SEEK_CUR);
92 - if (fread(&nsize, sizeof(nsize), 1, stream) != 1) {
93 + if ((fread(&nlangs, sizeof(nlangs), 1, stream) != 1) ||
94 + (fread(&nsize, sizeof(nsize), 1, stream) != 1)) {
97 nsize = ntoh16(nsize);
98 diff -urN poldek-0.18.8.org/trurlib/nstream.c poldek-0.18.8/trurlib/nstream.c
99 --- poldek-0.18.8.org/trurlib/nstream.c 2004-05-06 09:57:45.000000000 +0200
100 +++ poldek-0.18.8/trurlib/nstream.c 2005-04-21 22:04:22.622459848 +0200
102 z_off_t rc, off = *offset;
104 rc = gzseek(stream, off, whence);
111 printf("zfseek (%p, %ld, %lld, %d) = %d\n", stream, off, *offset, whence, rc);
117 - fseek(st->stream, 0, SEEK_SET); /* glibc BUG (?) */
118 + fseek(st->stream, 0, SEEK_SET); /* XXX glibc BUG (?) */
122 diff -urN poldek-0.18.8.org/vfile/vfile.c poldek-0.18.8/vfile/vfile.c
123 --- poldek-0.18.8.org/vfile/vfile.c 2004-02-26 19:22:28.000000000 +0100
124 +++ poldek-0.18.8/vfile/vfile.c 2005-04-21 22:04:22.630458632 +0200
126 z_off_t rc, off = *offset;
128 rc = gzseek(stream, off, whence);
135 printf("zfseek (%p, %ld, %lld, %d) = %d\n", stream, off, *offset, whence, rc);
138 vf->vf_stream = fopencookie(gzstream, mode, gzio_cookie);
139 if (vf->vf_stream != NULL) {
141 - fseek(vf->vf_stream, 0, SEEK_SET); /* glibc BUG (?) */
142 + vf->vf_buf = malloc(128); /* use small buffer to avoid reverse gzseeks on small forward fseeks */
143 + if(vf->vf_buf == NULL)
144 + vfile_err_fn("buffer malloc failed for %s\n", CL_URL(path));
146 + if(setvbuf(vf->vf_stream, vf->vf_buf, _IOFBF, 128) != 0) {
147 + vfile_err_fn("setvbuf failed for %s\n", CL_URL(path));
151 + fseek(vf->vf_stream, 0, SEEK_SET); /* XXX glibc BUG (?) */
153 vfile_err_fn("fopencookie %s: hgw error\n", CL_URL(path));
161 urltype = vf_url_type(path);
165 vf->vf_tmpath = NULL;
169 memset(vf, 0, sizeof(*vf));
172 diff -urN poldek-0.18.8.org/vfile/vfile.h poldek-0.18.8/vfile/vfile.h
173 --- poldek-0.18.8.org/vfile/vfile.h 2004-06-08 15:57:03.000000000 +0200
174 +++ poldek-0.18.8/vfile/vfile.h 2005-04-21 22:04:22.634458024 +0200