Outdated egg!
This is an egg for CHICKEN 4, the unsupported old release. You're almost certainly looking for the CHICKEN 5 version of this egg, if it exists.
If it does not exist, there may be equivalent functionality provided by another egg; have a look at the egg index. Otherwise, please consider porting this egg to the current version of CHICKEN.
posix-extras
Provides "the things that the posix unit forgot."
TOC »
API
Stat vector accessors
file-stat in Unit posix returns an untyped 13-element vector representing the stat information. These are its accessors.
- stat-inode sprocedure
Inode number of stat vector S.
- stat-permissions sprocedure
Permissions of stat vector S. You can test this value by performing bitwise operations on the result and the perm/... values from Unit posix.
For compatibility with file-permissions, this returns the entire mode field, which happens to include the file type. You can use stat-mode and stat-mode-type to get the file mode and type separately.
- stat-mode sprocedure
Like stat-permissions, but return only the file mode (permission) bits from the mode field.
(number->string (stat-mode s) 8) ; => "644"
- stat-mode-type sprocedure
Return only the file type bits from the mode field of stat vector S. You can then use equality operations with file type constants such as stat/ififo. However, it is probably better to use the wrappers stat-type and stat-fifo?, etc.
(= stat/ifdir (stat-mode-type (file-stat "~/.emacs.d"))) ; => #t
- stat-links sprocedure
Number of hard links of stat vector S.
- stat-owner sprocedure
Numeric user id of stat vector S.
- stat-group sprocedure
Numeric group id of stat vector S.
- stat-size sprocedure
File size in bytes of stat vector S.
- stat-access-time sprocedure
- stat-change-time sprocedure
- stat-modification-time sprocedure
Access, change or modification time of stat vector S in seconds since UNIX epoch.
- stat-device sprocedure
Device number of the device that stat vector S resides on. Compare with stat-device-number.
Not valid on Windows, where it returns an unspecified value.
- stat-device-number sprocedure
Device number of the block- or character- special file represented by stat vector S. The device number can be deconstructed with device-major and device-minor. For all other file types, the device number is 0.
Warning: Due to a limitation in Chicken, only 30 bits of the device number are recorded in the stat vector on 32-bit systems (this is raised to 32 bits on 64-bit systems; technically speaking, its foreign type is unsigned-int). Although 32-bit device numbers are most common, some platforms such as Linux may use 64-bit numbers. Therefore, the device number may be somewhat unreliable.
Not valid on Windows, where it returns an unspecified value.
- stat-block-size sprocedure
Returns the "optimal" block size for I/O on the file represented by stat vector S.
Not valid on Windows, where it returns an unspecified value.
- stat-blocks sprocedure
Number of blocks allocated for the file represented by stat vector S.
Not valid on Windows, where it returns an unspecified value.
Stat vector helpers
These convenience procedures correspond to the file-* procedures in Unit posix, but can be used on stat vectors.
- stat-type sprocedure
File type for stat vector S as a symbol, one of:
regular-file directory fifo socket symbolic-link character-device block-device
;; Example (stat-type (file-stat "~/.emacs.d")) ;=> directory
- stat-regular-file? sprocedure
Like regular-file? but for stat vectors.
- stat-symbolic-link? sprocedure
Like symbolic-link? but for stat vectors.
- stat-block-device? sprocedure
Like block-device? but for stat vectors.
- stat-character-device? sprocedure
Like character-device? but for stat vectors.
- stat-fifo? sprocedure
Like fifo? but for stat vectors.
- stat-socket? sprocedure
Like socket? but for stat vectors.
- stat-directory? sprocedure
Like directory? but for stat vectors.
(stat-directory? (file-stat "~/.emacs.d")) ; => #t
Stat mode constants
- stat/ifmtconstant
- stat/ififoconstant
- stat/ifchrconstant
- stat/ifdirconstant
- stat/ifblkconstant
- stat/ifregconstant
- stat/iflnkconstant
- stat/ifsockconstant
Constants used with stat-mode-type to get the type of file. Consult stat(2) for more information and note that, for example, stat/ifdir corresponds to S_IFDIR.
Symlink ownership and mode
- change-link-mode filename modeprocedure
Change the mode of symbolic link FILENAME to numeric MODE via the lchmod() C library function. This system call is only implemented on some platforms; it will raise an error otherwise.
- change-link-owner filename uid gidprocedure
Change the owner and group of symbolic link FILENAME to numeric UID and GID via the lchown() C library function. This system call is only implemented on some platforms; it will raise an error otherwise.
File times
- change-file-times filename atime mtimeprocedure
Change the access and modification times on filename to atime and mtime, respectively.
Note that atime and mtime must be within 32-bit range.
- file-access-time filenameprocedure
- set! (file-access-time FILE) SECONDSsetter
Gets or sets the access time on FILENAME.
On most platforms modification and access time must be set together, so this usually incurs a separate call to get the current modification time. For efficiency, use change-file-times when you want to set both.
Device special files
- create-special-file filename mode devnum #!optional minorprocedure
Create a special file node called FILENAME with numeric mode MODE. DEVNUM is the desired device number and is relevant for block and character devices only; a device number can be constructed with make-device-number. Device numbers created in this manner are restricted to 32 bits only.
If the optional MINOR argument is provided, then DEVNUM is taken as the major device number, and MINOR as the minor number. In this case, the resulting device number will be not be subject to the 32-bit restriction mentioned above.
- create-block-device filename major minor #!optional (mode 438)procedure
- create-character-device filename major minor #!optional (mode 438)procedure
Create a block or character device called FILENAME having major device number MAJOR and minor device number MINOR. The optional creation MODE may also be specified via perm/... bits or directly in octal, and defaults to #o666, subject to your current umask.
These are merely convenient aliases to create-special-file.
Device numbers
- device-major devnumprocedure
Extract and return the major number from the device number DEVNUM.
- device-minor devnumprocedure
Extract and return the minor number from the device number DEVNUM.
- make-device-number major minorprocedure
Create a single device number from the given device MAJOR and MINOR IDs.
Note: The resulting device number is capped at 32 bits even on platforms with 64-bit device IDs. You can still, however, create files with full-width device numbers with create-special-file and friends.
Pathnames
- resolve-pathname pprocedure
Resolve all ./, ../ and symbolic references in relative or absolute pathname string P. All components in the path must exist. Returns an absolute pathname string, or signals an error if (for example) a path component is missing.
Platform notes: Solaris is reported to return a relative pathname in some instances. Unimplemented on Windows and will signal an error.
Processes
- sleep secondsprocedure
Puts the process to sleep for seconds, which is an inexact number (that is, may include a fractional number of seconds). The sleep from Unit posix only supports whole seconds.
Returns either 0 if the time has completely elapsed, or the number of remaining seconds, if a signal occurred.
(sleep 1.4)
About this egg
Author
Alaric Snell-Pym wrote the original implementation for Ugarit, and Jim Ursetto eggified it, made it portable and added a lot of stuff. Maintained by Jim Ursetto.
Version history
- 0.1.5
- Use nanosleep instead of sleep+usleep
- 0.1.4
- Implement sub-second sleep
- 0.1.3
- Expand homedir path in resolve-pathname
- 0.1.2
- Add resolve-pathname
- 0.1.1
- Add change-file-times and file-access-time setter
- 0.1
- initial release
License
Copyright (c) 2012, Ursetto Consulting Inc. Copyright (c) 2008-2009, Warhead.org.uk Ltd All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the names of Warhead.org.uk Ltd, Snell Systems, Kitten Technologies, Ursetto Consulting Inc. nor the names of their contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.