/usr/share/scheme48-1.9/misc/pipe.scm is in scheme48 1.9-5.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | ; Part of Scheme 48 1.9. See file COPYING for notices and license.
; Authors: Richard Kelsey, Jonathan Rees, Mike Sperber, Ivan Shmakov
; Scheme analogues of Posix popen() and pclose() library calls.
; Create a pipe and exec COMMAND to talk to one end of the pipe while
; PROC is handed the other end. If INPUT? is true PROC gets the input
; end of the pipe and COMMAND gets the output end.
(define (call-with-mumble-pipe input?)
(lambda (command proc . may-be-port)
(call-with-values open-pipe
(lambda (input-pipe output-pipe)
(let ((pid (fork)))
(if pid
; Parent
(let ((proc-port (if input? input-pipe output-pipe)))
(close-port (if input? output-pipe input-pipe))
(call-with-values
(lambda ()
(proc proc-port))
(lambda vals
(close-port proc-port)
(wait-for-child-process pid)
(apply values vals))))
; Child
(dynamic-wind
(lambda ()
#f)
(lambda ()
(define port
(and (not (null? may-be-port))
(car may-be-port)))
(if input?
(remap-file-descriptors! (or
port
(current-input-port))
output-pipe
(current-error-port))
(remap-file-descriptors! input-pipe
(or
port
(current-output-port))
(current-error-port)))
(cond ((list? command)
(apply exec command))
(else
;; FIXME: consider using "$SHELL" here
(exec-file "/bin/sh" "-c" command))))
(lambda ()
(exit 1)))))))))
(define (close-port port)
(if (input-port? port)
(close-input-port port)
(close-output-port port)))
(define call-with-input-pipe
(call-with-mumble-pipe #t))
(define call-with-output-pipe
(call-with-mumble-pipe #f))
|