1
/* Copyright (C) 2001-2006 Artifex Software, Inc.
4
This software is provided AS-IS with no warranty, either express or
7
This software is distributed under license and may not be copied, modified
8
or distributed except as expressly authorized under the terms of that
9
license. Refer to licensing information at http://www.artifex.com/
10
or contact Artifex Software, Inc., 7 Mt. Lassen Drive - Suite A-134,
11
San Rafael, CA 94903, U.S.A., +1(415)492-9861, for further information.
14
/* $Id: gsiodevs.c 8250 2007-09-25 13:31:24Z giles $ */
15
/* %stdxxx IODevice implementation for non-PostScript configurations */
22
const char iodev_dtype_stdio[] = "Special";
23
#define iodev_stdio(dname, open) {\
24
dname, iodev_dtype_stdio,\
25
{ iodev_no_init, open, iodev_no_open_file,\
26
iodev_no_fopen, iodev_no_fclose,\
27
iodev_no_delete_file, iodev_no_rename_file, iodev_no_file_status,\
28
iodev_no_enumerate_files, NULL, NULL,\
29
iodev_no_get_params, iodev_no_put_params\
33
#define STDIO_BUF_SIZE 128
35
stdio_close_file(stream *s)
37
/* Don't close stdio files, but do free the buffer. */
38
gs_memory_t *mem = s->memory;
41
gs_free_object(mem, s->cbuf, "stdio_close_file(buffer)");
45
stdio_open(gx_io_device * iodev, const char *access, stream ** ps,
46
gs_memory_t * mem, char rw, FILE *file,
47
void (*srw_file)(stream *, FILE *, byte *, uint))
52
if (!streq1(access, rw))
53
return_error(gs_error_invalidfileaccess);
54
s = s_alloc(mem, "stdio_open(stream)");
55
buf = gs_alloc_bytes(mem, STDIO_BUF_SIZE, "stdio_open(buffer)");
56
if (s == 0 || buf == 0) {
57
gs_free_object(mem, buf, "stdio_open(buffer)");
58
gs_free_object(mem, s, "stdio_open(stream)");
59
return_error(gs_error_VMerror);
61
srw_file(s, file, buf, STDIO_BUF_SIZE);
62
s->procs.close = stdio_close_file;
68
stdin_open(gx_io_device * iodev, const char *access, stream ** ps,
71
return stdio_open(iodev, access, ps, mem, 'r',
72
mem->gs_lib_ctx->fstdin, sread_file);
74
const gx_io_device gs_iodev_stdin = iodev_stdio("%stdin%", stdin_open);
77
stdout_open(gx_io_device * iodev, const char *access, stream ** ps,
80
return stdio_open(iodev, access, ps, mem, 'w',
81
mem->gs_lib_ctx->fstdout, swrite_file);
83
const gx_io_device gs_iodev_stdout = iodev_stdio("%stdout%", stdout_open);
86
stderr_open(gx_io_device * iodev, const char *access, stream ** ps,
89
return stdio_open(iodev, access, ps, mem, 'w',
90
mem->gs_lib_ctx->fstderr, swrite_file);
92
const gx_io_device gs_iodev_stderr = iodev_stdio("%stderr%", stderr_open);