Newer
Older
;;; -*- Package: UNIX -*-
;;;
;;; **********************************************************************
;;; This code was written as part of the CMU Common Lisp project at
;;; Carnegie Mellon University, and has been placed in the public domain.
;;;
(ext:file-comment
"$Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/code/unix.lisp,v 1.63 1999/03/08 18:03:19 pw Exp $")
;;;
;;; **********************************************************************
;;;
;;; This file contains the UNIX low-level support.
;;;
(in-package "UNIX")
(use-package "ALIEN")
(use-package "C-CALL")
(use-package "SYSTEM")
(use-package "EXT")
(export '(
daddr-t caddr-t ino-t swblk-t size-t time-t dev-t off-t uid-t gid-t
timeval tv-sec tv-usec timezone tz-minuteswest tz-dsttime
itimerval it-interval it-value tchars t-intrc t-quitc t-startc
t-stopc t-eofc t-brkc ltchars t-suspc t-dsuspc t-rprntc t-flushc
t-werasc t-lnextc sgttyb sg-ispeed sg-ospeed sg-erase sg-kill
sg-flags winsize ws-row ws-col ws-xpixel ws-ypixel
direct d-off d-ino d-reclen #-(or linux svr4) d-namlen d-name
stat st-dev st-mode st-nlink st-uid st-gid st-rdev st-size
st-atime st-mtime st-ctime st-blksize st-blocks
s-ifmt s-ifdir s-ifchr s-ifblk s-ifreg s-iflnk s-ifsock
s-isuid s-isgid s-isvtx s-iread s-iwrite s-iexec
ruseage ru-utime ru-stime ru-maxrss ru-ixrss ru-idrss
ru-isrss ru-minflt ru-majflt ru-nswap ru-inblock ru-oublock
ru-msgsnd ru-msgrcv ru-nsignals ru-nvcsw ru-nivcsw
unix-errno get-unix-error-msg
unix-pathname unix-file-mode unix-fd unix-pid unix-uid unix-gid
unix-access r_ok w_ok x_ok f_ok unix-chdir unix-chmod setuidexec
setgidexec savetext readown writeown execown readgrp writegrp
execgrp readoth writeoth execoth unix-fchmod unix-chown unix-fchown
unix-getdtablesize unix-close unix-creat unix-dup unix-dup2
unix-fcntl f-dupfd f-getfd f-setfd f-getfl f-setfl f-getown f-setown
fndelay fappend fasync fcreat ftrunc fexcl unix-link unix-lseek
l_set l_incr l_xtnd unix-mkdir unix-open o_rdonly o_wronly o_rdwr
#+(or hpux svr4 freebsd linux) o_ndelay
#+(or hpux svr4 freebsd linux) o_noctty #+(or hpux svr4) o_nonblock
o_append o_creat o_trunc o_excl unix-pipe unix-read unix-readlink
unix-rename unix-rmdir unix-fast-select fd-setsize fd-set fd-clr
fd-isset fd-zero unix-select unix-sync unix-fsync unix-truncate
unix-ftruncate unix-symlink
#+(and sparc svr4) unix-times
unix-unlink unix-write unix-ioctl
tcsetpgrp tcgetpgrp tty-process-group
terminal-speeds tty-raw tty-crmod tty-echo tty-lcase
#-hpux tty-cbreak #-(or hpux linux) tty-tandem
#+(or hpux svr4 linux freebsd) termios
#+(or hpux svr4 linux freebsd) c-lflag
#+(or hpux svr4 linux freebsd) c-iflag
#+(or hpux svr4 linux freebsd) c-oflag
#+(or hpux svr4 linux freebsd) tty-icrnl
#+(or hpux svr4 linux) tty-ocrnl
#+(or hpux svr4 freebsd) vdsusp #+(or hpux svr4 linux freebsd) veof
#+(or hpux svr4 linux freebsd) vintr
#+(or hpux svr4 linux freebsd) vquit
#+(or hpux svr4 linux freebsd) vstart
#+(or hpux svr4 linux freebsd) vstop
#+(or hpux svr4 linux freebsd) vsusp
#+(or hpux svr4 linux freebsd) c-cflag
#+(or hpux svr4 linux freebsd) c-cc
#+(or bsd osf1) c-ispeed
#+(or bsd osf1) c-ospeed
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#+(or hpux svr4 linux freebsd) tty-icanon
#+(or hpux svr4 linux freebsd) vmin
#+(or hpux svr4 linux freebsd) vtime
#+(or hpux svr4 linux freebsd) tty-ixon
#+(or hpux svr4 freebsd linux) tcsanow
#+(or hpux svr4 freebsd linux) tcsadrain
#+(or hpux svr4 freebsd linux) tciflush
#+(or hpux svr4 freebsd linux) tcoflush
#+(or hpux svr4 freebsd linux) tcioflush
#+(or hpux svr4 freebsd linux) tcsaflush
#+(or hpux svr4 linux freebsd) unix-tcgetattr
#+(or hpux svr4 linux freebsd) unix-tcsetattr
#+(or hpux svr4 freebsd) unix-cfgetospeed
#+(or hpux svr4 freebsd) unix-cfsetospeed
#+(or hpux svr4 freebsd) unix-cfgetispeed
#+(or hpux svr4 freebsd) unix-cfsetispeed
#+(or hpux svr4 linux freebsd) tty-ignbrk
#+(or hpux svr4 linux freebsd) tty-brkint
#+(or hpux svr4 linux freebsd) tty-ignpar
#+(or hpux svr4 linux freebsd) tty-parmrk
#+(or hpux svr4 linux freebsd) tty-inpck
#+(or hpux svr4 linux freebsd) tty-istrip
#+(or hpux svr4 linux freebsd) tty-inlcr
#+(or hpux svr4 linux freebsd) tty-igncr
#+(or hpux svr4 linux) tty-iuclc
#+(or hpux svr4 linux freebsd) tty-ixany
#+(or hpux svr4 linux freebsd) tty-ixoff
#+hpux tty-ienqak
#+(or hpux irix solaris linux freebsd) tty-imaxbel
#+(or hpux svr4 linux freebsd) tty-opost
#+(or hpux svr4 linux) tty-olcuc
#+(or hpux svr4 linux freebsd) tty-onlcr
#+(or hpux svr4 linux) tty-onocr
#+(or hpux svr4 linux) tty-onlret
#+(or hpux svr4 linux) tty-ofill
#+(or hpux svr4 linux) tty-ofdel
#+(or hpux svr4 linux freebsd) tty-isig
#+(or hpux svr4 linux) tty-xcase
#+(or hpux svr4 linux freebsd) tty-echoe
#+(or hpux svr4 linux freebsd) tty-echok
#+(or hpux svr4 linux freebsd) tty-echonl
#+(or hpux svr4 linux freebsd) tty-noflsh
#+(or hpux svr4 linux freebsd) tty-iexten
#+(or hpux svr4 linux freebsd) tty-tostop
#+(or hpux irix solaris linux freebsd) tty-echoctl
#+(or hpux irix solaris linux freebsd) tty-echoprt
#+(or hpux irix solaris linux freebsd) tty-echoke
#+(or hpux irix solaris) tty-defecho
#+(or hpux irix solaris freebsd) tty-flusho
#+(or hpux irix solaris linux freebsd) tty-pendin
#+(or hpux svr4 linux freebsd) tty-cstopb
#+(or hpux svr4 linux freebsd) tty-cread
#+(or hpux svr4 linux freebsd) tty-parenb
#+(or hpux svr4 linux freebsd) tty-parodd
#+(or hpux svr4 linux freebsd) tty-hupcl
#+(or hpux svr4 linux freebsd) tty-clocal
#+(or irix solaris) rcv1en
#+(or irix solaris) xmt1en
#+(or hpux irix solaris) tty-loblk
#+(or hpux svr4 linux freebsd) vintr
#+(or hpux svr4 linux freebsd) verase
#+(or hpux svr4 linux freebsd) vkill
#+(or hpux svr4 linux freebsd) veol
#+(or hpux irix solaris linux freebsd) veol2
#+(or hpux irix solaris) tty-cbaud
#+(or hpux svr4 freebsd) tty-csize #+(or hpux svr4 freebsd) tty-cs5
#+(or hpux svr4 freebsd) tty-cs6 #+(or hpux svr4 freebsd) tty-cs7
#+(or hpux svr4 freebsd) tty-cs8
#+(or hpux svr4 freebsd) unix-tcsendbreak
#+(or hpux svr4 freebsd) unix-tcdrain
#+(or hpux svr4 freebsd) unix-tcflush
#+(or hpux svr4 freebsd) unix-tcflow
TIOCGETP TIOCSETP TIOCFLUSH TIOCSETC TIOCGETC TIOCSLTC
unix-exit unix-stat unix-lstat unix-fstat
unix-getrusage unix-fast-getrusage rusage_self rusage_children
unix-gettimeofday
#-hpux unix-utimes #-(or svr4 hpux) unix-setreuid
#-(or svr4 hpux) unix-setregid
unix-getpid unix-getppid
#+(or svr4 freebsd)unix-setpgid
unix-getgid unix-getegid unix-getpgrp unix-setpgrp unix-getuid
unix-getpagesize unix-gethostname unix-gethostid unix-fork
unix-current-directory unix-isatty unix-ttyname unix-execve
unix-socket unix-connect unix-bind unix-listen unix-accept
unix-recv unix-send unix-getpeername unix-getsockname))
(pushnew :unix *features*)
;;;; Common machine independent structures.
#+bsd
(def-alien-type quad-t (array unsigned-long 2))
(def-alien-type daddr-t #-(or linux alpha) long #+(or linux alpha) int)
(def-alien-type ino-t #-alpha unsigned-long #+alpha unsigned-int)
(def-alien-type size-t #-(or linux alpha) long #+linux unsigned-int
#+alpha unsigned-long)
(def-alien-type time-t #-(or linux alpha) unsigned-long #+linux long
#+alpha unsigned-int)
(def-alien-type dev-t #-(or alpha svr4 bsd linux) short #+linux unsigned-short
#+alpha int #+(and (not linux) (or bsd svr4)) unsigned-long)
#-FreeBSD
(def-alien-type off-t #-alpha long #+alpha unsigned-long)
#+FreeBSD
(def-alien-type off-t quad-t)
#-FreeBSD
(def-alien-type uid-t #-(or alpha svr4) unsigned-short #+alpha unsigned-int
#+svr4 long)
#+FreeBSD
(def-alien-type uid-t unsigned-long)
#-FreeBSD
(def-alien-type gid-t #-(or alpha svr4) unsigned-short #+alpha unsigned-int
#+svr4 long)
(def-alien-type mode-t #-(or alpha svr4) unsigned-short
(def-alien-type nlink-t #-svr4 unsigned-short #+svr4 unsigned-long)
(defconstant FD-SETSIZE #-(or hpux alpha linux) 256 #+hpux 2048 #+alpha 4096 #+linux 1024)
(fds-bits (array #-alpha unsigned-long #+alpha int #.(/ fd-setsize 32)))))
(setf (deref (slot ,fd-set 'fds-bits) ,word)
(logior (truly-the (unsigned-byte 32) (ash 1 ,bit))
(deref (slot ,fd-set 'fds-bits) ,word))))))
(setf (deref (slot ,fd-set 'fds-bits) ,word)
(logand (deref (slot ,fd-set 'fds-bits) ,word)
(32bit-logical-not
(truly-the (unsigned-byte 32) (ash 1 ,bit))))))))
(defmacro fd-isset (offset fd-set)
(let ((word (gensym))
(bit (gensym)))
`(multiple-value-bind (,word ,bit) (floor ,offset 32)
(logbitp ,bit (deref (slot ,fd-set 'fds-bits) ,word)))))
`(progn
,@(loop for index upfrom 0 below (/ fd-setsize 32)
collect `(setf (deref (slot ,fd-set 'fds-bits) ,index) 0))))
;;; From sys/time.h
(def-alien-type nil
(struct timeval
(tv-sec #-linux time-t #+linux int) ; seconds
(tv-usec #-linux time-t #+linux int))) ; and microseconds
(def-alien-type nil
(struct timezone
(tz-minuteswest int) ; minutes west of Greenwich
(tz-dsttime ; type of dst correction
#-linux (enum nil :none :usa :aust :wet :met :eet :can)
#+linux int)))
(def-alien-type nil
(struct itimerval
(it-interval (struct timeval)) ; timer interval
(it-value (struct timeval)))) ; current value
; High-res time. Actually posix definition under svr4 name.
(def-alien-type nil
(struct timestruc-t
(tv-sec time-t)
(tv-nsec long)))
#+(or linux FreeBSD)
(def-alien-type nil
(struct timespec-t
(ts-sec long)
(ts-nsec long)))
(def-alien-type nil
(struct tchars
(t-intrc char) ; interrupt
(t-quitc char) ; quit
(t-startc char) ; start output
(t-stopc char) ; stop output
(t-suspc char) ; stop process signal
(t-dsuspc char) ; delayed stop process signal
(t-rprntc char) ; reprint line
(t-flushc char) ; flush output (toggles)
#+linux (sg-flags #+mach short #-mach int) ; mode flags
(sg-ispeed char) ; input speed.
(sg-ospeed char) ; output speed
(sg-erase char) ; erase character
#-linux (sg-kill char) ; kill character
#-linux (sg-flags #+mach short #-mach int) ; mode flags
#+linux (sg-kill char)
#+linux (t (struct termios))
#+linux (check int)))
(def-alien-type nil
(struct winsize
(ws-row unsigned-short) ; rows, in characters
(ws-col unsigned-short) ; columns, in characters
(ws-xpixel unsigned-short) ; horizontal size, pixels
(ws-ypixel unsigned-short))) ; veritical size, pixels
;;; NOTE: There is both a termio (SYSV) and termios (POSIX)
;;; structure with similar but incompatible definitions. It may be that
;;; the non-BSD variant of termios below is really a termio but I (pw)
;;; can't verify. The BSD variant uses the Posix termios def. Some systems
;;; (Ultrix and OSF1) seem to support both if used independently.
;;; The 17f version of this seems a bit confused wrt the conditionals.
;;; Please check these defs for your system.
;;; TSM: from what I can tell looking at the 17f definition, my guess is that it
;;; was originally a termio for sunos (nonsolaris) (because it had the c-line
;;; member for sunos only), and then was mutated into the termios definition for
;;; later systems. The definition here is definitely not an IRIX termio because
;;; it doesn't have c-line. In any case, the functions tcgetattr, etc.,
;;; definitely take a termios, and termios seems to be the more standard
;;; standard now, so my suggestion is to just go with termios and forget about
;;; termio. Note the SVID says NCCS not NCC for the constant here, so I've
;;; changed it (which means you need to bootstrap it to avoid a reader error).
;;; On top of all that, SGI decided to change the termios structure on irix
;;; 6.[34] (but NOT 6.2), left the old routines named the same in the library,
;;; but introduced static functions in termios.h to redirect new calls to the
;;; new library--which means it's important not to #include termios.h before
;;; undefineds.h when building lisp.
(defconstant +NCCS+
#+hpux 16
#+irix 23
#+(and sunos (not svr4)) 17
"Size of control character vector.")
(c-iflag unsigned-int)
(c-oflag unsigned-int)
(c-cflag unsigned-int)
(c-lflag unsigned-int)
#+(or linux hpux (and sunos (not svr4)))
(c-reserved #-(or linux (and sunos (not svr4))) unsigned-int
#+(or linux (and sunos (not svr4))) unsigned-char)
(c-cc (array unsigned-char #.+NCCS+))
#+(or bsd osf1) (c-ispeed unsigned-int)
#+(or bsd osf1) (c-ospeed unsigned-int)))
#+(and sunos (not svr4)) (d-off long) ; offset of next disk directory entry
(d-namlen unsigned-short) ; length of string in d-name
(d-name (array char 256)))) ; name must be no longer than this
#+bsd
(def-alien-type nil
(struct direct
(d-fileno unsigned-long)
(d-reclen unsigned-short)
(d-type unsigned-char)
(d-namlen unsigned-char) ; length of string in d-name
(d-name (array char 256)))) ; name must be no longer than this
#-(or svr4 freebsd linux) ; eg hpux and alpha
(def-alien-type nil
(struct stat
(st-dev dev-t)
(st-ino ino-t)
(st-uid uid-t)
(st-gid gid-t)
(st-rdev dev-t)
(st-size off-t)
(st-atime time-t)
(st-spare1 int)
(st-mtime time-t)
(st-spare2 int)
(st-ctime time-t)
(st-spare3 int)
(st-blksize #-alpha long #+alpha unsigned-int)
(st-blocks #-alpha long #+alpha int)
Loading
Loading full blame...