summaryrefslogtreecommitdiff
path: root/fitz/stm_open.c
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2011-04-04 01:06:30 +0200
committerTor Andersson <tor.andersson@artifex.com>2011-04-04 01:06:30 +0200
commit4d125739c1ac42d629360a7e2700410e788028c7 (patch)
treea6cb6812fcde435c79ab646b3496c075e4e0a094 /fitz/stm_open.c
parentfc5ff7b56e0e0797570eba81a39e13d40aaccb40 (diff)
downloadmupdf-4d125739c1ac42d629360a7e2700410e788028c7.tar.xz
Change how files are opened with fz_openfd/file/filew.
Diffstat (limited to 'fitz/stm_open.c')
-rw-r--r--fitz/stm_open.c43
1 files changed, 41 insertions, 2 deletions
diff --git a/fitz/stm_open.c b/fitz/stm_open.c
index 6f1160d8..c7cf8409 100644
--- a/fitz/stm_open.c
+++ b/fitz/stm_open.c
@@ -78,7 +78,7 @@ static void closefile(fz_stream *stm)
}
fz_stream *
-fz_openfile(int fd)
+fz_openfd(int fd)
{
fz_stream *stm;
int *state;
@@ -92,6 +92,26 @@ fz_openfile(int fd)
return stm;
}
+fz_stream *
+fz_openfile(const char *name)
+{
+ int fd = open(name, O_BINARY | O_RDONLY, 0);
+ if (fd == -1)
+ return nil;
+ return fz_openfd(fd);
+}
+
+#ifdef _WIN32
+fz_stream *
+fz_openfilew(const wchar_t *name)
+{
+ int fd = _wopen(name, O_BINARY | O_RDONLY, 0);
+ if (fd == -1)
+ return nil;
+ return fz_openfd(fd);
+}
+#endif
+
/* Memory stream */
static int readbuffer(fz_stream *stm, unsigned char *buf, int len)
@@ -113,7 +133,8 @@ static void seekbuffer(fz_stream *stm, int offset, int whence)
static void closebuffer(fz_stream *stm)
{
- fz_dropbuffer(stm->state);
+ if (stm->state)
+ fz_dropbuffer(stm->state);
}
fz_stream *
@@ -133,3 +154,21 @@ fz_openbuffer(fz_buffer *buf)
return stm;
}
+
+fz_stream *
+fz_openmemory(unsigned char *data, int len)
+{
+ fz_stream *stm;
+
+ stm = fz_newstream(nil, readbuffer, closebuffer);
+ stm->seek = seekbuffer;
+
+ stm->bp = data;
+ stm->rp = data;
+ stm->wp = data + len;
+ stm->ep = data + len;
+
+ stm->pos = len;
+
+ return stm;
+}