M: unix (file-writer)
open-write <fd> init-fd <output-port> ;
+CONSTANT: secure-write-flags flags{ O_WRONLY O_CREAT O_TRUNC O_EXCL }
+
+: open-secure-write ( path -- fd )
+ secure-write-flags file-mode open-file ;
+
+M: unix (file-writer-secure)
+ open-secure-write <fd> init-fd <output-port> ;
+
CONSTANT: append-flags flags{ O_WRONLY O_APPEND O_CREAT }
: open-append ( path -- fd )
: open-write ( path -- win32-file )
GENERIC_WRITE CREATE_ALWAYS 0 open-file 0 >>ptr ;
+: open-secure-write ( path -- win32-file )
+ GENERIC_WRITE CREATE_NEW FILE_ATTRIBUTE_TEMPORARY open-file 0 >>ptr ;
<PRIVATE
M: windows (file-writer)
open-write <output-port> ;
+M: windows (file-writer-secure)
+ open-secure-write <output-port> ;
+
M: windows (file-appender)
open-append <output-port> ;
HOOK: (file-writer) io-backend ( path -- stream )
+HOOK: (file-writer-secure) io-backend ( path -- stream )
+
HOOK: (file-appender) io-backend ( path -- stream )
: <file-reader> ( path encoding -- stream )
: <file-writer> ( path encoding -- stream )
[ normalize-path (file-writer) { file-writer } declare ] dip <encoder> ; inline
+: <file-writer-secure> ( path encoding -- stream )
+ [ normalize-path (file-writer-secure) { file-writer } declare ] dip <encoder> ; inline
+
: <file-appender> ( path encoding -- stream )
[ normalize-path (file-appender) { file-writer } declare ] dip <encoder> ; inline
: with-file-writer ( path encoding quot -- )
[ <file-writer> ] dip with-output-stream ; inline
+: with-file-writer-secure ( path encoding quot -- )
+ [ <file-writer-secure> ] dip with-output-stream ; inline
+
: set-file-lines ( seq path encoding -- )
[ [ print ] each ] with-file-writer ;