diff options
-rw-r--r-- | lib.c | 4 | ||||
-rw-r--r-- | share/txr/stdlib/path-test.tl | 24 | ||||
-rw-r--r-- | stream.c | 16 | ||||
-rw-r--r-- | stream.h | 3 | ||||
-rw-r--r-- | sysif.c | 77 | ||||
-rw-r--r-- | sysif.h | 8 |
6 files changed, 95 insertions, 37 deletions
@@ -7643,6 +7643,8 @@ void init(const wchar_t *pn, mem_t *(*oom)(mem_t *, size_t), obj_init(); uw_init(); eval_init(); + hash_init(); + struct_init(); sysif_init(); arith_init(); rand_init(); @@ -7651,7 +7653,6 @@ void init(const wchar_t *pn, mem_t *(*oom)(mem_t *, size_t), sig_init(); #endif filter_init(); - hash_init(); regex_init(); gc_late_init(); parse_init(); @@ -7664,7 +7665,6 @@ void init(const wchar_t *pn, mem_t *(*oom)(mem_t *, size_t), glob_init(); #endif cadr_init(); - struct_init(); gc_state(gc_save); } diff --git a/share/txr/stdlib/path-test.tl b/share/txr/stdlib/path-test.tl index 1ca8d940..c7e825ed 100644 --- a/share/txr/stdlib/path-test.tl +++ b/share/txr/stdlib/path-test.tl @@ -7,8 +7,7 @@ (defun sys:path-test-mode (statfun path mask) (sys:path-test (s statfun path) - (let ((m (prop s :mode))) - (if (plusp (logand m mask)) t)))) + (plusp (logand s.mode mask)))) (defun path-exists-p (path) (sys:path-test (s stat path) t)) @@ -45,24 +44,23 @@ (defun path-mine-p (path) (sys:path-test (s stat path) - (let ((u (prop s :uid))) - (= u (geteuid))))) + (= s.uid (geteuid)))) (defun path-my-group-p (path) (sys:path-test (s stat path) - (let ((g (prop s :gid))) + (let ((g s.gid)) (or (= g (getegid)) (find g (getgroups)))))) (defun sys:path-access (path umask gmask omask) (sys:path-test (s stat path) - (let ((m (prop s :mode)) + (let ((m s.mode) (euid (geteuid))) (cond ((zerop euid) (or (zerop (logior umask s-ixusr)) (plusp (logand m (logior umask gmask omask))))) - ((= euid (prop s :uid)) (plusp (logand m umask))) - ((let ((g (prop s :gid))) + ((= euid s.uid) (plusp (logand m umask))) + ((let ((g s.gid)) (or (= g (getegid)) (find g (getgroups)))) (plusp (logand m gmask))) @@ -81,9 +79,7 @@ (defun path-newer (path-0 path-1) (sys:path-examine (s0 stat path-0) (sys:path-examine (s1 stat path-1) - (and s0 (or (not s1) - (> (prop s0 :mtime) - (prop s1 :mtime))))))) + (and s0 (or (not s1) (> s0.mtime s1.mtime)))))) (defun path-older (path-0 path-1) (path-newer path-1 path-0)) @@ -92,7 +88,5 @@ (sys:path-examine (s0 stat path-0) (sys:path-examine (s1 stat path-1) (and s0 s1 - (eql (prop s0 :dev) - (prop s1 :dev)) - (eql (prop s0 :ino) - (prop s1 :ino)))))) + (eql s0.dev s1.dev) + (eql s0.ino s1.ino))))) @@ -64,9 +64,6 @@ val stdin_s, stdout_s, stddebug_s, stderr_s, stdnull_s; -val dev_k, ino_k, mode_k, nlink_k, uid_k; -val gid_k, rdev_k, size_k, blksize_k, blocks_k; -val atime_k, mtime_k, ctime_k; val from_start_k, from_current_k, from_end_k; val real_time_k, name_k, fd_k; val format_s; @@ -3213,19 +3210,6 @@ void stream_init(void) detect_format_string(); - dev_k = intern(lit("dev"), keyword_package); - ino_k = intern(lit("ino"), keyword_package); - mode_k = intern(lit("mode"), keyword_package); - nlink_k = intern(lit("nlink"), keyword_package); - uid_k = intern(lit("uid"), keyword_package); - gid_k = intern(lit("gid"), keyword_package); - rdev_k = intern(lit("rdev"), keyword_package); - size_k = intern(lit("size"), keyword_package); - blksize_k = intern(lit("blksize"), keyword_package); - blocks_k = intern(lit("blocks"), keyword_package); - atime_k = intern(lit("atime"), keyword_package); - mtime_k = intern(lit("mtime"), keyword_package); - ctime_k = intern(lit("ctime"), keyword_package); from_start_k = intern(lit("from-start"), keyword_package); from_current_k = intern(lit("from-current"), keyword_package); from_end_k = intern(lit("from-end"), keyword_package); @@ -83,9 +83,6 @@ struct strm_ops { #define std_null (deref(lookup_var_l(nil, stdnull_s))) loc lookup_var_l(val env, val sym); -extern val dev_k, ino_k, mode_k, nlink_k, uid_k; -extern val gid_k, rdev_k, size_k, blksize_k, blocks_k; -extern val atime_k, mtime_k, ctime_k; extern val from_start_k, from_current_k, from_end_k; extern val real_time_k, name_k, fd_k; extern val format_s; @@ -24,6 +24,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include <stddef.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -55,6 +56,10 @@ #if HAVE_POLL #include <poll.h> #endif +#if HAVE_PWUID +#include <pwd.h> +#endif +#include ALLOCA_H #include "lib.h" #include "stream.h" #include "hash.h" @@ -63,8 +68,19 @@ #include "unwind.h" #include "gc.h" #include "eval.h" +#include "args.h" +#include "struct.h" +#include "txr.h" #include "sysif.h" +val stat_s; +val dev_k, ino_k, mode_k, nlink_k, uid_k; +val gid_k, rdev_k, size_k, blksize_k, blocks_k; +val atime_k, mtime_k, ctime_k; +val dev_s, ino_s, mode_s, nlink_s, uid_s; +val gid_s, rdev_s, size_s, blksize_s, blocks_s; +val atime_s, mtime_s, ctime_s; + static val errno_wrap(val newval) { val oldval = num(errno); @@ -578,6 +594,31 @@ static val stat_to_list(struct stat st) nao); } +static val stat_to_struct(struct stat st) +{ + args_decl(args, ARGS_MIN); + val strct = make_struct(stat_s, nil, args); + slotset(strct, dev_s, num(st.st_dev)); + slotset(strct, ino_s, num(st.st_ino)); + slotset(strct, mode_s, num(st.st_mode)); + slotset(strct, nlink_s, num(st.st_nlink)); + slotset(strct, uid_s, num(st.st_uid)); + slotset(strct, gid_s, num(st.st_gid)); + slotset(strct, rdev_s, num(st.st_rdev)); + slotset(strct, size_s, num(st.st_size)); +#if !HAVE_WINDOWS_H + slotset(strct, blksize_s, num(st.st_blksize)); + slotset(strct, blocks_s, num(st.st_blocks)); +#else + slotset(strct, blksize_s, zero); + slotset(strct, blocks_s, zero); +#endif + slotset(strct, atime_s, num(st.st_atime)); + slotset(strct, mtime_s, num(st.st_mtime)); + slotset(strct, ctime_s, num(st.st_ctime)); + + return strct; +} #endif static val stat_impl(val obj, int (*statfn)(val, struct stat *), @@ -591,7 +632,8 @@ static val stat_impl(val obj, int (*statfn)(val, struct stat *), uw_throwf(file_error_s, lit("unable to ~a ~a: ~a/~s"), name, obj, num(errno), string_utf8(strerror(errno)), nao); - return stat_to_list(st); + return if3(opt_compat && opt_compat <= 113, + stat_to_list(st), stat_to_struct(st)); #else uw_throwf(file_error_s, lit("~a is not implemented"), name, nao); #endif @@ -810,6 +852,39 @@ static val setegid_wrap(val nval) void sysif_init(void) { + stat_s = intern(lit("stat"), user_package); + dev_k = intern(lit("dev"), keyword_package); + ino_k = intern(lit("ino"), keyword_package); + mode_k = intern(lit("mode"), keyword_package); + nlink_k = intern(lit("nlink"), keyword_package); + uid_k = intern(lit("uid"), keyword_package); + gid_k = intern(lit("gid"), keyword_package); + rdev_k = intern(lit("rdev"), keyword_package); + size_k = intern(lit("size"), keyword_package); + blksize_k = intern(lit("blksize"), keyword_package); + blocks_k = intern(lit("blocks"), keyword_package); + atime_k = intern(lit("atime"), keyword_package); + mtime_k = intern(lit("mtime"), keyword_package); + ctime_k = intern(lit("ctime"), keyword_package); + dev_s = intern(lit("dev"), user_package); + ino_s = intern(lit("ino"), user_package); + mode_s = intern(lit("mode"), user_package); + nlink_s = intern(lit("nlink"), user_package); + uid_s = intern(lit("uid"), user_package); + gid_s = intern(lit("gid"), user_package); + rdev_s = intern(lit("rdev"), user_package); + size_s = intern(lit("size"), user_package); + blksize_s = intern(lit("blksize"), user_package); + blocks_s = intern(lit("blocks"), user_package); + atime_s = intern(lit("atime"), user_package); + mtime_s = intern(lit("mtime"), user_package); + ctime_s = intern(lit("ctime"), user_package); + + make_struct_type(stat_s, nil, + list(dev_s, ino_s, mode_s, nlink_s, uid_s, gid_s, + rdev_s, size_s, blksize_s, blocks_s, atime_s, + mtime_s, ctime_s, nao), nil, nil); + reg_fun(intern(lit("errno"), user_package), func_n1o(errno_wrap, 0)); reg_fun(intern(lit("exit"), user_package), func_n1(exit_wrap)); reg_fun(intern(lit("abort"), user_package), func_n0(abort_wrap)); @@ -24,4 +24,12 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +extern val stat_s; +extern val dev_k, ino_k, mode_k, nlink_k, uid_k; +extern val gid_k, rdev_k, size_k, blksize_k, blocks_k; +extern val atime_k, mtime_k, ctime_k; +extern val dev_s, ino_s, mode_s, nlink_s, uid_s; +extern val gid_s, rdev_s, size_s, blksize_s, blocks_s; +extern val atime_s, mtime_s, ctime_s; + void sysif_init(void); |