Truncate a file: Difference between revisions

add Standard ML
(Added Rust to this problem)
(add Standard ML)
Line 1,177:
# truncate "file.ext" to 1234 bytes
truncate("file.ext", 1234);</lang>
 
=={{header|Standard ML}}==
{{works with|Unix}}
This function behaves similarly to the ''truncate'' tool from the [[GNU]] coreutils: If the file does not exist yet, or the target length is larger than the current file size, the extended area appears zero-filled (usually resulting in a sparse file).
<lang sml>local
open Posix.FileSys
val perm = S.flags [S.irusr, S.iwusr, S.irgrp, S.iwgrp, S.iroth, S.iwoth]
in
fun truncate (path, len) =
let
val fd = createf (path, O_WRONLY, O.noctty, perm)
in
ftruncate (fd, len); Posix.IO.close fd
end
end</lang>
 
=={{header|Tcl}}==
559

edits