gdevpipe.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /* Copyright (C) 1993, 2000 Aladdin Enterprises. All rights reserved.
  2. This software is provided AS-IS with no warranty, either express or
  3. implied.
  4. This software is distributed under license and may not be copied,
  5. modified or distributed except as expressly authorized under the terms
  6. of the license contained in the file LICENSE in this distribution.
  7. For more information about licensing, please refer to
  8. http://www.ghostscript.com/licensing/. For information on
  9. commercial licensing, go to http://www.artifex.com/licensing/ or
  10. contact Artifex Software, Inc., 101 Lucas Valley Road #110,
  11. San Rafael, CA 94903, U.S.A., +1(415)492-9861.
  12. */
  13. /* $Id: gdevpipe.c,v 1.6 2002/02/21 22:24:51 giles Exp $ */
  14. /* %pipe% IODevice */
  15. #include "errno_.h"
  16. #include "pipe_.h"
  17. #include "stdio_.h"
  18. #include "string_.h"
  19. #include "gserror.h"
  20. #include "gserrors.h"
  21. #include "gstypes.h"
  22. #include "gsmemory.h" /* for gxiodev.h */
  23. #include "gxiodev.h"
  24. /* The pipe IODevice */
  25. private iodev_proc_fopen(pipe_fopen);
  26. private iodev_proc_fclose(pipe_fclose);
  27. const gx_io_device gs_iodev_pipe = {
  28. "%pipe%", "Special",
  29. {iodev_no_init, iodev_no_open_device,
  30. NULL /*iodev_os_open_file */ , pipe_fopen, pipe_fclose,
  31. iodev_no_delete_file, iodev_no_rename_file, iodev_no_file_status,
  32. iodev_no_enumerate_files, NULL, NULL,
  33. iodev_no_get_params, iodev_no_put_params
  34. }
  35. };
  36. /* The file device procedures */
  37. private int
  38. pipe_fopen(gx_io_device * iodev, const char *fname, const char *access,
  39. FILE ** pfile, char *rfname, uint rnamelen)
  40. {
  41. errno = 0;
  42. /*
  43. * Some platforms allow opening a pipe with a '+' in the access
  44. * mode, even though pipes are not positionable. Detect this here.
  45. */
  46. if (strchr(access, '+'))
  47. return_error(gs_error_invalidfileaccess);
  48. /*
  49. * The OSF/1 1.3 library doesn't include const in the
  50. * prototype for popen, so we have to break const here.
  51. */
  52. *pfile = popen((char *)fname, (char *)access);
  53. if (*pfile == NULL)
  54. return_error(gs_fopen_errno_to_code(errno));
  55. if (rfname != NULL)
  56. strcpy(rfname, fname);
  57. return 0;
  58. }
  59. private int
  60. pipe_fclose(gx_io_device * iodev, FILE * file)
  61. {
  62. pclose(file);
  63. return 0;
  64. }