/*
* UCW Library -- Fast Buffered I/O
*
- * (c) 1997--2006 Martin Mares <mj@ucw.cz>
+ * (c) 1997--2007 Martin Mares <mj@ucw.cz>
*
* This software may be freely distributed and used according to the terms
* of the GNU Lesser General Public License.
#include "lib/lib.h"
#include "lib/fastbuf.h"
+#include <stdio.h>
#include <stdlib.h>
void bclose(struct fastbuf *f)
else
{
bflush(f);
- f->seek(f, pos, SEEK_SET);
+ if (!f->seek || !f->seek(f, pos, SEEK_SET))
+ die("bsetpos: stream not seekable");
}
}
return bsetpos(f, btell(f) + pos);
case SEEK_END:
bflush(f);
- f->seek(f, pos, SEEK_END);
+ if (!f->seek || !f->seek(f, pos, SEEK_END))
+ die("bseek: stream not seekable");
break;
default:
die("bseek: invalid whence=%d", whence);
if (f->bptr < f->bstop)
return *f->bptr++;
if (!f->refill(f))
- return EOF;
+ return -1;
return *f->bptr++;
}
if (f->bptr < f->bstop)
return *f->bptr;
if (!f->refill(f))
- return EOF;
+ return -1;
return *f->bptr;
}
if (!f)
return 0;
sh_off_t pos = btell(f);
- bseek(f, 0, SEEK_END);
+ bflush(f);
+ if (!f->seek(f, 0, SEEK_END))
+ return -1;
sh_off_t len = btell(f);
bsetpos(f, pos);
return len;