english
version "1.0"
identify "xyz"

#: Copyright (c) 1998-2005 by Wayne C. Gramlich.
#, All rights reserved.

#: This module provicdes interfaces to the Unix(tm) operating system.
#, It is intended that these calls be `wrapped' by higher level libraries.

module unix_system

define unix_system
    external

define open_flags		#: Bit positions of open(2) flags
    enumeration
	write_only		#: O_CREAT = 1<<0
	read_write		#: O_RDWR = 1<<1
	unused1			# 1<<2
	unused2			# 1<<3
	unused3			# 1<<4
	unused4			# 1<<5
	create			#: O_CREAT = 1<<6
	exclusive		#: O_EXCL = 1<<7
	no_control_tty		#: O_NOCTTY = 1<<8
	truncate		#: O_TRUNC = 1<<9
	append			#: O_APPEND = 1<<10
	no_block		#: O_NONBLOCK = O_NDELAY = 1<<11
	synchronous		#: O_SYNC = 1<<12
    generate print, unsigned_convert

define file_control_operation	#: File control (fcntl(2)) operation flags
    enumeration
	duplicate		#: F_DUPFD(0) = Duplicate file descriptor
	get_close_on_execute	#: F_GETFD(1) = Get close on execute flag
	set_close_on_execute	#: F_SETFD(2) = Get close on execute flag
	get_flags		#: F_GETFL(3) = Get file descriptor flags
	set_flags		#: F_SETFL(4) = Set file_descriptor flags
	get_lock		#: F_GETLK(5) = Get file descretionary lock
	set_lock		#: F_GETLK(6) = Set file descretionary lock
	set_lock_wait		#: F_GETLKW(7) = Set file descr. lock, wait
	get_owner		#: F_GETOWN(8) = Get owner (for sockets)
	set_owner		#: F_SETOWN(9) = Set owner (for sockets)
    generate print, unsigned_convert

define socket_options		#: Socket options for setsockopt(2)
    enumeration
	unused1			#: Unused 1
	debug			#: SO_DEBUG(1) - Enable debugging
	reuse_address		#: SO_REUSEADDR(2) - Enable local address reuse
	type			#: SO_TYPE(3) - Get Socket type
	error			#: SO_ERROR(4) - Get and clear socket error
	do_not_route		#: SO_DONTROUTE(5) - Bypass output msg. routing
	broadcast		#: SO_BROADCAST(6) - Enable broadcast messages
	send_buffer		#: SO_SNDBUF(7) - Set send buffer size
	receive_buffer		#: SO_RCVBUF(8) - Set receive buffer size
	keep_alive		#: SO_KEEPALIVE(9) - Keep connection alive
	out_of_band		#: SO_OOBINLINE(10) - Enable out of band data
	no_check		#: SO_NO_CHECK(11) - ??
	priority		#: SO_PRIORITY(12) - ??
	linger			#: SO_LINGER(13) - Linger on close
	bsd_compatible		#: SO_BSDCOMPAT(14) - ??
    generate print, unsigned_convert

define unix_system_error_number	#: Error numbers from errno.h
    enumeration
	ok			#: The operation was successful
	not_permitted		#: EPERM=1 - Operation not permitted
	no_file			#: ENOENT=2 - No such file or directory
	no_process		#: ESRCH=3 - No such process
	interrupt		#: EINTR=4 - Interrupted system call
	io_error		#: EIO=5 - I/O error
	no_device		#: ENXIO=6 - No such device or address
	list_too_big		#: E2BIG=7 - Arg list too long
	no_execute		#: ENOEXEC=8 - Exec format error
	bad_file		#: EBADF=9 - Bad file number
	no_child		#: ECHILD=10 - No child processes
	try_again		#: EAGAIN=11 - Try again
	no_memory		#: ENOMEM=12 - Out of memory
	no_access		#: EACCES=13 - Permission denied
	bad_address		#: EFAULT=14 - Bad address
	block_required		#: ENOTBLK=15 - Block device required
	busy			#: EBUSY=16 - Device or resource busy
	file_exists		#: EEXIST=17 - File exists
	cross_device_link	#: EXDEV=18 - Cross-device link
	no_such_device		#: ENODEV=19 - No such device
	not_directory		#: ENOTDIR=20 - Not a directory
	is_directory		#: EISDIR=21 - Is a directory
	invalid			#: EINVAL=22 - Invalid argument
	file_table_overflow	#: ENFILE=23 - File table overflow
	too_many_files		#: EMFILE=24 - Too many open files
	not_tty			#: ENOTTY=25 - Not a typewriter
	text_busy		#: ETXTBSY=26 - Text file busy
	file_too_big		#: EFBIG=27 - File too large
	no_space		#: ENOSPC=28 - No space left on device
	illegal_seek		#: ESPIPE=29 - Illegal seek
	read_only		#: EROFS=30 - Read-only file system
	too_many_links		#: EMLINK=31 - Too many links
	broken_pipe		#: EPIPE=32 - Broken pipe
	domain_error		#: EDOM=33 - Math arg. out of domain of func
	range_error		#: ERANGE=34 - Math result not representable
	resource_deadlock	#: EDEADLK=35 - Resource deadlock would occur
	name_too_long		#: ENAMETOOLONG=36 - File name too long
	no_locks		#: ENOLCK=37 - No record locks available
	not_implemented		#: ENOSYS=38 - Function not implemented
	not_empty		#: ENOTEMPTY=39 - Directory not empty
	link_loop		#: ELOOP=40 - Too many sym. links encountered
	unused1
	no_message		#: ENOMSG=42 - No message of desired type
	identifier_removed	#: EIDRM=43 - Identifier removed
	channel_range		#: ECHRNG=44 - Channel number out of range
	level2_no_synch		#: EL2NSYNC=45 - Level 2 not synchronized
	level3_halted		#: EL3HLT=46 - Level 3 halted
	level3_reset		#: EL3RST=47 - Level 3 reset
	link_range		#: ELNRNG=48 - Link number out of range
	unattached		#: EUNATCH=49 - Protocol driver not attached
	no_csi			#: ENOCSI=50 - No CSI structure available
	level2_halted		#: EL2HLT=51 - Level 2 halted
	bad_exchange		#: EBADE=52 - Invalid exchange
	bad_request		#: EBADR=53 - Invalid request descriptor
	exchange_full		#: EXFULL=54 - Exchange full
	no_anode		#: ENOANO=55 - No anode
	bad_request_code	#: EBADRQC=56 - Invalid request code
	bad_slot		#: EBADSLT=57 - Invalid slot
	file_deadlock		#: EDEADLOCK=58 - File locking deadlock error
	bad_font		#: EBFONT=59 - Bad font file format
	not_stream		#: ENOSTR=60 - Device not a stream
	no_data			#: ENODATA=61 - No data available
	timre_expired		#: ETIME=62 - Timer expired
	no_streams		#: ENOSR=63 - Out of streams resources
	no_net			#: ENONET=64 - Machine is not on the network
	no_package		#: ENOPKG=65 - Package not installed
	remote_object		#: EREMOTE=66 - Object is remote
	no_link			#: ENOLINK=67 - Link has been severed
	advertise_error		#: EADV=68 - Advertise error
	srmount_error		#: ESRMNT=69 - Srmount error
	comm_error		#: ECOMM=70 - Communication error on send
	protocol_error		#: EPROTO=71 - Protocol error
	multihop		#: EMULTIHOP=72 - Multihop attempted
	rfs_error		#: EDOTDOT=73 - RFS specific error
	bad_message		#: EBADMSG=74 - Not a data message
	overflow		#: EOVERFLOW=75 - Value too large
	not_unique		#: ENOTUNIQ=76 - Name not unique on network
	bad_file_state		#: EBADFD=77 - File descriptor in bad state
	remote_changed		#: EREMCHG=78 - Remote address changed
	library_access		#: ELIBACC=79 - Can't access a needed sh. lib.
	library_bad		#: ELIBBAD=80 - Accessing a corrupted sh. lib.
	library_corrupted	#: ELIBSCN=81 - .lib section in a.out corrupted
	library_maximum		#: ELIBMAX=82 - Attempting to link in too many shared libraries
	library_execute		#: ELIBEXEC=83 - Can' exec a sh. lib. directly
	byte_sequence		#: EILSEQ=84 - Illegal byte sequence
	restart			#: ERESTART=85 - Interrupted system call should be restarted
	streams_pipe_error	#: ESTRPIPE=86 - Streams pipe error
	too_many_users		#: EUSERS=87 - Too many users
	not_socket		#: ENOTSOCK=88 - Socket operation on non-socket
	destination_required	#: EDESTADDRREQ=89 - Dest. address required
	message_size		#: EMSGSIZE=90 - Message too long
	protocol_type_error	#: EPROTOTYPE=91 - Protocol wrong type for socket
	no_protocol		#: ENOPROTOOPT=92 - Protocol not available
	protocol_unsupported	#: EPROTONOSUPPORT=93 - Protocol not supported
	socket_type_unsupported	#: ESOCKTNOSUPPORT=94 - Socket type not supported
	not_supported		#: EOPNOTSUPP=95 - Operation not supported on transport endpoint
	family_unsupported	#: EPFNOSUPPORT=96 - Protocol family not supported
	address_unsupported	#: EAFNOSUPPORT=97 - Address family not supported by protocol
	address_in_use		#: EADDRINUSE=98 - Address already in use
	address_unavailable	#: EADDRNOTAVAIL=99 - Cannot assign requested address
	network_down		#: ENETDOWN=100 - Network is down
	network_unreachable	#: ENETUNREACH=101 - Network is unreachable
	ntework_reset		#: ENETRESET=102 - Network dropped connection because of reset
	connection_aborted	#: ECONNABORTED=103 - Software caused connection abort
	connection_reset	#: ECONNRESET=104 - Connection reset by peer
	no_buffers		#: ENOBUFS=105 - No buffer space available
	is_connected		#: EISCONN=106 - Transport endpoint is already connected
	not_connected		#: ENOTCONN=107 - Transport endpoint isn't connected
	transport_shutdown	#: ESHUTDOWN=108 - Can't send after transport endpoint shutdown
	too_many_references	#: ETOOMANYREFS=109 - Too many refs: can't splice
	timed_out		#: ETIMEDOUT=110 - Connection timed out
	connection_refused	#: ECONNREFUSED=111 - Connection refused
	host_down		#: EHOSTDOWN=112 - Host is down
	host_unreachable	#: EHOSTUNREACH=113 - No route to host
	already_in_progress	#: EALREADY=114 - Operation already in progress
	in_process		#: EINPROGRESS=115 - Operation now in progress
	stale_nfs		#: ESTALE=116 - Stale NFS file handle
	needs_cleaning		#: EUCLEAN=117 - Structure needs cleaning
	no_xenix_named_type	#: ENOTNAM=118 - Not a XENIX named type file
	no_xenix_semaphore	#: ENAVAIL=119 - No XENIX semaphores available
	is_named_type		#: EISNAM=120 - Is a named type file
	remote_io_error		#: EREMOTEIO=121 - Remote I/O error
	quota_exceeded		#: EDQUOT=122 - Quota exceeded
    generate equal, print, unsigned_convert



#: There is only one {unix_system} object and it is ??@{unix_system}.

procedure accept@unix_system
    takes
	unix_system unix_system
	file_descriptor_number unsigned
    returns unsigned
    external unix_system__accept
    
    #: This procedure will accept a connection on the socket referred
    #, to by {file_descriptor_number}.  The internet address of the
    #, connection initiator is returned.  For now, this interface
    #, does not provide any way to get the port number.  A call to
    #, {status_get}@{unix_system}() will indicate how successful the
    #, operation is; the possible return values are {ok}, {bad_file},
    #, {not_socket}, {not_supported}, {bad_address}, or {try_again}.
    #,
    #, This procedure is equivalent to the accept(2) system call.



procedure bind@unix_system
    takes
	unix_system unix_system
	file_descriptor_number unsigned
	internet_address unsigned
	port_number unsigned
    returns_nothing
    external unix_system__bind

    #: This procedure will bind {internet_address} and {port_number} to
    #, the socket referred to by {file_descriptor_number}.  A call to
    #, {status_get}@{unix_system}() will indicate how successful the
    #, operation is; the possible return values are {ok}, {bad_file},
    #, {invalid}, or {no_access}.
    #,
    #, This procedure is equivalent to the bind(2) system call.



procedure connect@unix_system
    takes
	unix_system unix_system
	file_descriptor_number unsigned
	internet_address unsigned
	port_number unsigned
    returns_nothing
    external connect__unix_system

    #: This procedure will connect the socket referred to by
    #, {file_descriptor_number} to port {port_number} at the
    #, host identified by {internet_address}.  A call to
    #, {status_get}@(unix_system}() will indicate how successful
    #, the operation is; the possible return values are {ok}, and
    #, some other undocument error values (sorry!).
    #,
    #, This procedure is equivalent to the connect(2) system call.



procedure close@unix_system
    takes
	unix_system unix_system
	file_descriptor_number unsigned
    returns_nothing
    external unix_system__close

    #: This procedure will close {file_descriptor_number}.  A call to
    #, {status_get}@{unix_system}() will indicate how successful the
    #, operation is; the possible return values are {ok} or {bad_file}.
    #,
    #, It is really important to check the return status of this call
    #, when writing out a file because sometimes the operating system
    #, does not realize that there is no disk space left until after a
    #, write(2) system call has successfully returned.  By verifying
    #, that the close call succeeded, there is assurances that the file
    #, was written successfully.
    #,
    #, This procedure is equivalent to the close(2) system call.



procedure directory_create@unix_system
    takes
	unix_system unix_system
	new_directory_name string
	new_directory_mode unsigned
    returns_nothing
    external unix_system__directory_create

    #: This procedure will create a directory named {new_directory_name}
    #, with access mode bits of {new_directory_mode}.  A call to
    #, {status_get}@{unix_system}() will indicate how successful the
    #, operation is; the possible return values are {file_exists},
    #, {no_access}, {name_too_long}, {no_file}, {not_directory},
    #, {no_mememory}, and {read_only}.
    #,
    #, This procedure is equivalent to the mkdir(2) system call.



procedure duplicate@unix_system
    takes
	unix_system unix_system
	file_descriptor_number unsigned
    returns unsigned

    #: This procedure will duplicate the {file_descriptor_number} and
    #, return the duplicate file descriptor number.  A call to
    #, {status_get}@{unix_system}() will return one of {ok}, {not_open},
    #, and {none_available}.
    #,
    #, This procedure is equivalent to the dup(2) system call.


procedure duplicate2@unix_system
    takes
	unix_system unix_system
	from_file_descriptor_number unsigned
	to_file_descriptor_number unsigned
    returns unsigned
    external unix_system__duplicate2

    #: This procedure will duplicate the {from_file_descriptor_number} to
    #, {to_file_descriptor_number}, closing {to_file_descriptor_number} if
    #, necessary.  A call to {status_get}@{unix_system}() will return one
    #, of {ok}, {not_open}, and {none_available}.  This call is permitted
    #, modify file descriptors 0, 1, and 2.
    #,
    #, This procedure is equivalent to the dup2(2) system call.



procedure environment_get@unix_system
    takes
	unix_system unix_system
    returns string_array
    external unix_system__environment_get

    #: This procedure will return the environment vector passed into
    #, the currently executing process.



procedure execute@unix_system
    takes
	unix_system unix_system
	file_name string
	arguments string_array
	environment string_array	
    returns_nothing
    external unix_system__execute

    #: This procedure will execute the file named {file_name}
    #, with arguments of {arguments} and an environment of {environment}.
    #, This procedure will only return if an error occurs.
    


procedure exit@unix_system
    takes
	unix_system unix_system
	status unsigned
    returns_nothing
    external unix_system__exit

    #: This procedure will cause the current process to immediately
    #, exit with a status of {status}.  This procedure never returns.
    #, This procedure invokes the _exit(2) system call.



procedure file_control@unix_system
    takes
	unix_system unix_system
	file_descriptor_number unsigned
	file_control_operation file_control_operation
	operation_argument unsigned
    returns unsigned
    external unix_system__file_control

    #: This procedure will perform a fcntl(2) unix system call where
    #, {file_descriptor_number} is the file descriptor to operate on,
    #, {file_control_operation} is the operation to be performed, and
    #, {operation_argument} is an unsigned value to be passed into
    #, operation.  Not all operations need {operation_argument}.  Any
    #, return value from the operation is returned.



procedure fork@unix_system
    takes
	unix_system unix_system
    returns unsigned
    external unix_system__fork

    #: This procedure will performe fork(2) unix system call.
    #, In general, this procudure is intended to be used right
    #, before calling the {execute}@{unix_system}() procedure.
    #, The child process will get a return value of 0.  The parent
    #, process will get the child process id.



procedure get_socket_option@unix_system
    takes
	unix_system unix_system
	socket_number unsigned
	socket_options socket_options
    returns unsigned
    external unix_system__get_socket_option

    #: This procedure will return the {socket_option} value for
    #, {socket_number}.



procedure host_lookup@unix_system
    takes
	unix_system unix_system
	internet_address unsigned
	host_name string
    returns logical
    external unix_system__host_lookup


    #: This procedure will lookup the system name for {internet_address}
    #, and store it into the writable string {host_name}.  If the lookup
    #, is successful, {true}@{logical} is returned; otherwise, {false} is
    #, returned.
    #,
    #, This procedure is equivalent to gethostbyaddr(2).



procedure internet_address_lookup@unix_system
    takes
	unix_system unix_system
	host_name string
    returns unsigned
    external unix_system__internet_address_lookup

    #: This procedure will lookup the internet address associated with
    #, {host_name}.  If {host_name} can not be successfully looked up,
    #, 0 is returned.
    #,
    #, This procedure is equivalent to gethostbyname(2).



procedure kernel_system_name@unix_system
    takes
	unix_system unix_system
	system_name string
    returns_nothing
    external unix_system__kernel_system_name

    #: This procedure will store the kernel system name into the writable
    #, string {system_name}.
    #,
    #, This procedure is equivalent to uname(2).sysname.



procedure kernel_node_name@unix_system
    takes
	unix_system unix_system
	node_name string
    returns_nothing
    external unix_system__kernel_node_name

    #: This procedure will store the kernel system name into the writable
    #, string {node_name}.
    #,
    #, This procedure is equivalent to uname(2).nodename.



procedure kernel_domain_name@unix_system
    takes
	unix_system unix_system
	domain_name string
    returns_nothing

    #: This procedure will store the kernel system name into the writable
    #, string {domain_name}.
    #,
    #, This procedure is equivalent to uname(2).domainname.


procedure kill@unix_system
    takes
	unix_system unix_system
	process_number unsigned
	signal_number unsigned
    returns_nothing
    external unix_system__kill

    #: This procedure will send signal {signal_number} to process
    #, {process_number}.



procedure listen@unix_system
    takes
	unix_system unix_system
	file_descriptor_number unsigned
	queue_length unsigned
    returns_nothing
    external unix_system__listen

    #: This procedure will cause the operating system to start listening
    #, for connections on the socket referred to by {file_descriptor_number}.
    #, Up to {queue_length} connections can be pending for accepts before
    #, the operating system will start refusing connections.  A call to
    #, {status_get}@{unix_system}() will indicate how successful the
    #, operation is; the possible return values are {ok}, {bad_file},
    #, {not_socket}, or {not_supported}.
    #,
    #, This procedure is equivalient to the listen(2) system call.



procedure one_and_only@unix_system
    takes_nothing
    returns unix_system

    #: This procedure will return the one and only {unix_system} object.


procedure open@unix_system
    takes
	unix_system unix_system
	pathname string
	flags unsigned
	mode unsigned
    returns unsigned
    external unix_system__open

    #: This procedure will open and return a file_descriptor number for
    #, for {pathname}.  The {flags} argument specifies how to perform
    #, the open.  Basically, each flag bit is enableded by taking
    #, 1<<{unsigned_convert}@({open_flag}) for values of {open_flags}.
    #, If any file is created, it will be created with access modes
    #, {mode}.  A call to {status_get}@{unix_system}() will indicate how
    #, successful the operation is.  The possible return values are {ok},
    #, {busy}, {text_busy}, {bad_address}, {name_too_long}, {no_file},
    #, {not_directory}, {too_many_files}, {file_table_overflow},
    #, {no_memory}, {read_only}, {link_loop}, or {no_space}.
    #,
    #, This procedure is equivalent to the open(2) system call.



procedure pipe@unix_system
    takes
	unix_system unix_system
    returns unsigned, unsigned

    #: This procedure will invoke the unix pipe(2) system call and
    #, return two file descriptors that correspond to either end of
    #, the pipe.  The first file descriptor number is the read pipe
    #, number and the second file descriptor number is the write pipe
    #, number.  If any error occurs, 0xffffffff is returned for both
    #, file descriptor numbers.


procedure pipe_actual@unix_system
    takes
	unix_system unix_system
    returns_nothing
    external unix_system__pipe_actual

    #: This procedure will perform the actual unix pipe(2) system call.  The
    #, read file descriptor is obtained via {pipe_read_get}@{unix_system}()
    #, procedure call.  The write file descriptor is obtained via
    #, {pipe_write_get}@{unix_system}() procedure call.
    #,
    #, Note: This procedure should only be called from {pipe}@{unix_system}().



procedure pipe_read_get@unix_system
    takes
	unix_system unix_system
    returns unsigned
    external unix_system__pipe_read_get

    #: This procedure will return the read file descriptor for the last
    #, pipe created via a call to the {pipe_actual}@{unix_system}()
    #, procedure.
    #,
    #, Note: This procedure should only be called from {pipe}@{unix_system}().



procedure pipe_write_get@unix_system
    takes
	unix_system unix_system
    returns unsigned
    external unix_system__pipe_write_get

    #: This procedure will return the write file descriptor for the last
    #, pipe created via a call to the {pipe_actual}@{unix_system}()
    #, procedure.
    #,
    #, Note: This procedure should only be called from {pipe}@{unix_system}().



procedure print@unix_system
    takes
	unix_system unix_system
	out_stream out_stream
    returns_nothing

    #: This procedure will print {unix_system} to {out_stream}.


procedure read@unix_system
    takes
	unix_system unix_system
	file_descriptor_number unsigned
	memory memory
	offset unsigned
	amount unsigned
    returns unsigned
    external unix_system__read

    #: This procedure will attempt to read {amount} bytes of data
    #, from {file_descriptor_number} into {memory} starting at {offset}.
    #, The actual number of bytes read is returned.  A call to
    #, {status_get}@{unix_system}() will indicate how successful the operation
    #, is.  The possible return vaues are {ok}, {interrupt}, {try_again},
    #, {is_directory}, {bad_file}, {invalid}, or {bad_address}.
    #,
    #, This procedure is equivalent to the read(2) system call.



procedure resource_user_time_seconds_get@unix_system
    takes
	unix_system unix_system
    returns unsigned
    external unix_system__resource_user_time_seconds_get

    #: This procedure will return the number of user time seconds
    #, associated with {unix_system}.  This value is set via a call
    #, to either {resources_obtain}@{unix_system}() or via a call
    #, {wait}@{unix_system}().



procedure resource_user_time_microseconds_get@unix_system
    takes
	unix_system unix_system
    returns unsigned
    external unix_system__resource_user_time_microseconds_get

    #: This procedure will return the number of user time microseconds
    #, associated with {unix_system}.  This value is set via a call
    #, to either {resources_obtain}@{unix_system}() or via a call
    #, {wait}@{unix_system}().



procedure resource_system_time_seconds_get@unix_system
    takes
	unix_system unix_system
    returns unsigned
    external unix_system__resource_system_time_seconds_get

    #: This procedure will return the number of system time seconds
    #, associated with {unix_system}.  This value is set via a call
    #, to either {resources_obtain}@{unix_system}() or via a call
    #, {wait}@{unix_system}().



procedure resource_system_time_microseconds_get@unix_system
    takes
	unix_system unix_system
    returns unsigned
    external unix_system__resource_system_time_microseconds_get

    #: This procedure will return the number of system time microseconds
    #, associated with {unix_system}.  This value is set via a call
    #, to either {resources_obtain}@{unix_system}() or via a call
    #, {wait}@{unix_system}().



procedure resource_maximum_resident_set_size_get@unix_system
    takes
	unix_system unix_system
    returns unsigned
    external unix_system__resource_maximum_resident_size_get

    #: This procedure will return the maximum resident set size
    #, associated with {unix_system}.  This value is set via a call
    #, to either {resources_obtain}@{unix_system}() or via a call
    #, {wait}@{unix_system}().



procedure resource_maximum_shared_memory_size_get@unix_system
    takes
	unix_system unix_system
    returns unsigned
    external unix_system__resource_maximum_shared_memory_size_get

    #: This procedure will return the maximum shared memory size
    #, associated with {unix_system}.  This value is set via a call
    #, to either {resources_obtain}@{unix_system}() or via a call
    #, {wait}@{unix_system}().



procedure resource_maximum_unshared_data_size_get@unix_system
    takes
	unix_system unix_system
    returns unsigned
    external unix_system__resource_unshared_data_size_get

    #: This procedure will return the maximum unshared data size
    #, associated with {unix_system}.  This value is set via a call
    #, to either {resources_obtain}@{unix_system}() or via a call
    #, {wait}@{unix_system}().



procedure resource_maximum_unshared_stack_size_get@unix_system
    takes
	unix_system unix_system
    returns unsigned
    external unix_system__resource_maximum_unshared_stack_size_get

    #: This procedure will return the maximum unshared stack size
    #, associated with {unix_system}.  This value is set via a call
    #, to either {resources_obtain}@{unix_system}() or via a call
    #, {wait}@{unix_system}().



procedure resource_minor_page_faults_get@unix_system
    takes
	unix_system unix_system
    returns unsigned
    external unix_system__resource_minor_page_faults_get

    #: This procedure will return the number of minor page faults
    #, associated with {unix_system}.  This value is set via a call
    #, to either {resources_obtain}@{unix_system}() or via a call
    #, {wait}@{unix_system}().



procedure resource_major_page_faults_get@unix_system
    takes
	unix_system unix_system
    returns unsigned
    external unix_system__resource_major_page_faults_get

    #: This procedure will return the number of major page faults
    #, associated with {unix_system}.  This value is set via a call
    #, to either {resources_obtain}@{unix_system}() or via a call
    #, {wait}@{unix_system}().



procedure resource_swaps_get@unix_system
    takes
	unix_system unix_system
    returns unsigned
    external unix_system__resource_swaps_get

    #: This procedure will return the number of swaps
    #, associated with {unix_system}.  This value is set via a call
    #, to either {resources_obtain}@{unix_system}() or via a call
    #, {wait}@{unix_system}().



procedure resource_input_blocks_get@unix_system
    takes
	unix_system unix_system
    returns unsigned
    external unix_system__resource_input_blocks_get

    #: This procedure will return the number of input blocks
    #, associated with {unix_system}.  This value is set via a call
    #, to either {resources_obtain}@{unix_system}() or via a call
    #, {wait}@{unix_system}().



procedure resource_output_blocks_get@unix_system
    takes
	unix_system unix_system
    returns unsigned
    external unix_system__resource_output_blocks_get

    #: This procedure will return the number of output blocks
    #, associated with {unix_system}.  This value is set via a call
    #, to either {resources_obtain}@{unix_system}() or via a call
    #, {wait}@{unix_system}().



procedure resource_message_sends_get@unix_system
    takes
	unix_system unix_system
    returns unsigned
    external unix_system__resource_message_sends_get

    #: This procedure will return the number of message send
    #, associated with {unix_system}.  This value is set via a call
    #, to either {resources_obtain}@{unix_system}() or via a call
    #, {wait}@{unix_system}().



procedure resource_message_receives_get@unix_system
    takes
	unix_system unix_system
    returns unsigned
    external unix_system__resource_message_receives_get

    #: This procedure will return the number of message receives
    #, associated with {unix_system}.  This value is set via a call
    #, to either {resources_obtain}@{unix_system}() or via a call
    #, {wait}@{unix_system}().



procedure resource_signals_get@unix_system
    takes
	unix_system unix_system
    returns unsigned
    external unix_system__resource_signals_get

    #: This procedure will return the number of signals
    #, associated with {unix_system}.  This value is set via a call
    #, to either {resources_obtain}@{unix_system}() or via a call
    #, {wait}@{unix_system}().



procedure resource_voluntary_context_switches_get@unix_system
    takes
	unix_system unix_system
    returns unsigned
    external unix_system__resource_voluntary_context_switches_get

    #: This procedure will return the number of voluntary context switches
    #, associated with {unix_system}.  This value is set via a call
    #, to either {resources_obtain}@{unix_system}() or via a call
    #, {wait}@{unix_system}().



procedure resource_involuntary_context_switches_get@unix_system
    takes
	unix_system unix_system
    returns unsigned
    external unix_system__resource_involuntary_context_switches_get

    #: This procedure will return the number of involuntary context switches
    #, associated with {unix_system}.  This value is set via a call
    #, to either {resources_obtain}@{unix_system}() or via a call
    #, {wait}@{unix_system}().



procedure seek@unix_system
    takes
	unix_system unix_system
	file_descriptor_number unsigned
	offset unsigned
    returns unsigned
    external unix_system__seek

    #: This procedure will cause the I/O pointer for {file_descriptor_number}
    #, to be positioned to {offset}.  A call to {status_get}@{unix_system}()
    #, return an indication of how successful the operation is.  The
    #, possible return values are {ok}, {bad_file}, {illegal_seek}, or
    #, {invalid}.
    #,
    #, This command is equivalent to the lseek(2) command.



procedure set_socket_option@unix_system
    takes
	unix_system unix_system
	socket_number unsigned
	socket_options socket_options
	value unsigned
    returns_nothing
    external unix_system__set_socket_option

    #: This procedure will set the {socket_option} value for
    #, {socket_number} to {value}.



procedure select@unix_system
    takes
	unix_system unix_system
	read_file_set file_set
	write_file_set file_set
	exception_file_set file_set
	seconds unsigned
	microseconds unsigned
    returns unsigned
    external unix_system__select

    #: This procedure will wait for data to be ready for reading on
    #, {read_file_set}, data ready for writing on {write_file_set},
    #, some sort of problem to ready for {exception_file_set},
    #, or a timeout of {seconds} plus {micorseconds}.  A value of
    #, ??@{file_set} can be passed for any three of the file sets
    #, to indictate the empty set.  Any {file_set} objects that
    #, are not ??@{file_set} will be *modified* to indicate which
    #, file descriptors are ready for input or output or exception
    #, processing.  Specifying 0 as the value for both {seconds} and
    #, {microseconds} means that the select should *not* timeout.
    #, The number of bits set in all three {file_set} objects (that
    #, are not equal to ??@{file_set}) is returned.  Thus, a return
    #, value of 0 means that a timeout has occured.
    #,
    #, This is equivalent to the select(2) system call.



procedure status_get@unix_system
    takes
	unix_system unix_system
    returns unix_system_error_number
    external unix_system__status_get

    #: This procedure will return the success/fail status of the
    #, last unix system call.



#procedure status@unix_system
#    takes
#	file_descriptor_number unsigned
#	file_status file_status
#    returns_nothing
#    external unix_system__status
#
#    #: This procedure will obtain the file information pertaining to
#    #, {file_descriptor_number} and store the results into file_status.
#    #, This is equivalent to the fstat(2) system call.


procedure socket_stream_create@unix_system
    takes
	unix_system unix_system
    returns unsigned
    external unix_system__socket_stream_create

    #: This procedure will create and return a file descriptor number for
    #, use as a network TCP/IP stream.
    #,
    #, There is currently no interface for datagrams.
    #,
    #, The procedure is equivalent to a socket(2) system call.



procedure truncate@unix_system
    takes
	unix_system unix_system
	file_descriptor_number unsigned
	length unsigned
    returns_nothing
    external unix_system__truncate

    #: This procedure will truncate the file refered to by
    #, {file_descriptor_number} to no more than {length} bytes.
    #, This is equivalent to the ftruncate(2) system call.
    #,
    #, Eventually, there needs to be a version of this call
    #, that takes a 64-bit number.



procedure wait@unix_system
    takes
	unix_system unix_system
	process_number unsigned
	no_hang logical
	stopped_too logical
    returns unsigned
    external unix_system__wait

    #: This procedure will perform a unix wait4(2) system call.
    #, If {process_number} is 0, the procedure will wait until
    #, any child process exits/stops; in which case the process
    #, id of the child process that exited/stopped is returned.
    #, If {process_number} is non-zero, the procedure will wait for
    #, the specified child process to exit/stop.  If {no_hang}
    #, is {true}, this procedure will not block waiting for the child
    #, process exit/stop, instead it will return immediately with
    #, a value of 0xffffffff if specified child process is not
    #, exited/stopped.  If {stopped_too} is {true}, stopped processes
    #, are reported in addition to exited processes; otherwise, only
    #, exited processes are reported.  There are a number of
    #, {wait_*_get}@{unix_system} procedures for figuring out whether
    #, a process exited normally, via a signal, or is just stopped
    #, (i.e. {stopped_too} is {true}.)  Finally, the resource usage
    #, information for the exited/stopped process can be obatianed
    #, via the {resource_*_get}@{unix_system} procedures.



procedure wait_exited_get@unix_system
    takes
	unix_system unix_system
    returns logical
    external unix_system__wait_exited_get

    #: This procedure will return {true}@{logical} if the last call
    #, to {wait}@{unix_system}() resulted in a child process that
    #, exited normally; otherwise, {false} is returned.



procedure wait_exit_status_get@unix_system
    takes
	unix_system unix_system
    returns unsigned
    external unix_system__exit_status_get

    #: This procedure will return the least significant 8 bits of
    #, the return code for exiting process.  These 8 bits are only
    #, valid if {wait_exited_get}@{unix_system} returned {true}.



procedure wait_signaled_get@unix_system
    takes
	unix_system unix_system
    returns logical
    external unix_system__signaled_get

    #: This procedure will return {true}@{logical} if the last call
    #, to {wait}@{unix_system}() resulted in a child process that
    #, exited because of a signal; otherwise {false} is returned.



procedure wait_signal_get@unix_system
    takes
	unix_system unix_system
    returns unsigned
    external unix_system__signaled_get

    #: This procedure will return the signal value that caused the
    #, the last process to exit.  The signal value is only valid if
    #, {wait_signaled_get}@{unix_system} returned {true}.



procedure wait_stopped_get@unix_system
    takes
	unix_system unix_system
    returns logical
    external unix_system__stopped_get

    #: This procedure will return {true}@{logical} if the last call
    #, to {wait}@{unix_system}() resulted in a child process that
    #, exited because of a signal; otherwise {false} is returned.



procedure wait_stop_get@unix_system
    takes
	unix_system unix_system
    returns unsigned
    external unix_system__stopget

    #: This procedure will return the signal value that caused the
    #, the last process to stop.  The signal value is only valid if
    #, {wait_stopped_get}@{unix_system} returned {true}.



procedure write@unix_system
    takes
	unix_system unix_system
	file_descriptor_number unsigned
	memory memory
	offset unsigned
	amount unsigned
    returns unsigned
    external unix_system__write

    #: This procedure will attempt to write {amount} bytes of data
    #, from {memory} starting at {offset} to {file_descriptor_number}.
    #, The actual number of bytes written is returned.




#: Here are some trivial {open_flags} routines:

procedure set1@open_flags
    takes
	open_flags1 open_flags
    returns unsigned

    #: This procedure will return a mask with {open_flags1} set.


procedure set2@open_flags
    takes
	open_flags1 open_flags
	open_flags2 open_flags
    returns unsigned

    #: This procedure will return a mask with {open_flags1} and {open_flags2}
    #, set.


procedure set3@open_flags
    takes
	open_flags1 open_flags
	open_flags2 open_flags
	open_flags3 open_flags
    returns unsigned

    #: This procedure will return a mask with {open_flags1}, {open_flags2},
    #, and {open_flags3} set.


procedure set4@open_flags
    takes
	open_flags1 open_flags
	open_flags2 open_flags
	open_flags3 open_flags
	open_flags4 open_flags
    returns unsigned

    #: This procedure will return a mask with {open_flags1}, {open_flags2},
    #, {open_flags3}, and {open_flags4} set.