Hacked I/O system so that ports set/clear their

fd's CLOEXEC bit when they become unrevealed/revealed.
This commit is contained in:
shivers 1996-09-12 01:43:53 +00:00
parent aed6c163b8
commit 70a1342cef
47 changed files with 336 additions and 557 deletions

View File

@ -6,12 +6,7 @@
;;; These constants are not likely to change from stdio lib to stdio lib, ;;; These constants are not likely to change from stdio lib to stdio lib,
;;; but you need to check when you do a port. ;;; but you need to check when you do a port.
(define-syntax define-bufpols (define-enum-constants bufpol
(syntax-rules ()
((define-bufpols form ...)
(begin (define-enum-constant "bufpol" . form) ...))))
(define-bufpols
(block 0) ; _IOFBF (block 0) ; _IOFBF
(line #o100) ; _IOLBF (line #o100) ; _IOLBF
(none 4)) ; _IONBF (none 4)) ; _IONBF

View File

@ -2,14 +2,9 @@
;;; Copyright (c) 1993 by Olin Shivers. ;;; Copyright (c) 1993 by Olin Shivers.
;;; AIX version by Chipsy Sperber ;;; AIX version by Chipsy Sperber
(define-syntax define-errnos
(syntax-rules ()
((define-errnos form ...)
(begin (define-enum-constant "errno" . form) ...))))
(define errno/2big 7) ; 2big is not a legit Scheme symbol. Lose, lose. (define errno/2big 7) ; 2big is not a legit Scheme symbol. Lose, lose.
(define-errnos (define-enum-constants errno
;; POSIX: ;; POSIX:
(perm 1) ; Operation not permitted (perm 1) ; Operation not permitted
(noent 2) ; No such file or directory (noent 2) ; No such file or directory

View File

@ -2,12 +2,7 @@
;;; Copyright (c) 1993 by Olin Shivers. ;;; Copyright (c) 1993 by Olin Shivers.
;;; AIX version by Chipsy Sperber ;;; AIX version by Chipsy Sperber
(define-syntax define-open-flags (define-enum-constants open
(syntax-rules ()
((define-errnos form ...)
(begin (define-enum-constant "open" . form) ...))))
(define-open-flags
(read 0) (read 0)
(write 1) (write 1)
(read+write 2) (read+write 2)
@ -26,19 +21,28 @@
(bitwise-ior open/read (bitwise-ior open/read
(bitwise-ior open/write open/read+write))) (bitwise-ior open/write open/read+write)))
;;; These are internal; they are not part of the supported scsh interface. ;;; fcntl() commands
(define-enum-constants fcntl
(dup-fdes 0) ; F_DUPFD
(get-fdes-flags 1) ; F_GETFD
(set-fdes-flags 2) ; F_SETFD
(get-status-flags 3) ; F_GETFL
(set-status-flags 4) ; F_SETFL
(get-record-lock 5) ; F_GETLK
(set-record-lock-noblock 6) ; F_SETLK
(set-record-lock 7)) ; F_SETLKW
(define fcntl/close-on-exec 1) ;;; fcntl fdes-flags (F_GETFD)
(define fcntl/dupfd 0) (define fdflags/close-on-exec 1)
(define fcntl/get-fd-flags 1)
(define fcntl/set-fd-flags 2)
(define fcntl/get-file-flags 3)
(define fcntl/set-file-flags 4)
(define fcntl/get-record-lock 5) ; F_GETLK
(define fcntl/set-record-lock-noblock 6) ; F_SETLK
(define fcntl/set-record-lock 7) ; F_SETLKW
(define lock/read 1) ; F_RDLCK ;;; fcntl status-flags (F_GETFL)
(define lock/write 2) ; F_WRLCK ;;; Mostly, these are OPEN/... flags, like OPEN/APPEND.
(define lock/release 3) ' F_UNLCK ;;; (define fdstatus/... ...)
;;; fcntl lock values.
(define-enum-constants lock
(read 1) ; F_RDLCK
(write 2) ; F_WRLCK
(release 3)) ; F_UNLCK

View File

@ -3,14 +3,9 @@
;;; Copyright (c) 1994 by Brian D. Carlstrom. ;;; Copyright (c) 1994 by Brian D. Carlstrom.
;;; AIX version by Chipsy Sperber ;;; AIX version by Chipsy Sperber
(define-syntax define-signals
(syntax-rules ()
((define-signals form ...)
(begin (define-enum-constant "signal" . form) ...))))
;;POSIX only defined here. ;;POSIX only defined here.
(define-signals (define-enum-constants signal
;; POSIX ;; POSIX
(hup 1) ; hangup (hup 1) ; hangup
(int 2) ; interrupt (int 2) ; interrupt

View File

@ -6,12 +6,7 @@
;;; These constants are not likely to change from stdio lib to stdio lib, ;;; These constants are not likely to change from stdio lib to stdio lib,
;;; but you need to check when you do a port. ;;; but you need to check when you do a port.
(define-syntax define-bufpols (define-enum-constants bufpol
(syntax-rules ()
((define-bufpols form ...)
(begin (define-enum-constant "bufpol" . form) ...))))
(define-bufpols
(block 0) ; _IOFBF (block 0) ; _IOFBF
(line #o200) ; _IOLBF (line #o200) ; _IOLBF
(none 4)) ; _IONBF (none 4)) ; _IONBF

View File

@ -3,14 +3,9 @@
;;; These are the correct values for a Harris NightHawk running CX/UX ;;; These are the correct values for a Harris NightHawk running CX/UX
(define-syntax define-errnos
(syntax-rules ()
((define-errnos form ...)
(begin (define-enum-constant "errno" . form) ...))))
(define errno/2big 7) ; 2big is not a legit Scheme symbol. Lose, lose. (define errno/2big 7) ; 2big is not a legit Scheme symbol. Lose, lose.
(define-errnos (define-enum-constants errno
(perm 1) (perm 1)
(noent 2) (noent 2)
(srch 3) (srch 3)

View File

@ -1,12 +1,7 @@
;;; Flags for open(2) and fcntl(2). ;;; Flags for open(2) and fcntl(2).
;;; Copyright (c) 1993 by Olin Shivers. ;;; Copyright (c) 1993 by Olin Shivers.
(define-syntax define-open-flags (define-enum-constants open
(syntax-rules ()
((define-errnos form ...)
(begin (define-enum-constant "open" . form) ...))))
(define-open-flags
(read 0) (read 0)
(write 1) (write 1)
(read+write 2) (read+write 2)

View File

@ -2,14 +2,9 @@
;;; Copyright (c) 1994 by Olin Shivers. ;;; Copyright (c) 1994 by Olin Shivers.
;;; Copyright (c) 1994 by Brian D. Carlstrom. ;;; Copyright (c) 1994 by Brian D. Carlstrom.
(define-syntax define-signals
(syntax-rules ()
((define-signals form ...)
(begin (define-enum-constant "signal" . form) ...))))
;;POSIX only defined here. ;;POSIX only defined here.
(define-signals (define-enum-constants signal
;; POSIX ;; POSIX
(hup 1) ; hangup (hup 1) ; hangup
(int 2) ; interrupt (int 2) ; interrupt

View File

@ -25,7 +25,7 @@
target) target)
((fdport? fd/port) ((fdport? fd/port)
(call/fdes fd/port doit) (sleazy-call/fdes fd/port doit)
(if (%move-fdport target fd/port 1) (if (%move-fdport target fd/port 1)
(error "fdport shift failed.")) (error "fdport shift failed."))
fd/port) fd/port)
@ -37,7 +37,7 @@
(check-arg fd/port? fd/port input-source?) (check-arg fd/port? fd/port input-source?)
(or (input-port? fd/port) (or (input-port? fd/port)
(and (integer? fd/port) (and (integer? fd/port)
(let ((access (bitwise-and open/access-mask (i/o-flags fd/port)))) (let ((access (bitwise-and open/access-mask (fdes-status fd/port))))
(or (= access open/read) (or (= access open/read)
(= access open/read+write)))))) (= access open/read+write))))))
@ -45,7 +45,7 @@
(check-arg fd/port? fd/port output-source?) (check-arg fd/port? fd/port output-source?)
(or (output-port? fd/port) (or (output-port? fd/port)
(and (integer? fd/port) (and (integer? fd/port)
(let ((access (bitwise-and open/access-mask (i/o-flags fd/port)))) (let ((access (bitwise-and open/access-mask (fdes-status fd/port))))
(or (= access open/write) (or (= access open/write)
(= access open/read+write)))))) (= access open/read+write))))))
@ -61,24 +61,22 @@
fd/port maybe-target)) fd/port maybe-target))
(define (dup->fdes fd/port . maybe-target) (define (dup->fdes fd/port . maybe-target)
(check-arg fd/port? fd/port dup) (check-arg fd/port? fd/port dup->fdes)
(if (pair? maybe-target) (if (pair? maybe-target)
(let ((target (car maybe-target))) (let ((target (car maybe-target)))
(close-fdes target) ; Thus evicting any port there. (close-fdes target) ; Thus evicting any port there.
(call/fdes fd/port (lambda (fd) (%dup2 fd target)))) (sleazy-call/fdes fd/port (lambda (fd) (%dup2 fd target))))
(call/fdes fd/port %dup))) (sleazy-call/fdes fd/port %dup)))
(define (dup->inport fd/port . maybe-target) (define (dup->inport fd/port . maybe-target)
(apply really-dup->port fdes->inport fd/port maybe-target)) (apply really-dup->port make-input-fdport fd/port maybe-target))
(define (dup->outport fd/port . maybe-target) (define (dup->outport fd/port . maybe-target)
(apply really-dup->port fdes->outport fd/port maybe-target)) (apply really-dup->port make-output-fdport fd/port maybe-target))
(define (really-dup->port port-maker fd/port . maybe-target) (define (really-dup->port port-maker fd/port . maybe-target)
(let ((new-port (port-maker (apply dup->fdes fd/port maybe-target)))) (let ((fd (apply dup->fdes fd/port maybe-target)))
(if (null? maybe-target) (release-port-handle new-port)) (port-maker fd (if (null? maybe-target) 0 1))))
new-port))
;;; Not exported. ;;; Not exported.

View File

@ -224,7 +224,7 @@ scheme_value cloexec_unrevealed(void)
} }
int install_port(int fd, scheme_value port) int install_port(int fd, scheme_value port, int revealed)
{ {
FILE *stream; FILE *stream;
const char *modestr; const char *modestr;
@ -236,6 +236,9 @@ int install_port(int fd, scheme_value port)
fdports[fd] = port; fdports[fd] = port;
if( !revealed )
if( set_cloexec(fd, 1) ) return errno;
if( fstar_cache[fd] ) return 0; /* A hack mainly for stdio. */ if( fstar_cache[fd] ) return 0; /* A hack mainly for stdio. */
fstar_cache[fd] = stream = fdopen(fd, modestr); fstar_cache[fd] = stream = fdopen(fd, modestr);
@ -296,6 +299,7 @@ int move_fdport(int fd, scheme_value port, int new_revealed)
*PortData_OldRev(port_data) = ENTER_FIXNUM(EXTRACT_FIXNUM(*PortData_OldRev(port_data))+ *PortData_OldRev(port_data) = ENTER_FIXNUM(EXTRACT_FIXNUM(*PortData_OldRev(port_data))+
EXTRACT_FIXNUM(*PortData_Rev(port_data))); EXTRACT_FIXNUM(*PortData_Rev(port_data)));
*PortData_Rev(port_data) = ENTER_FIXNUM(new_revealed); *PortData_Rev(port_data) = ENTER_FIXNUM(new_revealed);
if( !new_revealed ) return set_cloexec(fd, 1);
return 0; return 0;
} }

View File

@ -22,9 +22,7 @@ int set_fdbuf( scheme_value data, int policy, int bufsize );
int close_fdport(scheme_value port_data); int close_fdport(scheme_value port_data);
scheme_value cloexec_unrevealed(void); int install_port(int fd, scheme_value port, int revealed);
int install_port(int fd, scheme_value port);
FILE *fdes2fstar(int fd); FILE *fdes2fstar(int fd);

View File

@ -6,12 +6,7 @@
;;; These constants are not likely to change from stdio lib to stdio lib, ;;; These constants are not likely to change from stdio lib to stdio lib,
;;; but you need to check when you do a port. ;;; but you need to check when you do a port.
(define-syntax define-bufpols (define-enum-constants bufpol
(syntax-rules ()
((define-bufpols form ...)
(begin (define-enum-constant "bufpol" . form) ...))))
(define-bufpols
(block 0) ; _IOFBF (block 0) ; _IOFBF
(line #o200) ; _IOLBF (line #o200) ; _IOLBF
(none 4)) ; _IONBF (none 4)) ; _IONBF

View File

@ -3,14 +3,9 @@
;;; These are the correct values for my SparcStation. ;;; These are the correct values for my SparcStation.
(define-syntax define-errnos
(syntax-rules ()
((define-errnos form ...)
(begin (define-enum-constant "errno" . form) ...))))
(define errno/2big 7) ; 2big is not a legit Scheme symbol. Lose, lose. (define errno/2big 7) ; 2big is not a legit Scheme symbol. Lose, lose.
(define-errnos (define-enum-constants errno
;; POSIX: ;; POSIX:
(perm 1) ; Operation not permitted (perm 1) ; Operation not permitted
(noent 2) ; No such file or directory (noent 2) ; No such file or directory

View File

@ -1,12 +1,7 @@
;;; Flags for open(2) and fcntl(2). ;;; Flags for open(2) and fcntl(2).
;;; Copyright (c) 1993 by Olin Shivers. ;;; Copyright (c) 1993 by Olin Shivers.
(define-syntax define-open-flags (define-enum-constants open
(syntax-rules ()
((define-errnos form ...)
(begin (define-enum-constant "open" . form) ...))))
(define-open-flags
(read 0) (read 0)
(write 1) (write 1)
(read+write 2) (read+write 2)
@ -24,3 +19,29 @@
(define open/access-mask (define open/access-mask
(bitwise-ior open/read (bitwise-ior open/read
(bitwise-ior open/write open/read+write))) (bitwise-ior open/write open/read+write)))
;;; fcntl() commands
(define-enum-constants fcntl
(dup-fdes 0) ; F_DUPFD
(get-fdes-flags 1) ; F_GETFD
(set-fdes-flags 2) ; F_SETFD
(get-status-flags 3) ; F_GETFL
(set-status-flags 4) ; F_SETFL
(get-record-lock 5) ; F_GETLK
(set-record-lock-noblock 6) ; F_SETLK
(set-record-lock 7)) ; F_SETLKW
;;; fcntl fdes-flags (F_GETFD)
(define fdflags/close-on-exec 1)
;;; fcntl status-flags (F_GETFL)
;;; Mostly, these are OPEN/... flags, like OPEN/APPEND.
;;; (define fdstatus/... ...)
;;; fcntl lock values.
(define-enum-constants lock
(read 1) ; F_RDLCK
(write 2) ; F_WRLCK
(release 3)) ; F_UNLCK

View File

@ -2,14 +2,9 @@
;;; Copyright (c) 1994 by Olin Shivers. ;;; Copyright (c) 1994 by Olin Shivers.
;;; Copyright (c) 1994 by Brian D. Carlstrom. ;;; Copyright (c) 1994 by Brian D. Carlstrom.
(define-syntax define-signals
(syntax-rules ()
((define-signals form ...)
(begin (define-enum-constant "signal" . form) ...))))
;;POSIX only defined here. ;;POSIX only defined here.
(define-signals (define-enum-constants signal
;; POSIX ;; POSIX
(hup 1) ; hangup (hup 1) ; hangup
(int 2) ; interrupt (int 2) ; interrupt

View File

@ -6,12 +6,7 @@
;;; These constants are not likely to change from stdio lib to stdio lib, ;;; These constants are not likely to change from stdio lib to stdio lib,
;;; but you need to check when you do a port. ;;; but you need to check when you do a port.
(define-syntax define-bufpols (define-enum-constants bufpol
(syntax-rules ()
((define-bufpols form ...)
(begin (define-enum-constant "bufpol" . form) ...))))
(define-bufpols
(block 0) ; _IOFBF (block 0) ; _IOFBF
(line #o200) ; _IOLBF (line #o200) ; _IOLBF
(none 4)) ; _IONBF (none 4)) ; _IONBF

View File

@ -4,14 +4,9 @@
;;; NOTE: When the hp9000s500 symbol is set, errno.h defines ENOMSG to be 250 ;;; NOTE: When the hp9000s500 symbol is set, errno.h defines ENOMSG to be 250
;;; instead of 35. What to do? We go with 35 in this file. ;;; instead of 35. What to do? We go with 35 in this file.
(define-syntax define-errnos
(syntax-rules ()
((define-errnos form ...)
(begin (define-enum-constant "errno" . form) ...))))
(define errno/2big 7) ; 2big is not a legit Scheme symbol. Lose, lose. (define errno/2big 7) ; 2big is not a legit Scheme symbol. Lose, lose.
(define-errnos (define-enum-constants errno
(perm 1) ; Not super-user (perm 1) ; Not super-user
(noent 2) ; No such file or directory (noent 2) ; No such file or directory
(srch 3) ; No such process (srch 3) ; No such process

View File

@ -1,12 +1,7 @@
;;; Flags for open(2) and fcntl(2). ;;; Flags for open(2) and fcntl(2).
;;; Copyright (c) 1993 by Olin Shivers. ;;; Copyright (c) 1993 by Olin Shivers.
(define-syntax define-open-flags (define-enum-constants open
(syntax-rules ()
((define-opens form ...)
(begin (define-enum-constant "open" . form) ...))))
(define-open-flags
;; POSIX ;; POSIX
(read 0) (read 0)
(write 1) (write 1)
@ -19,25 +14,34 @@
(exclusive #o2000) (exclusive #o2000)
;; NextStep ;; NextStep
(sync #o100000)) ; Synchronous writes (sync #o100000)) ; Synchronous writes
(define open/access-mask (define open/access-mask
(bitwise-ior open/read (bitwise-ior open/read
(bitwise-ior open/write open/read+write))) (bitwise-ior open/write open/read+write)))
;;; These are internal; they are not part of the supported scsh interface. ;;; fcntl() commands
(define-enum-constants fcntl
(dup-fdes 0) ; F_DUPFD
(get-fdes-flags 1) ; F_GETFD
(set-fdes-flags 2) ; F_SETFD
(get-status-flags 3) ; F_GETFL
(set-status-flags 4) ; F_SETFL
(get-record-lock 5) ; F_GETLK
(set-record-lock-noblock 6) ; F_SETLK
(set-record-lock 7)) ; F_SETLKW
(define fcntl/close-on-exec 1) ;;; fcntl fdes-flags (F_GETFD)
(define fcntl/dupfd 0) (define fdflags/close-on-exec 1)
(define fcntl/get-fd-flags 1)
(define fcntl/set-fd-flags 2)
(define fcntl/get-file-flags 3)
(define fcntl/set-file-flags 4)
(define fcntl/get-record-lock 5) ; F_GETLK
(define fcntl/set-record-lock-noblock 6) ; F_SETLK
(define fcntl/set-record-lock 7) ; F_SETLKW
(define lock/read 1) ; F_RDLCK ;;; fcntl status-flags (F_GETFL)
(define lock/write 2) ; F_WRLCK ;;; Mostly, these are OPEN/... flags, like OPEN/APPEND.
(define lock/release 3) ' F_UNLCK ;;; (define fdstatus/... ...)
;;; fcntl lock values.
(define-enum-constants lock
(read 1) ; F_RDLCK
(write 2) ; F_WRLCK
(release 3)) ; F_UNLCK

View File

@ -2,12 +2,7 @@
;;; Copyright (c) 1994 by Olin Shivers. ;;; Copyright (c) 1994 by Olin Shivers.
;;; Copyright (c) 1994 by Brian D. Carlstrom. ;;; Copyright (c) 1994 by Brian D. Carlstrom.
(define-syntax define-signals (define-enum-constants signal
(syntax-rules ()
((define-signals form ...)
(begin (define-enum-constant "signal" . form) ...))))
(define-signals
(hup 1) ; floating point exception (hup 1) ; floating point exception
(int 2) ; Interrupt (int 2) ; Interrupt
(quit 3) ; quit (quit 3) ; quit

View File

@ -7,12 +7,7 @@
;;; These constants are not likely to change from stdio lib to stdio lib, ;;; These constants are not likely to change from stdio lib to stdio lib,
;;; but you need to check when you do a port. ;;; but you need to check when you do a port.
(define-syntax define-bufpols (define-enum-constants bufpol
(syntax-rules ()
((define-bufpols form ...)
(begin (define-enum-constant "bufpol" . form) ...))))
(define-bufpols
(block 0) ; _IOFBF (block 0) ; _IOFBF
(line #o100) ; _IOLBF (line #o100) ; _IOLBF
(none 4)) ; _IONBF (none 4)) ; _IONBF

View File

@ -3,14 +3,9 @@
;;; These are the correct values for my SparcStation. ;;; These are the correct values for my SparcStation.
(define-syntax define-errnos
(syntax-rules ()
((define-errnos form ...)
(begin (define-enum-constant "errno" . form) ...))))
(define errno/2big 7) ; 2big is not a legit Scheme symbol. Lose, lose. (define errno/2big 7) ; 2big is not a legit Scheme symbol. Lose, lose.
(define-errnos (define-enum-constants errno
;; POSIX: ;; POSIX:
(perm 1) ; Operation not permitted (perm 1) ; Operation not permitted
(noent 2) ; No such file or directory (noent 2) ; No such file or directory

View File

@ -1,12 +1,7 @@
;;; Flags for open(2) and fcntl(2). ;;; Flags for open(2) and fcntl(2).
;;; Copyright (c) 1993 by Olin Shivers. ;;; Copyright (c) 1993 by Olin Shivers.
(define-syntax define-open-flags (define-enum-constants open
(syntax-rules ()
((define-errnos form ...)
(begin (define-enum-constant "open" . form) ...))))
(define-open-flags
(read 0) (read 0)
(write 1) (write 1)
(read+write 2) (read+write 2)
@ -25,16 +20,28 @@
(bitwise-ior open/read (bitwise-ior open/read
(bitwise-ior open/write open/read+write))) (bitwise-ior open/write open/read+write)))
(define fcntl/close-on-exec 1) ;;; fcntl() commands
(define fcntl/dupfd 0) (define-enum-constants fcntl
(define fcntl/get-fd-flags 1) (dup-fdes 0) ; F_DUPFD
(define fcntl/set-fd-flags 2) (get-fdes-flags 1) ; F_GETFD
(define fcntl/get-file-flags 3) (set-fdes-flags 2) ; F_SETFD
(define fcntl/set-file-flags 4) (get-status-flags 3) ; F_GETFL
(define fcntl/get-record-lock 5) (set-status-flags 4) ; F_SETFL
(define fcntl/set-record-lock-noblock 6) (get-record-lock 5) ; F_GETLK
(define fcntl/set-record-lock 7) (set-record-lock-noblock 6) ; F_SETLK
(set-record-lock 7)) ; F_SETLKW
(define lock/read 1) ;;; fcntl fdes-flags (F_GETFD)
(define lock/write 2)
(define lock/release 3) (define fdflags/close-on-exec 1)
;;; fcntl status-flags (F_GETFL)
;;; Mostly, these are OPEN/... flags, like OPEN/APPEND.
;;; (define fdstatus/... ...)
;;; fcntl lock values.
(define-enum-constants lock
(read 1) ; F_RDLCK
(write 2) ; F_WRLCK
(release 3)) ; F_UNLCK

View File

@ -2,14 +2,9 @@
;;; Copyright (c) 1994 by Olin Shivers. ;;; Copyright (c) 1994 by Olin Shivers.
;;; Copyright (c) 1994 by Brian D. Carlstrom. ;;; Copyright (c) 1994 by Brian D. Carlstrom.
(define-syntax define-signals
(syntax-rules ()
((define-signals form ...)
(begin (define-enum-constant "signal" . form) ...))))
;;POSIX only defined here. ;;POSIX only defined here.
(define-signals (define-enum-constants signal
;; POSIX ;; POSIX
(hup 1) ; hangup (hup 1) ; hangup
(int 2) ; interrupt (int 2) ; interrupt

View File

@ -7,12 +7,7 @@
;;; These constants are not likely to change from stdio lib to stdio lib, ;;; These constants are not likely to change from stdio lib to stdio lib,
;;; but you need to check when you do a port. ;;; but you need to check when you do a port.
(define-syntax define-bufpols (define-enum-constants bufpol
(syntax-rules ()
((define-bufpols form ...)
(begin (define-enum-constant "bufpol" . form) ...))))
(define-bufpols
(block 0) ; _IOFBF (block 0) ; _IOFBF
(line 1) ; _IOLBF (line 1) ; _IOLBF
(none 2)) ; _IONBF (none 2)) ; _IONBF

View File

@ -4,14 +4,9 @@
;;; These are the correct values for Linux systems. ;;; These are the correct values for Linux systems.
(define-syntax define-errnos
(syntax-rules ()
((define-errnos form ...)
(begin (define-enum-constant "errno" . form) ...))))
(define errno/2big 7) ; 2big is not a legit Scheme symbol. Lose, lose. (define errno/2big 7) ; 2big is not a legit Scheme symbol. Lose, lose.
(define-errnos (define-enum-constants errno
;; POSIX: ;; POSIX:
(perm 1 ); Operation Not Permitted (perm 1 ); Operation Not Permitted

View File

@ -2,12 +2,7 @@
;;; Copyright (c) 1993 by Olin Shivers. ;;; Copyright (c) 1993 by Olin Shivers.
;;; Copyright (c) 1994 by Brian D. Carlstrom ;;; Copyright (c) 1994 by Brian D. Carlstrom
(define-syntax define-open-flags (define-enum-constants open
(syntax-rules ()
((define-opens form ...)
(begin (define-enum-constant "open" . form) ...))))
(define-open-flags
;; POSIX ;; POSIX
(read #x0000) (read #x0000)
(write #x0001) (write #x0001)
@ -16,8 +11,8 @@
(append #x0400) ; set append mode (append #x0400) ; set append mode
;; Linux ;; Linux
(shlock #x0004) ; open with shared file lock (shared-lock #x0004) ; open with shared file lock
(exlock #x0008) ; open with exclusive file lock (exclusive-lock #x0008) ; open with exclusive file lock
(async #x2000) ; signal pgrep when data ready (async #x2000) ; signal pgrep when data ready
(fsync #x1000) ; synchronus writes (fsync #x1000) ; synchronus writes
@ -33,55 +28,30 @@
(bitwise-ior open/read (bitwise-ior open/read
(bitwise-ior open/write open/read+write))) (bitwise-ior open/write open/read+write)))
;;;; fcntl ;;; fcntl() commands
;;;; Rough sketch only. Will define a separate proc for each fcntl command. (define-enum-constants fcntl
; (dup-fdes 0) ; F_DUPFD
;;;; fcntl commands (get-fdes-flags 1) ; F_GETFD
;dup (set-fdes-flags 2) ; F_SETFD
; (get-status-flags 3) ; F_GETFL
;get-flags ; Only gives close-on-exec bit. (set-status-flags 4) ; F_SETFL
;set-flags (get-owner 9) ; F_GETOWN (Not POSIX)
; (set-owner 8) ; F_SETOWN (Not POSIX)
;get-status ; Returns open flags + get-status flags (below) (get-record-lock 5) ; F_GETLK
;set-status ; Can set: append, sync, async, nbio, nonblocking, no-delay (set-record-lock-noblock 6) ; F_SETLK
; (set-record-lock 7)) ; F_SETLKW
;get-lock
;set-lock
;nonblocking-set-lock
;
;get-record-lock
;set-record-lock
;set-record-lock-noblock
;
;get-owner ; Not POSIX
;set-owner ; Not POSIX
;remote-set-lock ; Not POSIX
;nonblocking-remote-set-lock ; Not POSIX
;remote-get-lock ; Not POSIX
;
;;;; Flags
;
;close-on-exec ; get-flags
;
;async ; get-status
;no-delay ; get-status
;nbio ; get-status
;
;;; These are internal; they are not part of the supported scsh interface.
(define fcntl/close-on-exec 1) ;;; fcntl fdes-flags (F_GETFD)
(define fcntl/dupfd 0) (define fdflags/close-on-exec 1)
(define fcntl/get-fd-flags 1)
(define fcntl/set-fd-flags 2)
(define fcntl/get-file-flags 3)
(define fcntl/set-file-flags 4)
(define fcntl/get-owner 9) ; Not POSIX
(define fcntl/set-owner 8) ; Not POSIX
(define fcntl/get-record-lock 5) ; F_GETLK
(define fcntl/set-record-lock-noblock 6) ; F_SETLK
(define fcntl/set-record-lock 7) ; F_SETLKW
(define lock/read 0) ; F_RDLCK ;;; fcntl status-flags (F_GETFL)
(define lock/release 2) ; F_UNLCK ;;; Mostly, these are OPEN/... flags, like OPEN/APPEND.
(define lock/write 1) ; F_WRLCK ;;; (define fdstatus/... ...)
;;; fcntl lock values.
(define-enum-constants lock
(read 0) ; F_RDLCK
(release 2) ; F_UNLCK
(write 1)) ; F_WRLCK

View File

@ -2,12 +2,7 @@
;;; Copyright (c) 1994 by Olin Shivers. ;;; Copyright (c) 1994 by Olin Shivers.
;;; Copyright (c) 1994 by Brian D. Carlstrom. ;;; Copyright (c) 1994 by Brian D. Carlstrom.
(define-syntax define-signals (define-enum-constants signal
(syntax-rules ()
((define-signals form ...)
(begin (define-enum-constant "signal" . form) ...))))
(define-signals
;; POSIX ;; POSIX
(hup 1) (hup 1)
(int 2) (int 2)

View File

@ -150,9 +150,8 @@
(error "create-socket: integer arguments expected ~s ~s ~s" (error "create-socket: integer arguments expected ~s ~s ~s"
pf type protocol) pf type protocol)
(let* ((fd (%socket pf type protocol)) (let* ((fd (%socket pf type protocol))
(in (make-input-fdport fd)) (in (make-input-fdport fd 0))
(out (dup->outport in))) (out (dup->outport in)))
(%install-port fd in)
(make-socket pf in out))))) (make-socket pf in out)))))
(define-foreign %socket/errno (define-foreign %socket/errno
@ -252,9 +251,8 @@
(let* ((family (socket:family sock)) (let* ((family (socket:family sock))
(name (make-addr family)) (name (make-addr family))
(fd (%accept (socket->fdes sock) family name)) (fd (%accept (socket->fdes sock) family name))
(in (make-input-fdport fd)) (in (make-input-fdport fd 0))
(out (dup->outport in))) (out (dup->outport in)))
(%install-port fd in)
(values (make-socket family in out) (values (make-socket family in out)
(make-socket-address family name))))) (make-socket-address family name)))))
@ -340,12 +338,10 @@
(error "create-socket-pair: integer argument expected ~s" type) (error "create-socket-pair: integer argument expected ~s" type)
(receive (s1 s2) (receive (s1 s2)
(%socket-pair type) (%socket-pair type)
(let* ((in1 (make-input-fdport s1)) (let* ((in1 (make-input-fdport s1 0))
(out1 (dup->outport in1)) (out1 (dup->outport in1))
(in2 (make-input-fdport s2)) (in2 (make-input-fdport s2 0))
(out2 (dup->outport in2))) (out2 (dup->outport in2)))
(%install-port s1 in1)
(%install-port s2 in2)
(values (make-socket protocol-family/unix in1 out1) (values (make-socket protocol-family/unix in1 out1)
(make-socket protocol-family/unix in2 out2)))))) (make-socket protocol-family/unix in2 out2))))))

View File

@ -6,20 +6,31 @@
fd ; Unix file descriptor - integer. fd ; Unix file descriptor - integer.
(closed? #f) ; Is port closed. (closed? #f) ; Is port closed.
(peek-char #f) (peek-char #f)
(revealed 0) ; REVEALED & OLD-REVEALED are for keeping revealed ; REVEALED & OLD-REVEALED are for keeping
(old-revealed 0)) ; track of whether the FD value has escaped. (old-revealed 0)) ; track of whether the FD value has escaped.
;;; We could flush the PEEK-CHAR field and use stdio ungetc(), but it ;;; We could flush the PEEK-CHAR field and use stdio ungetc(), but it
;;; is only guaranteed for buffered streams. Too bad... ;;; is only guaranteed for buffered streams. Too bad...
(define (make-input-fdport fd) (define (alloc-input-fdport fd revealed)
(make-extensible-input-port (make-fdport-data fd) (make-extensible-input-port (make-fdport-data fd revealed)
input-fdport-methods)) input-fdport-methods))
(define (make-output-fdport fd) (define (alloc-output-fdport fd revealed)
(make-extensible-output-port (make-fdport-data fd) (make-extensible-output-port (make-fdport-data fd revealed)
output-fdport-methods)) output-fdport-methods))
(define (make-input-fdport fd revealed)
(let ((p (alloc-input-fdport fd revealed)))
(%install-port fd p revealed)
p))
(define (make-output-fdport fd revealed)
(let ((p (alloc-output-fdport fd revealed)))
(%install-port fd p revealed)
p))
(define (fdport? x) (define (fdport? x)
(cond ((or (and (extensible-input-port? x) (cond ((or (and (extensible-input-port? x)
(extensible-input-port-local-data x)) (extensible-input-port-local-data x))
@ -128,14 +139,12 @@
;;; ------------ ;;; ------------
(define (open-file fname flags . maybe-mode) (define (open-file fname flags . maybe-mode)
(let* ((fd (apply open-fdes fname flags maybe-mode)) (let ((fd (apply open-fdes fname flags maybe-mode))
(access (bitwise-and flags open/access-mask)) (access (bitwise-and flags open/access-mask)))
(port ((if (or (= access open/read) (= access open/read+write)) ((if (or (= access open/read) (= access open/read+write))
make-input-fdport make-input-fdport
make-output-fdport) make-output-fdport)
fd))) fd 0)))
(%install-port fd port)
port))
(define (open-input-file fname . maybe-flags) (define (open-input-file fname . maybe-flags)
(let ((flags (:optional maybe-flags 0))) (let ((flags (:optional maybe-flags 0)))
@ -154,8 +163,11 @@
(define (increment-revealed-count port delta) (define (increment-revealed-count port delta)
(let* ((data (extensible-port-local-data port)) (let* ((data (extensible-port-local-data port))
(count (fdport-data:revealed data))) (count (fdport-data:revealed data))
(set-fdport-data:revealed data (+ count delta)))) (newcount (+ count delta)))
(set-fdport-data:revealed data newcount)
(if (and (zero? count) (> newcount 0)) ; We just became revealed,
(%set-cloexec (fdport-data:fd data) #f)))) ; so don't close on exec().
(define (release-port-handle port) (define (release-port-handle port)
(check-arg fdport? port port->fdes) (check-arg fdport? port port->fdes)
@ -164,7 +176,10 @@
(if (zero? rev) (if (zero? rev)
(set-fdport-data:old-revealed data (set-fdport-data:old-revealed data
(- (fdport-data:old-revealed data) 1)) (- (fdport-data:old-revealed data) 1))
(set-fdport-data:revealed data (- rev 1))))) (let ((new-rev (- rev 1)))
(set-fdport-data:revealed data new-rev)
(if (zero? new-rev) ; We just became unrevealed, so
(%set-cloexec (fdport-data:fd data) #t)))))); the fd can be closed on exec.
(define (port-revealed port) (define (port-revealed port)
(let ((count (fdport-data:revealed (let ((count (fdport-data:revealed
@ -173,12 +188,11 @@
(and (not (zero? count)) count))) (and (not (zero? count)) count)))
(define (fdes->port fd port-maker) ; local proc. (define (fdes->port fd port-maker) ; local proc.
(let ((port (or (%maybe-fdes->port fd) (cond ((%maybe-fdes->port fd) =>
(let ((port (port-maker fd))) (lambda (p)
(%install-port fd port) (increment-revealed-count p 1)
port)))) p))
(increment-revealed-count port 1) (else (port-maker fd 1))))
port))
(define (fdes->inport fd) (fdes->port fd make-input-fdport)) (define (fdes->inport fd) (fdes->port fd make-input-fdport))
(define (fdes->outport fd) (fdes->port fd make-output-fdport)) (define (fdes->outport fd) (fdes->port fd make-output-fdport))
@ -205,6 +219,14 @@
(else (error "Not a file descriptor or fdport." fd/port)))) (else (error "Not a file descriptor or fdport." fd/port))))
;;; Don't mess with the revealed count in the port case
;;; -- just sneakily grab the fdes and run.
(define (sleazy-call/fdes fd/port proc)
(proc (cond ((integer? fd/port) fd/port)
((fdport? fd/port) (fdport-data:fd (fdport-data fd/port)))
(else (error "Not a file descriptor or fdport." fd/port)))))
;;; Random predicates and arg checkers ;;; Random predicates and arg checkers
;;; ---------------------------------- ;;; ----------------------------------
@ -274,7 +296,7 @@
;;; If this fd has an associated input or output port, ;;; If this fd has an associated input or output port,
;;; move it to a new fd, freeing this one up. ;;; move it to a new fd, freeing this one up.
;;; Unitialized fdport in table is set to 0, does this mean
(define (evict-ports fd) (define (evict-ports fd)
(cond ((%maybe-fdes->port fd) => ; Shouldn't bump the revealed count. (cond ((%maybe-fdes->port fd) => ; Shouldn't bump the revealed count.
(lambda (port) (lambda (port)

View File

@ -6,12 +6,7 @@
;;; These constants are not likely to change from stdio lib to stdio lib, ;;; These constants are not likely to change from stdio lib to stdio lib,
;;; but you need to check when you do a port. ;;; but you need to check when you do a port.
(define-syntax define-bufpols (define-enum-constants bufpol
(syntax-rules ()
((define-bufpols form ...)
(begin (define-enum-constant "bufpol" . form) ...))))
(define-bufpols
(block 0) ; _IOFBF (block 0) ; _IOFBF
(line #o200) ; _IOLBF (line #o200) ; _IOLBF
(none 4)) ; _IONBF (none 4)) ; _IONBF

View File

@ -3,14 +3,9 @@
;;; These are the correct values for NextStep systems. ;;; These are the correct values for NextStep systems.
(define-syntax define-errnos
(syntax-rules ()
((define-errnos form ...)
(begin (define-enum-constant "errno" . form) ...))))
(define errno/2big 7) ; 2big is not a legit Scheme symbol. Lose, lose. (define errno/2big 7) ; 2big is not a legit Scheme symbol. Lose, lose.
(define-errnos (define-enum-constants errno
;; POSIX: ;; POSIX:
(perm 1) ; Operation not permitted (perm 1) ; Operation not permitted
(noent 2) ; No such file or directory (noent 2) ; No such file or directory

View File

@ -1,12 +1,7 @@
;;; Flags for open(2) and fcntl(2). ;;; Flags for open(2) and fcntl(2).
;;; Copyright (c) 1993 by Olin Shivers. ;;; Copyright (c) 1993 by Olin Shivers.
(define-syntax define-open-flags (define-enum-constants open
(syntax-rules ()
((define-opens form ...)
(begin (define-enum-constant "open" . form) ...))))
(define-open-flags
;; POSIX ;; POSIX
(read 0) (read 0)
(write 1) (write 1)
@ -26,55 +21,31 @@
(bitwise-ior open/read (bitwise-ior open/read
(bitwise-ior open/write open/read+write))) (bitwise-ior open/write open/read+write)))
;;;; fcntl
;;;; Rough sketch only. Will define a separate proc for each fcntl command.
;
;;;; fcntl commands
;dup
;
;get-flags ; Only gives close-on-exec bit.
;set-flags
;
;get-status ; Returns open flags + get-status flags (below)
;set-status ; Can set: append, sync, async, nbio, nonblocking, no-delay
;
;get-lock
;set-lock
;nonblocking-set-lock
;
;get-record-lock
;set-record-lock
;set-record-lock-noblock
;
;get-owner ; Not POSIX
;set-owner ; Not POSIX
;remote-set-lock ; Not POSIX
;nonblocking-remote-set-lock ; Not POSIX
;remote-get-lock ; Not POSIX
;
;;;; Flags
;
;close-on-exec ; get-flags
;
;async ; get-status
;no-delay ; get-status
;nbio ; get-status
;
;;; These are internal; they are not part of the supported scsh interface.
(define fcntl/close-on-exec 1) ;;; fcntl() commands
(define-enum-constants fcntl
(dup-fdes 0) ; F_DUPFD
(get-fdes-flags 1) ; F_GETFD
(set-fdes-flags 2) ; F_SETFD
(get-status-flags 3) ; F_GETFL
(set-status-flags 4) ; F_SETFL
(get-owner 5) ; F_GETOWN (Not POSIX)
(set-owner 6) ; F_SETOWN (Not POSIX)
(get-record-lock 7) ; F_GETLK
(set-record-lock-noblock 8) ; F_SETLK
(set-record-lock 9)) ; F_SETLKW
(define fcntl/dupfd 0) ;;; fcntl fdes-flags (F_GETFD)
(define fcntl/get-fd-flags 1)
(define fcntl/set-fd-flags 2)
(define fcntl/get-file-flags 3)
(define fcntl/set-file-flags 4)
(define fcntl/get-owner 5) ; Not POSIX
(define fcntl/set-owner 6) ; Not POSIX
(define fcntl/get-record-lock 7) ; F_GETLK
(define fcntl/set-record-lock-noblock 8) ; F_SETLK
(define fcntl/set-record-lock 9) ; F_SETLKW
(define lock/read 1) ; F_RDLCK (define fdflags/close-on-exec 1)
(define lock/write 2) ; F_WRLCK
(define lock/release 3) ' F_UNLCK ;;; fcntl status-flags (F_GETFL)
;;; Mostly, these are OPEN/... flags, like OPEN/APPEND.
;;; (define fdstatus/... ...)
;;; fcntl lock values.
(define-enum-constants lock
(read 1) ; F_RDLCK
(write 2) ; F_WRLCK
(release 3)) ; F_UNLCK

View File

@ -1,12 +1,7 @@
;;; Signal constant definitions for NextStep ;;; Signal constant definitions for NextStep
;;; Copyright (c) 1994 by Olin Shivers. ;;; Copyright (c) 1994 by Olin Shivers.
(define-syntax define-signals (define-enum-constants signal
(syntax-rules ()
((define-signals form ...)
(begin (define-enum-constant "signal" . form) ...))))
(define-signals
;; POSIX ;; POSIX
(hup 1) ; hangup (hup 1) ; hangup
(int 2) ; interrupt (int 2) ; interrupt

View File

@ -657,7 +657,6 @@
;; Try each directory in PATH-LIST. ;; Try each directory in PATH-LIST.
(let ((argv (list->vector (cons prog (map stringify arglist))))) (let ((argv (list->vector (cons prog (map stringify arglist)))))
(cloexec-unrevealed-ports)
(for-each (lambda (dir) (for-each (lambda (dir)
(let ((binary (string-append dir "/" prog))) (let ((binary (string-append dir "/" prog)))
(%%exec/errno binary argv env))) (%%exec/errno binary argv env)))

View File

@ -6,12 +6,7 @@
;;; These constants are not likely to change from stdio lib to stdio lib, ;;; These constants are not likely to change from stdio lib to stdio lib,
;;; but you need to check when you do a port. ;;; but you need to check when you do a port.
(define-syntax define-bufpols (define-enum-constants bufpol
(syntax-rules ()
((define-bufpols form ...)
(begin (define-enum-constant "bufpol" . form) ...))))
(define-bufpols
(block 0) ; _IOFBF (block 0) ; _IOFBF
(line #o100) ; _IOLBF (line #o100) ; _IOLBF
(none 4)) ; _IONBF (none 4)) ; _IONBF

View File

@ -4,14 +4,9 @@
;;; These are the correct values for my SparcStation. ;;; These are the correct values for my SparcStation.
(define-syntax define-errnos
(syntax-rules ()
((define-errnos form ...)
(begin (define-enum-constant "errno" . form) ...))))
(define errno/2big 7) ; 2big is not a legit Scheme symbol. Lose, lose. (define errno/2big 7) ; 2big is not a legit Scheme symbol. Lose, lose.
(define-errnos (define-enum-constants errno
;; POSIX: ;; POSIX:
(perm 1) ; Not Super-User (perm 1) ; Not Super-User
(noent 2) ; No Such File Or Directory (noent 2) ; No Such File Or Directory

View File

@ -1,12 +1,8 @@
;;; Flags for open(2) and fcntl(2). ;;; Flags for open(2) and fcntl(2).
;;; Copyright (c) 1993 by Olin Shivers. ;;; Copyright (c) 1993 by Olin Shivers.
;;; Modified for Solaris by tvb@math.ufl.edu ;;; Modified for Solaris by tvb@math.ufl.edu
(define-syntax define-open-flags
(syntax-rules ()
((define-errnos form ...)
(begin (define-enum-constant "open" . form) ...))))
(define-open-flags (define-enum-constants open
(read 0) (read 0)
(write 1) (write 1)
(read+write 2) (read+write 2)
@ -25,58 +21,30 @@
(bitwise-ior open/read (bitwise-ior open/read
(bitwise-ior open/write open/read+write))) (bitwise-ior open/write open/read+write)))
;;;; fcntl
;;;; Rough sketch only. Will define a separate proc for each fcntl command.
;
;;;; fcntl commands
;dup
;
;get-flags ; Only gives close-on-exec bit.
;set-flags
;
;get-status ; Returns open flags + get-status flags (below)
;set-status ; Can set: append, sync, async, nbio, nonblocking, no-delay
;
;get-lock
;set-lock
;nonblocking-set-lock
;
;get-record-lock
;set-record-lock
;
;get-owner ; Not POSIX
;set-owner ; Not POSIX
;remote-set-lock ; Not POSIX
;nonblocking-remote-set-lock ; Not POSIX
;remote-get-lock ; Not POSIX
;
;;;; Flags
;
;close-on-exec ; get-flags
;
;async ; get-status
;no-delay ; get-status
;nbio ; get-status
;
;lock/read ; set-lock
;lock/write ; set-lock
;lock/release ; set-lock
;;; These are internal; they are not part of the supported scsh interface. (define-enum-constants fcntl
(dup-fdes 0) ; F_DUPFD
(get-fdes-flags 1) ; F_GETFD
(set-fdes-flags 2) ; F_SETFD
(get-status-flags 3) ; F_GETFL
(set-status-flags 4) ; F_SETFL
(get-owner 23) ; F_GETOWN (Not Posix)
(set-owner 24) ; F_SETOWN (Not Posix)
(get-record-lock 5) ; F_GETLK
(set-record-lock-noblock 6) ; F_SETLK
(set-record-lock 7)) ; F_SETLKW
(define fcntl/close-on-exec 1) ;;; fcntl fdes-flags (F_GETFD)
(define fcntl/dupfd 0) (define fdflags/close-on-exec 1)
(define fcntl/get-fd-flags 1)
(define fcntl/set-fd-flags 2)
(define fcntl/get-file-flags 3)
(define fcntl/set-file-flags 4)
(define fcntl/get-owner 23) ; F_GETOWN
(define fcntl/set-owner 24) ; F_SETOWN
(define fcntl/get-record-lock 5) ; F_GETLK
(define fcntl/set-record-lock-noblock 6) ; F_SETLK
(define fcntl/set-record-lock 7) ; F_SETLKW
(define lock/read 1) ; F_RDLCK ;;; fcntl status-flags (F_GETFL)
(define lock/write 2) ; F_WRLCK ;;; Mostly, these are OPEN/... flags, like OPEN/APPEND.
(define lock/release 3) ; F_UNLCK ;;; (define fdstatus/... ...)
;;; fcntl lock values.
(define-enum-constants lock
(read 1) ; F_RDLCK
(write 2) ; F_WRLCK
(release 3)) ; F_UNLCK

View File

@ -2,14 +2,9 @@
;;; Copyright (c) 1994 by Olin Shivers. ;;; Copyright (c) 1994 by Olin Shivers.
;;; Modified for Solaris by tvb@math.ufl.edu ;;; Modified for Solaris by tvb@math.ufl.edu
(define-syntax define-signals
(syntax-rules ()
((define-signals form ...)
(begin (define-enum-constant "signal" . form) ...))))
;; Adapted from signal.h - tvb ;; Adapted from signal.h - tvb
(define-signals (define-enum-constants signal
;; POSIX ;; POSIX
(hup 1) ; Hangup (hup 1) ; Hangup
(int 2) ; Interrupt (Rubout) (int 2) ; Interrupt (Rubout)

View File

@ -6,12 +6,7 @@
;;; These constants are not likely to change from stdio lib to stdio lib, ;;; These constants are not likely to change from stdio lib to stdio lib,
;;; but you need to check when you do a port. ;;; but you need to check when you do a port.
(define-syntax define-bufpols (define-enum-constants bufpol
(syntax-rules ()
((define-bufpols form ...)
(begin (define-enum-constant "bufpol" . form) ...))))
(define-bufpols
(block 0) ; _IOFBF (block 0) ; _IOFBF
(line #o200) ; _IOLBF (line #o200) ; _IOLBF
(none 4)) ; _IONBF (none 4)) ; _IONBF

View File

@ -3,14 +3,9 @@
;;; These are the correct values for my SparcStation. ;;; These are the correct values for my SparcStation.
(define-syntax define-errnos
(syntax-rules ()
((define-errnos form ...)
(begin (define-enum-constant "errno" . form) ...))))
(define errno/2big 7) ; 2big is not a legit Scheme symbol. Lose, lose. (define errno/2big 7) ; 2big is not a legit Scheme symbol. Lose, lose.
(define-errnos (define-enum-constants errno
;; POSIX: ;; POSIX:
(perm 1) ; Operation not permitted (perm 1) ; Operation not permitted
(noent 2) ; No such file or directory (noent 2) ; No such file or directory

View File

@ -1,12 +1,7 @@
;;; Flags for open(2) and fcntl(2). ;;; Flags for open(2) and fcntl(2).
;;; Copyright (c) 1993 by Olin Shivers. ;;; Copyright (c) 1993 by Olin Shivers.
(define-syntax define-open-flags (define-enum-constants open
(syntax-rules ()
((define-errnos form ...)
(begin (define-enum-constant "open" . form) ...))))
(define-open-flags
(read 0) (read 0)
(write 1) (write 1)
(read+write 2) (read+write 2)
@ -25,59 +20,30 @@
(bitwise-ior open/read (bitwise-ior open/read
(bitwise-ior open/write open/read+write))) (bitwise-ior open/write open/read+write)))
;;;; fcntl ;;; fcntl() commands
;;;; Rough sketch only. Will define a separate proc for each fcntl command. (define-enum-constants fcntl
; (dup-fdes 0) ; F_DUPFD
;;;; fcntl commands (get-fdes-flags 1) ; F_GETFD
;dup (set-fdes-flags 2) ; F_SETFD
; (get-status-flags 3) ; F_GETFL
;get-flags ; Only gives close-on-exec bit. (set-status-flags 4) ; F_SETFL
;set-flags (get-owner 5) ; F_GETOWN (Not Posix)
; (set-owner 6) ; F_SETOWN (Not Posix)
;get-status ; Returns open flags + get-status flags (below) (get-record-lock 7) ; F_GETLK
;set-status ; Can set: append, sync, async, nbio, nonblocking, no-delay (set-record-lock-noblock 8) ; F_SETLK
; (set-record-lock 9)) ; F_SETLKW
;get-lock
;set-lock
;nonblocking-set-lock
;
;get-record-lock
;set-record-lock
;set-record-lock-noblock
;
;get-owner ; Not POSIX
;set-owner ; Not POSIX
;remote-set-lock ; Not POSIX
;nonblocking-remote-set-lock ; Not POSIX
;remote-get-lock ; Not POSIX
;
;;;; Flags
;
;close-on-exec ; get-flags
;
;async ; get-status
;no-delay ; get-status
;nbio ; get-status
;
;lock/read ; set-lock
;lock/write ; set-lock
;lock/release ; set-lock
;;; These are internal; they are not part of the supported scsh interface. ;;; fcntl fdes-flags (F_GETFD)
(define fcntl/close-on-exec 1) (define fdflags/close-on-exec 1)
(define fcntl/dupfd 0) ;;; fcntl status-flags (F_GETFL)
(define fcntl/get-fd-flags 1) ;;; Mostly, these are OPEN/... flags, like OPEN/APPEND.
(define fcntl/set-fd-flags 2) ;;; (define fdstatus/... ...)
(define fcntl/get-file-flags 3)
(define fcntl/set-file-flags 4)
(define fcntl/get-owner 5) ; F_GETOWN
(define fcntl/set-owner 6) ; F_SETOWN
(define fcntl/get-record-lock 7) ; F_GETLK
(define fcntl/set-record-lock-noblock 8) ; F_SETLK
(define fcntl/set-record-lock 9) ; F_SETLKW
(define lock/read 1) ; F_RDLCK ;;; fcntl lock values.
(define lock/write 2) ; F_WRLCK
(define lock/release 3) ' F_UNLCK (define-enum-constants lock
(read 1) ; F_RDLCK
(write 2) ; F_WRLCK
(release 3)) ; F_UNLCK

View File

@ -1,14 +1,9 @@
;;; Signal constant definitions for Sun4 ;;; Signal constant definitions for Sun4
;;; Copyright (c) 1994 by Olin Shivers. ;;; Copyright (c) 1994 by Olin Shivers.
(define-syntax define-signals
(syntax-rules ()
((define-signals form ...)
(begin (define-enum-constant "signal" . form) ...))))
;;POSIX only defined here, couldn't find signal.h for Sun4 -dalbertz ;;POSIX only defined here, couldn't find signal.h for Sun4 -dalbertz
(define-signals (define-enum-constants signal
;; POSIX ;; POSIX
(hup 1) ; hangup (hup 1) ; hangup
(int 2) ; interrupt (int 2) ; interrupt

View File

@ -109,7 +109,7 @@
(receive (iflag-hi8 iflag-lo24 oflag-hi8 oflag-lo24 (receive (iflag-hi8 iflag-lo24 oflag-hi8 oflag-lo24
cflag-hi8 cflag-lo24 lflag-hi8 lflag-lo24 cflag-hi8 cflag-lo24 lflag-hi8 lflag-lo24
ispeed-code ospeed-code) ispeed-code ospeed-code)
(call/fdes fdport (lambda (fd) (%tty-info fd control-chars))) (sleazy-call/fdes fdport (lambda (fd) (%tty-info fd control-chars)))
(make-%tty-info control-chars (make-%tty-info control-chars
(bitwise-ior (arithmetic-shift iflag-hi8 24) iflag-lo24) (bitwise-ior (arithmetic-shift iflag-hi8 24) iflag-lo24)
(bitwise-ior (arithmetic-shift oflag-hi8 24) oflag-lo24) (bitwise-ior (arithmetic-shift oflag-hi8 24) oflag-lo24)
@ -161,7 +161,7 @@
(cflag-lo24 (bitwise-and cf #xffffff)) (cflag-lo24 (bitwise-and cf #xffffff))
(lflag-hi8 (arithmetic-shift lf -24)) (lflag-hi8 (arithmetic-shift lf -24))
(lflag-lo24 (bitwise-and lf #xffffff))) (lflag-lo24 (bitwise-and lf #xffffff)))
(call/fdes fdport (sleazy-call/fdes fdport
(lambda (fd) (lambda (fd)
(%set-tty-info fd option (%set-tty-info fd option
cc cc
@ -221,7 +221,7 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define (send-tty-break fdport . maybe-duration) (define (send-tty-break fdport . maybe-duration)
(call/fdes fdport (sleazy-call/fdes fdport
(lambda (fdes) (lambda (fdes)
(%send-tty-break-fdes fdes (:optional maybe-duration 0))))) (%send-tty-break-fdes fdes (:optional maybe-duration 0)))))
@ -240,7 +240,7 @@
(cond ((integer? fdport) (%tcdrain fdport)) ; File descriptor. (cond ((integer? fdport) (%tcdrain fdport)) ; File descriptor.
((fdport? fdport) ; Scheme port -- flush first. ((fdport? fdport) ; Scheme port -- flush first.
(force-output fdport) (force-output fdport)
(call/fdes fdport %tcdrain)) (sleazy-call/fdes fdport %tcdrain))
(else (error "Illegal argument to DRAIN-TTY" fdport)))) (else (error "Illegal argument to DRAIN-TTY" fdport))))
(define-errno-syscall (%tcdrain fdes) %tcdrain/errno) (define-errno-syscall (%tcdrain fdes) %tcdrain/errno)
@ -255,7 +255,7 @@
(define (make-tty-flusher flag) (define (make-tty-flusher flag)
(lambda (fdport) (lambda (fdport)
(call/fdes fdport (lambda (fdes) (%tcflush fdes flag))))) (sleazy-call/fdes fdport (lambda (fdes) (%tcflush fdes flag)))))
(define flush-tty/input (make-tty-flusher %flush-tty/input)) (define flush-tty/input (make-tty-flusher %flush-tty/input))
(define flush-tty/output (make-tty-flusher %flush-tty/output)) (define flush-tty/output (make-tty-flusher %flush-tty/output))
@ -274,7 +274,7 @@
(define (make-flow-controller action) (define (make-flow-controller action)
(lambda (fdport) (lambda (fdport)
(call/fdes fdport (lambda (fdes) (%tcflow fdes action))))) (sleazy-call/fdes fdport (lambda (fdes) (%tcflow fdes action)))))
(define start-tty-output (make-flow-controller %tcflow/start-out)) (define start-tty-output (make-flow-controller %tcflow/start-out))
(define stop-tty-output (make-flow-controller %tcflow/stop-out)) (define stop-tty-output (make-flow-controller %tcflow/stop-out))
@ -310,7 +310,7 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define (set-tty-process-group port/fd proc-group) (define (set-tty-process-group port/fd proc-group)
(call/fdes port/fd (sleazy-call/fdes port/fd
(lambda (fd) (lambda (fd)
(%set-tty-process-group fd (if (integer? proc-group) (%set-tty-process-group fd (if (integer? proc-group)
proc-group proc-group
@ -325,7 +325,7 @@
(to-scheme integer errno_or_false)) (to-scheme integer errno_or_false))
(define (tty-process-group port/fd) (define (tty-process-group port/fd)
(call/fdes port/fd %tty-process-group)) (sleazy-call/fdes port/fd %tty-process-group))
(define-errno-syscall (%tty-process-group fd) %tty-process-group/errno (define-errno-syscall (%tty-process-group fd) %tty-process-group/errno
pid) pid)
@ -348,14 +348,12 @@
(let lp () (let lp ()
(receive (errno fd) (open-control-tty/errno ttyname flags) (receive (errno fd) (open-control-tty/errno ttyname flags)
(cond ((not errno) (cond ((not errno)
(let* ((access (bitwise-and flags open/access-mask)) (let ((access (bitwise-and flags open/access-mask)))
(port ((if (or (= access open/read) ((if (or (= access open/read)
(= access open/read+write)) (= access open/read+write))
make-input-fdport make-input-fdport
make-output-fdport) make-output-fdport)
fd))) fd 1)))
(%install-port fd port)
port))
((= errno/intr errno) (lp)) ((= errno/intr errno) (lp))
(else (errno-error errno open-control-tty ttyname flags))))))) (else (errno-error errno open-control-tty ttyname flags)))))))

View File

@ -6,12 +6,7 @@
;;; These constants are not likely to change from stdio lib to stdio lib, ;;; These constants are not likely to change from stdio lib to stdio lib,
;;; but you need to check when you do a port. ;;; but you need to check when you do a port.
(define-syntax define-bufpols (define-enum-constants bufpol
(syntax-rules ()
((define-bufpols form ...)
(begin (define-enum-constant "bufpol" . form) ...))))
(define-bufpols
(block 0) ; _IOFBF (block 0) ; _IOFBF
(line #o200) ; _IOLBF (line #o200) ; _IOLBF
(none 4)) ; _IONBF (none 4)) ; _IONBF

View File

@ -4,14 +4,9 @@
;;; These are the correct values for Ultrix. ;;; These are the correct values for Ultrix.
(define-syntax define-errnos
(syntax-rules ()
((define-errnos form ...)
(begin (define-enum-constant "errno" . form) ...))))
(define errno/2big 7) ; 2big is not a legit Scheme symbol. Lose, lose. (define errno/2big 7) ; 2big is not a legit Scheme symbol. Lose, lose.
(define-errnos (define-enum-constants errno
;; POSIX: ;; POSIX:
(perm 1) ; Operation not permitted (perm 1) ; Operation not permitted
(noent 2) ; No such file or directory (noent 2) ; No such file or directory

View File

@ -2,12 +2,7 @@
;;; Copyright (c) 1993 by Olin Shivers. ;;; Copyright (c) 1993 by Olin Shivers.
;;; Copyright (c) 1994 by Brian D. Carlstrom. ;;; Copyright (c) 1994 by Brian D. Carlstrom.
(define-syntax define-open-flags (define-enum-constants open
(syntax-rules ()
((define-errnos form ...)
(begin (define-enum-constant "open" . form) ...))))
(define-open-flags
(read #o000) (read #o000)
(write #o001) (write #o001)
(read+write #o002) (read+write #o002)
@ -29,16 +24,29 @@
(bitwise-ior open/read (bitwise-ior open/read
(bitwise-ior open/write open/read+write))) (bitwise-ior open/write open/read+write)))
(define fcntl/close-on-exec 1) ;;; fcntl() commands
(define fcntl/dupfd 0)
(define fcntl/get-fd-flags 1)
(define fcntl/set-fd-flags 2)
(define fcntl/get-file-flags 3)
(define fcntl/set-file-flags 4)
(define fcntl/get-record-lock 7) ; F_GETLK
(define fcntl/set-record-lock-noblock 8) ; F_SETLK
(define fcntl/set-record-lock 9) ; F_SETLKW
(define lock/read 1) ; F_RDLCK (define-enum-constants fcntl
(define lock/write 2) ; F_WRLCK (dup-fdes 0) ; F_DUPFD
(define lock/release 3) ; F_UNLCK (get-fdes-flags 1) ; F_GETFD
(set-fdes-flags 2) ; F_SETFD
(get-status-flags 3) ; F_GETFL
(set-status-flags 4) ; F_SETFL
(get-record-lock 7) ; F_GETLK
(set-record-lock-noblock 8) ; F_SETLK
(set-record-lock 9)) ; F_SETLKW
;;; fcntl fdes-flags (F_GETFD)
(define fdflags/close-on-exec 1)
;;; fcntl status-flags (F_GETFL)
;;; Mostly, these are OPEN/... flags, like OPEN/APPEND.
;;; (define fdstatus/... ...)
;;; fcntl lock values.
(define-enum-constants lock
(read 1) ; F_RDLCK
(write 2) ; F_WRLCK
(release 3)) ; F_UNLCK

View File

@ -2,14 +2,9 @@
;;; Copyright (c) 1994 by Olin Shivers. ;;; Copyright (c) 1994 by Olin Shivers.
;;; Copyright (c) 1994 by Brian D. Carlstrom. ;;; Copyright (c) 1994 by Brian D. Carlstrom.
(define-syntax define-signals
(syntax-rules ()
((define-signals form ...)
(begin (define-enum-constant "signal" . form) ...))))
;;POSIX only defined here. ;;POSIX only defined here.
(define-signals (define-enum-constants signal
;; POSIX ;; POSIX
(hup 1) ; hangup (hup 1) ; hangup
(int 2) ; interrupt (int 2) ; interrupt