xref: /plan9/sys/src/cmd/gs/src/gxclio.h (revision 593dc095aefb2a85c828727bbfa9da139a49bdf4)
1 /* Copyright (C) 1995, 1997, 1998 Aladdin Enterprises.  All rights reserved.
2 
3   This software is provided AS-IS with no warranty, either express or
4   implied.
5 
6   This software is distributed under license and may not be copied,
7   modified or distributed except as expressly authorized under the terms
8   of the license contained in the file LICENSE in this distribution.
9 
10   For more information about licensing, please refer to
11   http://www.ghostscript.com/licensing/. For information on
12   commercial licensing, go to http://www.artifex.com/licensing/ or
13   contact Artifex Software, Inc., 101 Lucas Valley Road #110,
14   San Rafael, CA  94903, U.S.A., +1(415)492-9861.
15 */
16 
17 /* $Id: gxclio.h,v 1.5 2002/06/16 08:45:43 lpd Exp $ */
18 /* I/O interface for command lists */
19 
20 #ifndef gxclio_INCLUDED
21 #  define gxclio_INCLUDED
22 
23 #include "gp.h"			/* for gp_file_name_sizeof */
24 
25 /*
26  * There are two implementations of the I/O interface for command lists --
27  * one suitable for embedded systems, which stores the "files" in RAM, and
28  * one suitable for other systems, which uses an external file system --
29  * with the choice made at compile/link time.  This header file defines the
30  * API between the command list code proper and its I/O interface.
31  */
32 
33 typedef void *clist_file_ptr;	/* We can't do any better than this. */
34 
35 /* ---------------- Open/close/unlink ---------------- */
36 
37 /*
38  * If *fname = 0, generate and store a new scratch file name; otherwise,
39  * open an existing file.  Only modes "r" and "w+" are supported,
40  * and only binary data (but the caller must append the "b" if needed).
41  * Mode "r" with *fname = 0 is an error.
42  */
43 int clist_fopen(char fname[gp_file_name_sizeof], const char *fmode,
44 		clist_file_ptr * pcf,
45 		gs_memory_t * mem, gs_memory_t *data_mem,
46 		bool ok_to_compress);
47 
48 /*
49  * Close a file, optionally deleting it.
50  */
51 int clist_fclose(clist_file_ptr cf, const char *fname, bool delete);
52 
53 /*
54  * Delete a file.
55  */
56 int clist_unlink(const char *fname);
57 
58 /* ---------------- Writing ---------------- */
59 
60 /* clist_space_available returns min(requested, available). */
61 long clist_space_available(long requested);
62 
63 int clist_fwrite_chars(const void *data, uint len, clist_file_ptr cf);
64 
65 /* ---------------- Reading ---------------- */
66 
67 int clist_fread_chars(void *data, uint len, clist_file_ptr cf);
68 
69 /* ---------------- Position/status ---------------- */
70 
71 /*
72  * Set the low-memory warning threshold.  clist_ferror_code will return 1
73  * if fewer than this many bytes of memory are left for storing band data.
74  */
75 int clist_set_memory_warning(clist_file_ptr cf, int bytes_left);
76 
77 /*
78  * clist_ferror_code returns a negative error code per gserrors.h, not a
79  * Boolean; 0 means no error, 1 means low-memory warning.
80  */
81 int clist_ferror_code(clist_file_ptr cf);
82 
83 long clist_ftell(clist_file_ptr cf);
84 
85 /*
86  * We pass the file name to clist_rewind and clist_fseek in case the
87  * implementation has to close and reopen the file.  (clist_fseek with
88  * offset = 0 and mode = SEEK_END indicates we are about to append.)
89  */
90 void clist_rewind(clist_file_ptr cf, bool discard_data, const char *fname);
91 
92 int clist_fseek(clist_file_ptr cf, long offset, int mode, const char *fname);
93 
94 #endif /* gxclio_INCLUDED */
95