summaryrefslogtreecommitdiffstats
path: root/sysif.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2020-02-04 23:25:16 -0800
committerKaz Kylheku <kaz@kylheku.com>2020-02-04 23:25:16 -0800
commitc554db7ce82378612673e33d905b29f2d820a1a5 (patch)
tree8d9bd08470b1d68004f1d2c0ecf749800cb1c8b1 /sysif.c
parent5601100718f5647f2cc317c504af8b2470bad5a1 (diff)
downloadtxr-c554db7ce82378612673e33d905b29f2d820a1a5.tar.gz
txr-c554db7ce82378612673e33d905b29f2d820a1a5.tar.bz2
txr-c554db7ce82378612673e33d905b29f2d820a1a5.zip
stat and fstat become equivalent.
* sysif.c (get_fd): Move this function higher in the file to avoid forward declarations. The do_fstatt code being moved into do_stat needs to call it. (do_stat): Provide stat and fstat functionality in one function. (do_fstat): Static function removed. (fstat_wrap): Call do_stat instead of do_fstat. * txr.1: Updated.
Diffstat (limited to 'sysif.c')
-rw-r--r--sysif.c63
1 files changed, 30 insertions, 33 deletions
diff --git a/sysif.c b/sysif.c
index 9bc81f75..def72149 100644
--- a/sysif.c
+++ b/sysif.c
@@ -301,13 +301,38 @@ static val mkdir_wrap(val path, val mode)
}
#endif
+#if HAVE_CHMOD || HAVE_CHOWN || HAVE_SYS_STAT || HAVE_FILE_STAMP_CHANGE
+static int get_fd(val stream, val self)
+{
+ val fd_in = if3(integerp(stream), stream, stream_get_prop(stream, fd_k));
+
+ if (stream && !fd_in)
+ uw_throwf(file_error_s,
+ lit("~a: stream ~s has no :fd property"),
+ self, stream, nao);
+
+ if (!stream)
+ uw_throwf(file_error_s,
+ lit("~a: ~s isn't a stream object"),
+ self, stream, nao);
+
+ return c_int(fd_in, self);
+}
+#endif
+
#if HAVE_SYS_STAT
static int do_stat(val wpath, struct stat *buf)
{
- char *path = utf8_dup_to(c_str(wpath));
- int res = stat(path, buf);
- free(path);
- return res;
+ if (stringp(wpath)) {
+ char *path = utf8_dup_to(c_str(wpath));
+ int res = stat(path, buf);
+ free(path);
+ return res;
+ } else {
+ val self = lit("stat");
+ int fd = get_fd(wpath, self);
+ return fstat(fd, buf);
+ }
}
#ifdef S_IFLNK
@@ -522,25 +547,6 @@ static val mkfifo_wrap(val path, val mode)
#endif
-#if HAVE_CHMOD || HAVE_CHOWN || HAVE_SYS_STAT || HAVE_FILE_STAMP_CHANGE
-static int get_fd(val stream, val self)
-{
- val fd_in = if3(integerp(stream), stream, stream_get_prop(stream, fd_k));
-
- if (stream && !fd_in)
- uw_throwf(file_error_s,
- lit("~a: stream ~s has no :fd property"),
- self, stream, nao);
-
- if (!stream)
- uw_throwf(file_error_s,
- lit("~a: ~s isn't a stream object"),
- self, stream, nao);
-
- return c_int(fd_in, self);
-}
-#endif
-
#if HAVE_CHMOD
#define CHM_O 4
@@ -1030,15 +1036,6 @@ static val exit_star_wrap(val status)
#endif
-#if HAVE_SYS_STAT
-static int do_fstat(val stream, struct stat *buf)
-{
- val self = lit("fstat");
- int fd = get_fd(stream, self);
- return fstat(fd, buf);
-}
-#endif
-
time_t c_time(val time)
{
return if3(convert(time_t, -1) > 0, c_unum(time), c_num(time));
@@ -1143,7 +1140,7 @@ static val lstat_wrap(val path)
val fstat_wrap(val stream)
{
- return stat_impl(stream, do_fstat, lit("fstat"), nil);
+ return stat_impl(stream, do_stat, lit("fstat"), nil);
}
#if HAVE_FILE_STAMP_CHANGE