1 /* Copyright (C) 2001-2019 Artifex Software, Inc.
2    All Rights Reserved.
3 
4    This software is provided AS-IS with no warranty, either express or
5    implied.
6 
7    This software is distributed under license and may not be copied,
8    modified or distributed except as expressly authorized under the terms
9    of the license contained in the file LICENSE in this distribution.
10 
11    Refer to licensing information at http://www.artifex.com or contact
12    Artifex Software, Inc.,  1305 Grant Avenue - Suite 200, Novato,
13    CA 94945, U.S.A., +1(415)492-9861, for further information.
14 */
15 
16 
17 /* Interface for streams that mimic stdio functions (fopen, fread, fseek, ftell) */
18 /* Requires stream.h */
19 
20 #ifndef strmio_INCLUDED
21 #  define strmio_INCLUDED
22 
23 #include "scommon.h"
24 
25 /*
26  * Open a stream using a filename that can include a PS style IODevice prefix
27  * If iodev_default is the '%os' device, then the file will be on the host
28  * file system transparently to the caller. The "%os%" prefix can be used
29  * to explicilty access the host file system.
30  *
31  * NOTE: sfopen() always opens files in "binary" mode on systems where that
32  * is applicable - so callers should not do so themselves.
33  */
34 stream * sfopen(const char *path, const char *mode, gs_memory_t *mem);
35 
36 /*
37  * Read a number of bytes from a stream, returning number read. Return count
38  * will be less than count if EOF or error. Return count is number of elements.
39  */
40 int sfread(void *ptr, size_t size, size_t count, stream *s);
41 
42 /*
43  * Read a byte from a stream
44  */
45 int sfgetc(stream *s);
46 
47 /*
48  * Seek to a position in the stream. Returns the 0, or -1 if error
49  */
50 int sfseek(stream *s, gs_offset_t offset, int whence);
51 
52 /*
53  * Seek to beginning of the file
54  */
55 int srewind(stream *s);
56 
57 /*
58  * Return the current position in the stream or -1 if error.
59  */
60 long sftell(stream *s);
61 
62 /*
63  * Return the EOF status, or 0 if not at EOF.
64  */
65 int sfeof(stream *s);
66 
67 /*
68  * Return the error status, or 0 if no error
69  */
70 int sferror(stream *s);
71 
72 /*
73  * close and free the stream. Any further access (including another call to sfclose())
74  * to  the  stream results in undefined behaviour (reference to freed memory);
75  */
76 int sfclose(stream *s);
77 
78 /* Get a callout-capable stdin stream. */
79 int gs_get_callout_stdin(stream **ps, gs_memory_t *mem);
80 
81 #endif /* strmio_INCLUDED */
82