summaryrefslogtreecommitdiffstats
path: root/share/txr/stdlib/path-test.tl
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2019-11-03 21:57:42 -0800
committerKaz Kylheku <kaz@kylheku.com>2019-11-03 21:57:42 -0800
commit4a70ba5b24e9b6ce14c5ed3875df367f6a0ee4b7 (patch)
treef6500e4c62afdeec7e47864c454a9ad7dde2b81b /share/txr/stdlib/path-test.tl
parent5135b7a124340e50bd376d22dce41fd0d20852fe (diff)
downloadtxr-4a70ba5b24e9b6ce14c5ed3875df367f6a0ee4b7.tar.gz
txr-4a70ba5b24e9b6ce14c5ed3875df367f6a0ee4b7.tar.bz2
txr-4a70ba5b24e9b6ce14c5ed3875df367f6a0ee4b7.zip
path-tests: fix incorrect type tests.
Reported by user vapnik spaknik, who discovered the path-symlink-p function yielding a false positive on a regular file. The functions in this group are bit testing rather than extracting a bitfield and checking the enumerated value. * share/txr/stdlib/path-test.tl (sys:path-test-type): New function. (path-file-p, path-dir-p, path-symlink-p, path-blkdev-p, path-chrdev-p, path-sock-p, path-pipe-p): Use sys:path-test-type rather than sys:path-test-mode.
Diffstat (limited to 'share/txr/stdlib/path-test.tl')
-rw-r--r--share/txr/stdlib/path-test.tl18
1 files changed, 11 insertions, 7 deletions
diff --git a/share/txr/stdlib/path-test.tl b/share/txr/stdlib/path-test.tl
index 4e26f1f8..635510a9 100644
--- a/share/txr/stdlib/path-test.tl
+++ b/share/txr/stdlib/path-test.tl
@@ -32,6 +32,10 @@
^[sys:do-path-test ,statfun ,path
(lambda (,sym) (when ,sym ,*body))]))
+(defun sys:path-test-type (statfun path code)
+ (sys:path-test (s statfun path)
+ (eql (logand s.mode s-ifmt) code)))
+
(defun sys:path-test-mode (statfun path mask)
(sys:path-test (s statfun path)
(plusp (logand s.mode mask))))
@@ -40,25 +44,25 @@
(sys:path-test (s stat path) t))
(defun path-file-p (path)
- [sys:path-test-mode stat path s-ifreg])
+ [sys:path-test-type stat path s-ifreg])
(defun path-dir-p (path)
- [sys:path-test-mode stat path s-ifdir])
+ [sys:path-test-type stat path s-ifdir])
(defun path-symlink-p (path)
- [sys:path-test-mode lstat path s-iflnk])
+ [sys:path-test-type lstat path s-iflnk])
(defun path-blkdev-p (path)
- [sys:path-test-mode stat path s-ifblk])
+ [sys:path-test-type stat path s-ifblk])
(defun path-chrdev-p (path)
- [sys:path-test-mode stat path s-ifchr])
+ [sys:path-test-type stat path s-ifchr])
(defun path-sock-p (path)
- [sys:path-test-mode stat path s-ifsock])
+ [sys:path-test-type stat path s-ifsock])
(defun path-pipe-p (path)
- [sys:path-test-mode stat path s-ififo])
+ [sys:path-test-type stat path s-ififo])
(defun path-setgid-p (path)
[sys:path-test-mode stat path s-isgid])