[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Chicken-users] S_IFMT constants
From: |
Alaric Snell-Pym |
Subject: |
[Chicken-users] S_IFMT constants |
Date: |
Thu, 15 Jan 2009 10:03:16 +0000 |
Hello there,
The posix unit supplies a useful set of constants for file permission
bits. But, the file-stat procedure returns a mode bit that contains
some combination of those ORed together, *plus* some extra bits to
specify the file type.
In the NetBSD manpages for stat(2), it looks like this, for example:
#define S_IFMT 0170000 /* type of file */
#define S_IFIFO 0010000 /* named pipe (fifo) */
#define S_IFCHR 0020000 /* character special */
#define S_IFDIR 0040000 /* directory */
#define S_IFBLK 0060000 /* block special */
#define S_IFREG 0100000 /* regular */
#define S_IFLNK 0120000 /* symbolic link */
#define S_IFSOCK 0140000 /* socket */
#define S_IFWHT 0160000 /* whiteout */
#define S_ISUID 0004000 /* set user id on execution */
#define S_ISGID 0002000 /* set group id on execution */
#define S_ISVTX 0001000 /* save swapped text even after use */
#define S_IRUSR 0000400 /* read permission, owner */
#define S_IWUSR 0000200 /* write permission, owner */
#define S_IXUSR 0000100 /* execute/search permission, owner */
#define S_IRGRP 0000040 /* read permission, group */
#define S_IWGRP 0000020 /* write permission, group */
#define S_IXGRP 0000010 /* execute/search permission, group */
#define S_IROTH 0000004 /* read permission, other */
#define S_IWOTH 0000002 /* write permission, other */
#define S_IXOTH 0000001 /* execute/search permission, other */
Chicken doesn't seem to have a way to portably get the values of
S_IFMT and friends, unless I'm missing something; there are procedures
like stat-socket?, but each does its own stat syscall, and I want to
do a single state on a file then branch on the file's type, while also
using other elements of the stat result (this is for my backup system,
Ugarit).
So I propose the following be added to posixunix.scm (and posixwin?):
(define-foreign-variable _s_ifmt int "S_IFMT")
(define stat/ifmt _s_ifmt)
(define-foreign-variable _s_ififo int "S_IFIFO")
(define stat/ififo _s_ififo)
(define-foreign-variable _s_ifchr int "S_IFCHR")
(define stat/ifchr _s_ifchr)
(define-foreign-variable _s_ifdir int "S_IFDIR")
(define stat/ifdir _s_ifdir)
(define-foreign-variable _s_ifblk int "S_IFBLK")
(define stat/ifblk _s_ifblk)
(define-foreign-variable _s_ifreg int "S_IFREG")
(define stat/ifreg _s_ifreg)
(define-foreign-variable _s_iflnk int "S_IFLNK")
(define stat/iflnk _s_iflnk)
(define-foreign-variable _s_ifsock int "S_IFSOCK")
(define stat/ifsock _s_ifsock)
(as S_IFWHT isn't portable, I'm skipping it)
ABS
--
Alaric Snell-Pym
Work: http://www.snell-systems.co.uk/
Play: http://www.snell-pym.org.uk/alaric/
Blog: http://www.snell-pym.org.uk/?author=4
- [Chicken-users] S_IFMT constants,
Alaric Snell-Pym <=