1 /* Copyright (C) 2001-2012 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.,  7 Mt. Lassen Drive - Suite A-134, San Rafael,
13    CA  94903, U.S.A., +1(415)492-9861, for further information.
14 */
15 
16 
17 /* I/O interface for command lists */
18 
19 #ifndef gxclio_INCLUDED
20 #  define gxclio_INCLUDED
21 
22 #include "gp.h"			/* for gp_file_name_sizeof */
23 
24 /*
25  * There are two implementations of the I/O interface for command lists --
26  * one suitable for embedded systems, which stores the "files" in RAM, and
27  * one suitable for other systems, which uses an external file system --
28  * with the choice made at compile/link time.  This header file defines the
29  * API between the command list code proper and its I/O interface.
30  */
31 
32 typedef void *clist_file_ptr;	/* We can't do any better than this. */
33 
34 struct clist_io_procs_s {
35 
36     /* ---------------- Open/close/unlink ---------------- */
37 
38     /*
39      * If *fname = 0, generate and store a new scratch file name; otherwise,
40      * open an existing file.  Only modes "r" and "w+" are supported,
41      * and only binary data (but the caller must append the "b" if needed).
42      * Mode "r" with *fname = 0 is an error.
43      */
44     int (*fopen)(char fname[gp_file_name_sizeof], const char *fmode,
45                     clist_file_ptr * pcf,
46                     gs_memory_t * mem, gs_memory_t *data_mem,
47                     bool ok_to_compress);
48 
49     /*
50      * Close a file, optionally deleting it.
51      */
52     int (*fclose)(clist_file_ptr cf, const char *fname, bool delete);
53 
54     /*
55      * Delete a file.
56      */
57     int (*unlink)(const char *fname);
58 
59     /* ---------------- Writing ---------------- */
60 
61     int (*fwrite_chars)(const void *data, uint len, clist_file_ptr cf);
62 
63     /* ---------------- Reading ---------------- */
64 
65     int (*fread_chars)(void *data, uint len, clist_file_ptr cf);
66 
67     /* ---------------- Position/status ---------------- */
68 
69     /*
70      * Set the low-memory warning threshold.  clist_ferror_code will return 1
71      * if fewer than this many bytes of memory are left for storing band data.
72      */
73     int (*set_memory_warning)(clist_file_ptr cf, int bytes_left);
74 
75     /*
76      * clist_ferror_code returns a negative error code per gserrors.h, not a
77      * Boolean; 0 means no error, 1 means low-memory warning.
78      */
79     int (*ferror_code)(clist_file_ptr cf);
80 
81     int64_t (*ftell)(clist_file_ptr cf);
82 
83     /*
84      * We pass the file name to clist_rewind and clist_fseek in case the
85      * implementation has to close and reopen the file.  (clist_fseek with
86      * offset = 0 and mode = SEEK_END indicates we are about to append.)
87      */
88     void (*rewind)(clist_file_ptr cf, bool discard_data, const char *fname);
89 
90     int (*fseek)(clist_file_ptr cf, int64_t offset, int mode, const char *fname);
91 };
92 
93 typedef struct clist_io_procs_s clist_io_procs_t;
94 
95 extern const clist_io_procs_t *clist_io_procs_file_global;
96 extern const clist_io_procs_t *clist_io_procs_memory_global;
97 
98 #endif /* gxclio_INCLUDED */
99