summaryrefslogtreecommitdiffstats
path: root/stream.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2023-09-23 00:19:54 -0700
committerKaz Kylheku <kaz@kylheku.com>2023-09-23 00:19:54 -0700
commit08e99752e3d29f69dd661aaba3b7809a117264d9 (patch)
tree5494c258d64f71e094ac2969bcef3e06bf88eaf6 /stream.c
parent2df419cdb5295b405a98d24f0226cb42bfbf37d2 (diff)
downloadtxr-08e99752e3d29f69dd661aaba3b7809a117264d9.tar.gz
txr-08e99752e3d29f69dd661aaba3b7809a117264d9.tar.bz2
txr-08e99752e3d29f69dd661aaba3b7809a117264d9.zip
New T mode for open-file.
The T mode uses O_TMPFILE to create an unlinkd temporary file. * stream.h (struct stdio_mode): New flag, tmpfile. (stdio_mode_init_blank, stdio_mode_init_r, stdio_mode_init_rpb): Updated to cover new bitfield member. * stream.c (w_open_mode): If tmpfile flag is on, add O_TMPFILE. (do_parse_mode): Recognize "T" mode selector and set all appropriate mode bits. If we are not on a platform that has O_TMPFILE, set the maformed flag. * txr.1: Documented.
Diffstat (limited to 'stream.c')
-rw-r--r--stream.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/stream.c b/stream.c
index 6e733735..5ea9330f 100644
--- a/stream.c
+++ b/stream.c
@@ -1132,6 +1132,9 @@ int w_open_mode(const wchar_t *wname, const struct stdio_mode m)
if3(m.create, if3(!m.notrunc, O_TRUNC, 0) | O_CREAT, 0) |
if3(m.append, O_APPEND, 0) |
if3(m.excl, O_EXCL, 0) |
+#if O_TMPFILE
+ if3(m.tmpfile, O_TMPFILE, 0) |
+#endif
if3(m.nonblock, O_NONBLOCK, 0));
char *stkname = coerce(char *, alloca(nsiz));
int fd;
@@ -1464,6 +1467,16 @@ static struct stdio_mode do_parse_mode(val mode_str, struct stdio_mode m_dfl,
m.create = 1;
m.notrunc = 1;
break;
+ case 'T':
+ ms++;
+#if O_TMPFILE
+ m.read = 1;
+ m.write = 1;
+ m.tmpfile = 1;
+#else
+ m.malformed = 1;
+#endif
+ break;
default:
break;
}