diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2017-04-08 13:10:56 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2017-04-08 13:10:56 -0700 |
commit | 478ae133483a91b35028eca9666689669fe55015 (patch) | |
tree | 53ff027735fc2b9479bdc7d962b454ba636a065f | |
parent | 44638912c7353e46c5d2d9b6fe9362f662809f02 (diff) | |
download | txr-478ae133483a91b35028eca9666689669fe55015.tar.gz txr-478ae133483a91b35028eca9666689669fe55015.tar.bz2 txr-478ae133483a91b35028eca9666689669fe55015.zip |
New path slot in stat struct.
* ftw.c (ftw_callback): Pass path to stat_to_struct function.
* socket.c (path_s): Variable definition removed from here.
(sock_load_init): Do not intern path symbol here.
* sysif.c (path_s): Variable definition moved here.
(stat_to_struct): New parameter, path. Store its argument in
the path slot of the structure.
(stat_impl): New parameter, path. Pass argument to
stat_to_struct.
(statp, statl): Pass path down to stat_impl.
(statf): Pass nil down as path argument of stat_impl.
(sysif_init): Intern path symbol here.
Add path_s to the slot list in the make_struct_type
call which creates the stat structure type.
* sysif.h (path_s): Declared here now.
(stat_to_struct): Declaration updated.
* txr.1: Documented new slot of stat structure and
behavior of stat, lstat and fstat w.r.t. this slot.
-rw-r--r-- | ftw.c | 2 | ||||
-rw-r--r-- | socket.c | 4 | ||||
-rw-r--r-- | sysif.c | 19 | ||||
-rw-r--r-- | sysif.h | 4 | ||||
-rw-r--r-- | txr.1 | 26 |
5 files changed, 40 insertions, 15 deletions
@@ -61,7 +61,7 @@ static int ftw_callback(const char *c_path, const struct stat *c_sb, { val path = string_utf8(c_path); val type = num(c_type); - val sb = stat_to_struct(*c_sb); + val sb = stat_to_struct(*c_sb, path); val level = num(fb->level); val base = num(fb->base); val result; @@ -50,6 +50,7 @@ #include "args.h" #include "struct.h" #include "arith.h" +#include "sysif.h" #include "socket.h" #define MIN(A, B) ((A) < (B) ? (A) : (B)) @@ -76,7 +77,7 @@ struct dgram_stream { val sockaddr_in_s, sockaddr_in6_s, sockaddr_un_s, addrinfo_s; val flags_s, family_s, socktype_s, protocol_s, addr_s, canonname_s; -val port_s, flow_info_s, scope_id_s, path_s; +val port_s, flow_info_s, scope_id_s; static val ipv4_addr_to_num(struct in_addr *src) { @@ -1073,7 +1074,6 @@ void sock_load_init(void) port_s = intern(lit("port"), user_package); flow_info_s = intern(lit("flow-info"), user_package); scope_id_s = intern(lit("scope-id"), user_package); - path_s = intern(lit("path"), user_package); #ifdef HAVE_GETADDRINFO reg_fun(intern(lit("getaddrinfo"), user_package), func_n3o(getaddrinfo_wrap, 1)); @@ -92,7 +92,7 @@ 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; +val atime_s, mtime_s, ctime_s, path_s; #if HAVE_PWUID val passwd_s, gecos_s, dir_s, shell_s; @@ -654,7 +654,7 @@ static val stat_to_list(struct stat st) nao); } -val stat_to_struct(struct stat st) +val stat_to_struct(struct stat st, val path) { args_decl(args, ARGS_MIN); val strct = make_struct(stat_s, nil, args); @@ -676,13 +676,15 @@ val stat_to_struct(struct stat st) slotset(strct, atime_s, num(st.st_atime)); slotset(strct, mtime_s, num(st.st_mtime)); slotset(strct, ctime_s, num(st.st_ctime)); + if (path) + slotset(strct, path_s, path); return strct; } #endif static val stat_impl(val obj, int (*statfn)(val, struct stat *), - val name) + val name, val path) { #if HAVE_SYS_STAT struct stat st; @@ -693,7 +695,7 @@ static val stat_impl(val obj, int (*statfn)(val, struct stat *), name, obj, num(errno), string_utf8(strerror(errno)), nao); return if3(opt_compat && opt_compat <= 113, - stat_to_list(st), stat_to_struct(st)); + stat_to_list(st), stat_to_struct(st, path)); #else uw_throwf(file_error_s, lit("~a is not implemented"), name, nao); #endif @@ -701,17 +703,17 @@ static val stat_impl(val obj, int (*statfn)(val, struct stat *), val statp(val path) { - return stat_impl(path, w_stat, lit("stat")); + return stat_impl(path, w_stat, lit("stat"), path); } static val statl(val path) { - return stat_impl(path, w_lstat, lit("lstat")); + return stat_impl(path, w_lstat, lit("lstat"), path); } val statf(val stream) { - return stat_impl(stream, w_fstat, lit("fstat")); + return stat_impl(stream, w_fstat, lit("fstat"), nil); } #if HAVE_SYS_STAT @@ -1483,6 +1485,7 @@ void sysif_init(void) atime_s = intern(lit("atime"), user_package); mtime_s = intern(lit("mtime"), user_package); ctime_s = intern(lit("ctime"), user_package); + path_s = intern(lit("path"), user_package); #if HAVE_PWUID passwd_s = intern(lit("passwd"), user_package); gecos_s = intern(lit("gecos"), user_package); @@ -1506,7 +1509,7 @@ void sysif_init(void) make_struct_type(stat_s, nil, 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, nil, nil); + mtime_s, ctime_s, path_s, nao), nil, nil, nil, nil); #if HAVE_PWUID make_struct_type(passwd_s, nil, nil, list(name_s, passwd_s, uid_s, gid_s, @@ -31,7 +31,7 @@ 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; +extern val atime_s, mtime_s, ctime_s, path_s; #if !HAVE_FTRUNCATE typedef long off_t; @@ -52,7 +52,7 @@ val exec_wrap(val file, val args_opt); #endif #if HAVE_SYS_STAT struct stat; -val stat_to_struct(struct stat st); +val stat_to_struct(struct stat st, val path); #endif val statp(val path); val statf(val path); @@ -46646,7 +46646,7 @@ as a way of specifying a command to execute. .mets (defstruct stat nil .mets \ \ dev ino mod nlink uid gid .mets \ \ rdev size blksize blocks atime -.mets \ \ mtime ctime) +.mets \ \ mtime ctime path) .syne .desc The @@ -46657,13 +46657,24 @@ by the .codn lstat , and .code fstat -functions. The slots are the direct counterparts of the +functions. Except for +.codn path , +the slots are the direct counterparts of the members of POSIX C structure .codn "struct stat" . For instance the slot .code dev corresponds to .codn st_dev . +The +.code path +slot is set by the functions +.code stat +and +.codn lstat . +Its value is +.code nil +when the path is not available. .coNP Functions @, stat @ lstat and @ fstat .synb @@ -46710,6 +46721,17 @@ function can retrieve a file descriptor, otherwise an exception of type .code file-error is thrown. +The +.code path +slot of the returned structure +holds a copy of their +.meta path +argument value. +In the case of +.codn fstat , +this slot is +.codn nil . + .coNP Variables @, s-ifmt @, s-iflnk @, s-ifreg @, s-ifblk ... , @ s-ixoth .desc The following variables exist, having integer values. These are bitmasks |