aboutsummaryrefslogtreecommitdiff
path: root/jim-aio.c
diff options
context:
space:
mode:
authorSteve Bennett <steveb@workware.net.au>2021-07-15 14:15:08 +1000
committerSteve Bennett <steveb@workware.net.au>2022-04-14 11:18:01 +1000
commit81e1890c0f595c474cabcaa83f66882005336d93 (patch)
tree75e9fe03c05b9780c1a34039e508121bb6cfced6 /jim-aio.c
parent703ac20adb9daff423eea44f4af548f485a97254 (diff)
downloadjimtcl-81e1890c0f595c474cabcaa83f66882005336d93.zip
jimtcl-81e1890c0f595c474cabcaa83f66882005336d93.tar.gz
jimtcl-81e1890c0f595c474cabcaa83f66882005336d93.tar.bz2
aio: TIP 603 - Implement stat of an open file handle
Although the interface is different ('$handle stat' vs 'chan configure -stat') the behaviour is the same. Signed-off-by: Steve Bennett <steveb@workware.net.au>
Diffstat (limited to 'jim-aio.c')
-rw-r--r--jim-aio.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/jim-aio.c b/jim-aio.c
index 4b3237f..5769f78 100644
--- a/jim-aio.c
+++ b/jim-aio.c
@@ -121,6 +121,7 @@
/* no fdopen() with ANSIC, so can't support these */
#undef HAVE_PIPE
#undef HAVE_SOCKETPAIR
+#undef Jim_FileStat
#endif
#if defined(HAVE_SOCKETS) && !defined(JIM_BOOTSTRAP)
@@ -1426,6 +1427,20 @@ static int aio_cmd_onexception(Jim_Interp *interp, int argc, Jim_Obj *const *arg
}
#endif
+#if defined(jim_ext_file) && defined(Jim_FileStat)
+static int aio_cmd_stat(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
+{
+ jim_stat_t sb;
+ AioFile *af = Jim_CmdPrivData(interp);
+
+ if (Jim_FileStat(af->fd, &sb) == -1) {
+ JimAioSetError(interp, NULL);
+ return JIM_ERR;
+ }
+ return Jim_FileStoreStatData(interp, argc == 0 ? NULL : argv[0], &sb);
+}
+#endif
+
#if defined(JIM_SSL) && !defined(JIM_BOOTSTRAP)
static int aio_cmd_ssl(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
@@ -1803,6 +1818,15 @@ static const jim_subcmd_type aio_command_table[] = {
1,
/* Description: Sets buffering */
},
+#if defined(jim_ext_file) && defined(Jim_FileStat)
+ { "stat",
+ "?var?",
+ aio_cmd_stat,
+ 0,
+ 1,
+ /* Description: 'file stat' on the open file */
+ },
+#endif
#ifdef jim_ext_eventloop
{ "readable",
"?readable-script?",