You are looking at historical revision 28399 of this page. It may differ significantly from its current revision.
Provides "the things that the posix unit forgot."
Stat vector accessors
file-stat in Unit posix returns an untyped 13-element vector representing the stat information. These are its accessors.[procedure] (stat-inode s)
Inode number of stat vector S.[procedure] (stat-permissions s)
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.[procedure] (stat-mode s)
Like stat-permissions, but return only the file mode (permission) bits from the mode field.
(number->string (stat-mode s) 8) ; => "644"[procedure] (stat-mode-type s)
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[procedure] (stat-links s)
Number of hard links of stat vector S.[procedure] (stat-owner s)
Numeric user id of stat vector S.[procedure] (stat-group s)
Numeric group id of stat vector S.[procedure] (stat-size s)
File size in bytes of stat vector S.[procedure] (stat-access-time s)
[procedure] (stat-change-time s)
[procedure] (stat-modification-time s)
Access, change or modification time of stat vector S in seconds since UNIX epoch.[procedure] (stat-device s)
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.[procedure] (stat-device-number s)
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.[procedure] (stat-block-size s)
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.[procedure] (stat-blocks s)
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.[procedure] (stat-type s)
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[procedure] (stat-regular-file? s)
Like regular-file? but for stat vectors.[procedure] (stat-symbolic-link? s)
Like symbolic-link? but for stat vectors.[procedure] (stat-block-device? s)
Like block-device? but for stat vectors.[procedure] (stat-character-device? s)
Like character-device? but for stat vectors.[procedure] (stat-fifo? s)
Like fifo? but for stat vectors.[procedure] (stat-socket? s)
Like socket? but for stat vectors.[procedure] (stat-directory? s)
Like directory? but for stat vectors.
(stat-directory? (file-stat "~/.emacs.d")) ; => #t
Stat mode constants[constant] stat/ifmt
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[procedure] (change-link-mode filename mode)
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.[procedure] (change-link-owner filename uid gid)
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[procedure] (change-file-times filename atime mtime)
Change the access and modification times on filename to atime and mtime, respectively.
Note that atime and mtime must be within 32-bit range.[procedure] (file-access-time filename)
[setter] (set! (file-access-time FILE) SECONDS)
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[procedure] (create-special-file filename mode devnum #!optional minor)
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.[procedure] (create-block-device filename major minor #!optional (mode #o666))
[procedure] (create-character-device filename major minor #!optional (mode #o666))
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[procedure] (device-major devnum)
Extract and return the major number from the device number DEVNUM.[procedure] (device-minor devnum)
Extract and return the minor number from the device number DEVNUM.[procedure] (make-device-number major minor)
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[procedure] (resolve-pathname p)
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[procedure] (sleep seconds)
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.
About this egg
- Implement sub-second sleep
- Expand homedir path in resolve-pathname
- Add resolve-pathname
- Add change-file-times and file-access-time setter
- initial release
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.