📄 unit-posix.html
字号:
<html><head><title>CHICKEN User's Manual - Unit posix</title></head><body><p> </p><a name="unit-posix"></a><h1>Unit posix</h1><p>This unit provides services as used on many UNIX-like systems. Note that the following definitions are not all available on non-UNIX systems like Windows. See below for Windows specific notes.</p><p>This unit uses the <tt>regex</tt>, <tt>scheduler</tt>, <tt>extras</tt> and <tt>utils</tt> units.</p><p>All errors related to failing file-operations will signal a condition of kind <tt>(exn i/o file)</tt>.</p><a name="constants"></a><h2>Constants</h2><a name="file-control-commands"></a><h3>File-control Commands</h3><a name="fcntl-dupfd"></a><h4>fcntl/dupfd</h4><a name="fcntl-getfd"></a><h4>fcntl/getfd</h4><a name="fcntl-setfd"></a><h4>fcntl/setfd</h4><a name="fcntl-getfl"></a><h4>fcntl/getfl</h4><a name="fcntl-setfl"></a><h4>fcntl/setfl</h4><a name="standard-i-o-file-descriptors"></a><h3>Standard I/O file-descriptors</h3><a name="fileno-stdin"></a><h4>fileno/stdin</h4><a name="fileno-stdout"></a><h4>fileno/stdout</h4><a name="fileno-stderr"></a><h4>fileno/stderr</h4><a name="open-flags"></a><h3>Open flags</h3><a name="open-rdonly"></a><h4>open/rdonly</h4><a name="open-wronly"></a><h4>open/wronly</h4><a name="open-rdwr"></a><h4>open/rdwr</h4><a name="open-read"></a><h4>open/read</h4><a name="open-write"></a><h4>open/write</h4><a name="open-creat"></a><h4>open/creat</h4><a name="open-append"></a><h4>open/append</h4><a name="open-excl"></a><h4>open/excl</h4><a name="open-noctty"></a><h4>open/noctty</h4><a name="open-nonblock"></a><h4>open/nonblock</h4><a name="open-trunc"></a><h4>open/trunc</h4><a name="open-sync"></a><h4>open/sync</h4><a name="open-fsync"></a><h4>open/fsync</h4><a name="open-binary"></a><h4>open/binary</h4><a name="open-text"></a><h4>open/text</h4><a name="permission-bits"></a><h3>Permission bits</h3><a name="perm-irusr"></a><h4>perm/irusr</h4><a name="perm-iwusr"></a><h4>perm/iwusr</h4><a name="perm-ixusr"></a><h4>perm/ixusr</h4><a name="perm-irgrp"></a><h4>perm/irgrp</h4><a name="perm-iwgrp"></a><h4>perm/iwgrp</h4><a name="perm-ixgrp"></a><h4>perm/ixgrp</h4><a name="perm-iroth"></a><h4>perm/iroth</h4><a name="perm-iwoth"></a><h4>perm/iwoth</h4><a name="perm-ixoth"></a><h4>perm/ixoth</h4><a name="perm-irwxu"></a><h4>perm/irwxu</h4><a name="perm-irwxg"></a><h4>perm/irwxg</h4><a name="perm-irwxo"></a><h4>perm/irwxo</h4><a name="perm-isvtx"></a><h4>perm/isvtx</h4><a name="perm-isuid"></a><h4>perm/isuid</h4><a name="perm-isgid"></a><h4>perm/isgid</h4><a name="directories"></a><h2>Directories</h2><a name="change-directory"></a><h3>change-directory</h3><pre>[procedure] (change-directory NAME)</pre><p>Changes the current working directory to <tt>NAME</tt>.</p><a name="current-directory"></a><h3>current-directory</h3><pre>[procedure] (current-directory [DIR])</pre><p>Returns the name of the current working directory. If the optional argument <tt>DIR</tt> is given, then <tt>(current-directory DIR)</tt> is equivalent to <tt>(change-directory DIR)</tt>.</p><a name="create-directory"></a><h3>create-directory</h3><pre>[procedure] (create-directory NAME #!optional PARENTS?)</pre><p>Creates a directory with the pathname <tt>NAME</tt>. If the <tt>PARENTS?</tt> argument is given and not false, any nonextant parent directories are also created.</p><a name="delete-directory"></a><h3>delete-directory</h3><pre>[procedure] (delete-directory NAME)</pre><p>Deletes the directory with the pathname <tt>NAME</tt>. The directory has to be empty.</p><a name="directory"></a><h3>directory</h3><pre>[procedure] (directory [PATHNAME [SHOW-DOTFILES?]])</pre><p>Returns a list with all files that are contained in the directory with the name <tt>PATHNAME</tt> (which defaults to the value of <tt>(current-directory)</tt>). Files beginning with <tt>.</tt> are included only if <tt>SHOW-DOTFILES?</tt> is given and not <tt>#f</tt>.</p><a name="directory"></a><h3>directory?</h3><pre>[procedure] (directory? NAME)</pre><p>Returns <tt>#t</tt> if there exists a file with the name <tt>NAME</tt> and if that file is a directory, or <tt>#f</tt> otherwise.</p><a name="glob"></a><h3>glob</h3><pre>[procedure] (glob PATTERN1 ...)</pre><p>Returns a list of the pathnames of all existing files matching <tt>PATTERN1 ...</tt>, which should be strings containing the usual file-patterns (with <tt>*</tt> matching zero or more characters and <tt>?</tt> matching zero or one character). Bug: wildcard characters are only recognized in the rightmost portion of the pattern.</p><a name="canonical-path"></a><h3>canonical-path</h3><pre>[procedure] (canonical-path NAME)</pre><p>Returns a canonical path for <tt>NAME</tt>, which should be a string containing a path-or-filename. The string returned by <tt>canonical-path</tt> is OS dependent; it may be quoted and used in a shell on the calling machine. (Quoting is suggested as shell special characters, including space, are not escaped.) However, all path separators and prefixes are handled in an OS independent fashion. Any appearance of <tt>/</tt> below imply <tt>\\</tt> is also handled.</p><p>The prefix for <tt>NAME</tt> determines what path to prepend. If <tt>NAME</tt> begins with a <tt>"~/"</tt>, this prefix is stripped and the user's home directory is added. If beginning with <tt>/</tt> or a DRIVE-LETTER:\\ combination, no additional path is added. Otherwise, the current directory and separator are added. All relative path elements and duplicate separators are processed and removed. If <tt>NAME</tt> ends with a <tt>/</tt> or is empty, the appropriate slash is appended to the tail.</p><p>No directories or files are actually tested for existence; this procedure only canonicalises path syntax.</p><a name="set-root-directory"></a><h3>set-root-directory!</h3><pre>[procedure] (set-root-directory! STRING)</pre><p>Sets the root directory for the current process to the path given in <tt>STRING</tt> (using the <tt>chroot</tt> function). If the current process has no root permissions, the operation will fail.</p><a name="pipes"></a><h2>Pipes</h2><a name="call-with-input-pipe"></a><h3>call-with-input-pipe</h3><a name="call-with-output-pipe"></a><h3>call-with-output-pipe</h3><pre>[procedure] (call-with-input-pipe CMDLINE PROC [MODE])[procedure] (call-with-output-pipe CMDLINE PROC [MODE])</pre><p>Call <tt>PROC</tt> with a single argument: a input- or output port for a pipe connected to the subprocess named in <tt>CMDLINE</tt>. If <tt>PROC</tt> returns normally, the pipe is closed and any result values are returned.</p><a name="close-input-pipe"></a><h3>close-input-pipe</h3><a name="close-output-pipe"></a><h3>close-output-pipe</h3><pre>[procedure] (close-input-pipe PORT)[procedure] (close-output-pipe PORT)</pre><p>Closes the pipe given in <tt>PORT</tt> and waits until the connected subprocess finishes. The exit-status code of the invoked process is returned.</p><a name="create-pipe"></a><h3>create-pipe</h3><pre>[procedure] (create-pipe)</pre><p>The fundamental pipe-creation operator. Calls the C function <tt>pipe()</tt> and returns 2 values: the file-descriptors of the input- and output-ends of the pipe.</p><a name="open-input-pipe"></a><h3>open-input-pipe</h3><pre>[procedure] (open-input-pipe CMDLINE [MODE])</pre><p>Spawns a subprocess with the command-line string <tt>CMDLINE</tt> and returns a port, from which the output of the process can be read. If <tt>MODE</tt> is specified, it should be the keyword <tt>#:text</tt> (the default) or <tt>#:binary</tt>.</p><a name="open-output-pipe"></a><h3>open-output-pipe</h3><pre>[procedure] (open-output-pipe CMDLINE [MODE])</pre><p>Spawns a subprocess with the command-line string <tt>CMDLINE</tt> and returns a port. Anything written to that port is treated as the input for the process. If <tt>MODE</tt> is specified, it should be the keyword <tt>#:text</tt> (the default) or <tt>#:binary</tt>.</p><a name="pipe-buf"></a><h3>pipe/buf</h3><p>This variable contains the maximal number of bytes that can be written atomically into a pipe or FIFO.</p><a name="with-input-from-pipe"></a><h3>with-input-from-pipe</h3><a name="with-output-to-pipe"></a><h3>with-output-to-pipe</h3><pre>[procedure] (with-input-from-pipe CMDLINE THUNK [MODE])[procedure] (with-output-to-pipe CMDLINE THUNK [MODE])</pre><p>Temporarily set the value of <tt>current-input-port/current-output-port</tt> to a port for a pipe connected to the subprocess named in <tt>CMDLINE</tt> and call the procedure <tt>THUNK</tt> with no arguments. After <tt>THUNK</tt> returns normally the pipe is closed and the standard input-/output port is restored to its previous value and any result values are returned.</p><PRE>(with-output-to-pipe <B><FONT COLOR="#BC8F8F">"gs -dNOPAUSE -sDEVICE=jpeg -dBATCH -sOutputFile=signballs.jpg -g600x600 -q -"</FONT></B> (<B><FONT COLOR="#A020F0">lambda</FONT></B> () (print #<<EOF %!IOPSC-1993 %%Creator: HAYAKAWA Takashi<xxxxxxxx@xx.xxxxxx.xx.xx> /C/neg/d/mul/R/rlineto/E/exp/H{{cvx def}repeat}def/T/dup/g/gt/r/roll/J/ifelse 8 H/A/copy(z&v4QX&93r9AxYQOZomQalxS2w!!O&vMYa43d6r93rMYvx2dca!D&cjSnjSnjjS3o!v&6A X&55SAxM1CD7AjYxTTd62rmxCnTdSST0g&12wECST!&!J0g&D1!&xM0!J0g!l&544dC2Ac96ra!m&3A F&&vGoGSnCT0g&wDmlvGoS8wpn6wpS2wTCpS1Sd7ov7Uk7o4Qkdw!&Mvlx1S7oZES3w!J!J!Q&7185d Z&lx1CS9d9nE4!k&X&MY7!&1!J!x&jdnjdS3odS!N&mmx1C2wEc!G&150Nx4!n&2o!j&43r!U&0777d ]&2AY2A776ddT4oS3oSnMVC00VV0RRR45E42063rNz&v7UX&UOzF!F!J![&44ETCnVn!a&1CDN!Y&0M V1c&j2AYdjmMdjjd!o&1r!M){( )T 0 4 3 r put T(/)g{T(9)g{cvn}{cvi}J}{($)g[]J}J cvx}forall/moveto/p/floor/w/div/S/add 29 H[{[{]setgray fill}for Y}for showpage EOF ) ) )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -