home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1996 February / PCWK0296.iso / sharewar / dos / program / gs300sr1 / gs300sr1.exe / GDEVPIPE.C < prev    next >
C/C++ Source or Header  |  1994-07-27  |  2KB  |  65 lines

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