1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
/* Copyright (C) 1993, 2000 Aladdin Enterprises. All rights reserved.
This file is part of AFPL Ghostscript.
AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND. No author or
distributor accepts any responsibility for the consequences of using it, or
for whether it serves any particular purpose or works at all, unless he or
she says so in writing. Refer to the Aladdin Free Public License (the
"License") for full details.
Every copy of AFPL Ghostscript must include a copy of the License, normally
in a plain ASCII text file named PUBLIC. The License grants you the right
to copy, modify and redistribute AFPL Ghostscript, but only under certain
conditions described in the License. Among other things, the License
requires that the copyright notice and this notice be preserved on all
copies.
*/
/*$Id$ */
/* %pipe% IODevice */
#include "errno_.h"
#include "pipe_.h"
#include "stdio_.h"
#include "string_.h"
#include "gserror.h"
#include "gserrors.h"
#include "gstypes.h"
#include "gsmemory.h" /* for gxiodev.h */
#include "gxiodev.h"
/* The pipe IODevice */
private iodev_proc_fopen(pipe_fopen);
private iodev_proc_fclose(pipe_fclose);
const gx_io_device gs_iodev_pipe = {
"%pipe%", "Special",
{iodev_no_init, iodev_no_open_device,
NULL /*iodev_os_open_file */ , pipe_fopen, pipe_fclose,
iodev_no_delete_file, iodev_no_rename_file, iodev_no_file_status,
iodev_no_enumerate_files, NULL, NULL,
iodev_no_get_params, iodev_no_put_params
}
};
/* The file device procedures */
private int
pipe_fopen(gx_io_device * iodev, const char *fname, const char *access,
FILE ** pfile, char *rfname, uint rnamelen)
{
errno = 0;
/*
* Some platforms allow opening a pipe with a '+' in the access
* mode, even though pipes are not positionable. Detect this here.
*/
if (strchr(access, '+'))
return_error(gs_error_invalidfileaccess);
/*
* The OSF/1 1.3 library doesn't include const in the
* prototype for popen, so we have to break const here.
*/
*pfile = popen((char *)fname, (char *)access);
if (*pfile == NULL)
return_error(gs_fopen_errno_to_code(errno));
if (rfname != NULL)
strcpy(rfname, fname);
return 0;
}
private int
pipe_fclose(gx_io_device * iodev, FILE * file)
{
pclose(file);
return 0;
}
|