diff options
author | Tor Andersson <tor@ghostscript.com> | 2004-10-05 09:52:44 +0200 |
---|---|---|
committer | Tor Andersson <tor@ghostscript.com> | 2004-10-05 09:52:44 +0200 |
commit | 9ce9759c580d5522ad2d3812b26aff49644d8881 (patch) | |
tree | 2eb3aa263955f7bdfe4461624aa3dfe8d9992e83 /filter | |
parent | 7ad0eac4b8c81c5123ef5a62b23ba2895dd997c8 (diff) | |
download | mupdf-9ce9759c580d5522ad2d3812b26aff49644d8881.tar.xz |
improved reading to buffers and writing files
Diffstat (limited to 'filter')
-rw-r--r-- | filter/buffer.c | 2 | ||||
-rw-r--r-- | filter/filec.c | 9 | ||||
-rw-r--r-- | filter/filer.c | 23 | ||||
-rw-r--r-- | filter/filew.c | 7 |
4 files changed, 30 insertions, 11 deletions
diff --git a/filter/buffer.c b/filter/buffer.c index 25e30a55..aae27474 100644 --- a/filter/buffer.c +++ b/filter/buffer.c @@ -32,7 +32,7 @@ fz_newbufferwithdata(fz_buffer **bp, unsigned char *data, int size) b->bp = data; b->rp = b->bp; - b->wp = b->bp; + b->wp = b->bp + size; b->ep = b->bp + size; b->eof = 0; diff --git a/filter/filec.c b/filter/filec.c index f62d1265..fc5599e1 100644 --- a/filter/filec.c +++ b/filter/filec.c @@ -13,15 +13,20 @@ fz_openfile(fz_file **filep, char *path, int mode) { fz_error *error; fz_file *file; + int realmode; int fd; - assert(mode == O_RDONLY || mode == O_WRONLY); + assert(mode == O_RDONLY || mode == O_WRONLY || mode == O_APPEND); + + realmode = mode; + if (mode == O_WRONLY) + realmode = O_WRONLY | O_CREAT | O_TRUNC; file = *filep = fz_malloc(sizeof(fz_file)); if (!file) return fz_outofmem; - fd = open(path, mode, 0); + fd = open(path, realmode, 0644); if (fd == -1) return fz_throw("ioerror: open '%s': %s", path, strerror(errno)); diff --git a/filter/filer.c b/filter/filer.c index 804d7f7e..368f9dbe 100644 --- a/filter/filer.c +++ b/filter/filer.c @@ -175,11 +175,12 @@ fz_readline(fz_file *f, char *buf, int n) * a freshly allocated buffer; realloced and trimmed to size. */ -enum { CHUNKSIZE = 4096 }; +enum { CHUNKSIZE = 1024 * 32 }; fz_error * -fz_readfile(unsigned char **bufp, int *lenp, fz_file *file) +fz_readfile(fz_buffer **bufp, fz_file *file) { + fz_buffer *real; unsigned char *newbuf; unsigned char *buf; int len; @@ -187,7 +188,6 @@ fz_readfile(unsigned char **bufp, int *lenp, fz_file *file) int n; *bufp = nil; - *lenp = 0; len = 0; pos = 0; @@ -209,8 +209,6 @@ fz_readfile(unsigned char **bufp, int *lenp, fz_file *file) n = fz_read(file, buf + pos, len - pos); -printf("fz_read %d bytes\n", n); - if (n < 0) { fz_free(buf); @@ -228,8 +226,19 @@ printf("fz_read %d bytes\n", n); return fz_outofmem; } - *bufp = newbuf; - *lenp = pos; + real = *bufp = fz_malloc(sizeof(fz_buffer)); + if (!real) + { + fz_free(newbuf); + return fz_outofmem; + } + + real->ownsdata = 1; + real->bp = buf; + real->rp = buf; + real->wp = buf + pos; + real->ep = buf + pos; + return nil; } } diff --git a/filter/filew.c b/filter/filew.c index 0422e60e..a7b15664 100644 --- a/filter/filew.c +++ b/filter/filew.c @@ -99,7 +99,12 @@ fz_write(fz_file *f, char *buf, int n) return -1; } - fz_rewindbuffer(f->in); + if (f->in->rp > f->in->bp) + f->error = fz_rewindbuffer(f->in); + else + f->error = fz_growbuffer(f->in); + if (f->error) + return -1; } } |