1 /* Copyright (C) 1993, 2000 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: gdevpipe.c,v 1.6 2002/02/21 22:24:51 giles Exp $ */
18 /* %pipe% IODevice */
19 #include "errno_.h"
20 #include "pipe_.h"
21 #include "stdio_.h"
22 #include "string_.h"
23 #include "gserror.h"
24 #include "gserrors.h"
25 #include "gstypes.h"
26 #include "gsmemory.h" /* for gxiodev.h */
27 #include "gxiodev.h"
28
29 /* The pipe IODevice */
30 private iodev_proc_fopen(pipe_fopen);
31 private iodev_proc_fclose(pipe_fclose);
32 const gx_io_device gs_iodev_pipe = {
33 "%pipe%", "Special",
34 {iodev_no_init, iodev_no_open_device,
35 NULL /*iodev_os_open_file */ , pipe_fopen, pipe_fclose,
36 iodev_no_delete_file, iodev_no_rename_file, iodev_no_file_status,
37 iodev_no_enumerate_files, NULL, NULL,
38 iodev_no_get_params, iodev_no_put_params
39 }
40 };
41
42 /* The file device procedures */
43
44 private int
pipe_fopen(gx_io_device * iodev,const char * fname,const char * access,FILE ** pfile,char * rfname,uint rnamelen)45 pipe_fopen(gx_io_device * iodev, const char *fname, const char *access,
46 FILE ** pfile, char *rfname, uint rnamelen)
47 {
48 errno = 0;
49 /*
50 * Some platforms allow opening a pipe with a '+' in the access
51 * mode, even though pipes are not positionable. Detect this here.
52 */
53 if (strchr(access, '+'))
54 return_error(gs_error_invalidfileaccess);
55 /*
56 * The OSF/1 1.3 library doesn't include const in the
57 * prototype for popen, so we have to break const here.
58 */
59 *pfile = popen((char *)fname, (char *)access);
60 if (*pfile == NULL)
61 return_error(gs_fopen_errno_to_code(errno));
62 if (rfname != NULL)
63 strcpy(rfname, fname);
64 return 0;
65 }
66
67 private int
pipe_fclose(gx_io_device * iodev,FILE * file)68 pipe_fclose(gx_io_device * iodev, FILE * file)
69 {
70 pclose(file);
71 return 0;
72 }
73