From 022ea8cfd80b97221abfbf2ba09110c0ecef3dc6 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Tue, 4 Feb 2020 23:30:57 -0800 Subject: fstat: turn into true alias. We can get rid of fstat_wrap entirely and make the lstat and fstat function bindings point to the same function. * parser.c (load_rcfile): Call stat_wrap instead of fstat_wrap. * sysif.c (stat_wrap): Static function becomes extern. Useless forward declaration removed. (fstat_wrap): Static function removed. (sysif_init): Bind fstat and lstat to the same function object. * sysif.h (fstat_wrap): Declaration removed. (stat_wrap): Declaration added. --- parser.c | 2 +- sysif.c | 16 ++++++---------- sysif.h | 2 +- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/parser.c b/parser.c index 7c40b5d7..6f21f62e 100644 --- a/parser.c +++ b/parser.c @@ -798,7 +798,7 @@ static void load_rcfile(val name) open_txr_file(name, &lisp_p, &resolved_name, &stream); if (stream) { - if (!funcall1(path_private_to_me_p, fstat_wrap(stream))) { + if (!funcall1(path_private_to_me_p, stat_wrap(stream))) { format(std_output, lit("** possible security problem: ~a is writable to others\n"), name, nao); diff --git a/sysif.c b/sysif.c index def72149..d117729b 100644 --- a/sysif.c +++ b/sysif.c @@ -556,8 +556,6 @@ static val mkfifo_wrap(val path, val mode) enum chm_state { chm_who, chm_perm, chm_nxtop, chm_comma }; enum chm_op { chm_add, chm_sub, chm_set }; -static val stat_wrap(val path); - static val chmod_wrap(val target, val mode) { val self = lit("chmod"); @@ -1128,7 +1126,7 @@ static val stat_impl(val obj, int (*statfn)(val, struct stat *), #endif } -static val stat_wrap(val path) +val stat_wrap(val path) { return stat_impl(path, do_stat, lit("stat"), path); } @@ -1138,11 +1136,6 @@ static val lstat_wrap(val path) return stat_impl(path, do_lstat, lit("lstat"), path); } -val fstat_wrap(val stream) -{ - return stat_impl(stream, do_stat, lit("fstat"), nil); -} - #if HAVE_FILE_STAMP_CHANGE #if HAVE_FUTIMENS @@ -2372,9 +2365,12 @@ void sysif_init(void) reg_fun(intern(lit("lutimes"), user_package), func_n5(wrap_lutimes)); #endif - reg_fun(intern(lit("stat"), user_package), func_n1(stat_wrap)); + { + val fn = func_n1(stat_wrap); + reg_fun(intern(lit("stat"), user_package), fn); + reg_fun(intern(lit("fstat"), user_package), fn); + } reg_fun(intern(lit("lstat"), user_package), func_n1(lstat_wrap)); - reg_fun(intern(lit("fstat"), user_package), func_n1(fstat_wrap)); #if HAVE_SYS_STAT #ifndef S_IFSOCK diff --git a/sysif.h b/sysif.h index f10d2da3..c2a650c0 100644 --- a/sysif.h +++ b/sysif.h @@ -49,7 +49,7 @@ val num_time(time_t time); struct stat; val stat_to_struct(struct stat st, val path); #endif -val fstat_wrap(val path); +val stat_wrap(val path); val stdio_ftell(FILE *); int stdio_fseek(FILE *, val, int whence); #if HAVE_GETEUID -- cgit v1.2.3