diff options
author | c-blake <c-blake@users.noreply.github.com> | 2023-02-15 11:41:28 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-15 17:41:28 +0100 |
commit | c91ef1a09f3284315e9e66c32532f5a8e3ba9297 (patch) | |
tree | ee11511a58e78e17085448ffb508f6eeaf199fe3 /tests/stdlib/tmemfiles2.nim | |
parent | e24d0e5faf1f6f2906262457007261e2358f1e5d (diff) | |
download | Nim-c91ef1a09f3284315e9e66c32532f5a8e3ba9297.tar.gz |
Fix `closeHandle` bug, add `setFileSize`, make `resize` work on Windows (#21375)
* Add general purpose `setFileSize` (unexported for now). Use to simplify `memfiles.open` as well as make robust (via hard allocation, not merely `ftruncate` address space allocation) on systems with `posix_fallocate`. As part of this, fix a bad `closeHandle` return check bug on Windows and add `MemFile.resize` for Windows now that setFileSize makes that easier. * Adapt existing test to exercise newly portable `MemFile.resize`. * Since Apple has never provided `posix_fallocate`, provide a fallback. This is presently written in terms of `ftruncate`, but it can be improved to use `F_PREALLOCATE` instead, as mentioned in a comment.
Diffstat (limited to 'tests/stdlib/tmemfiles2.nim')
-rw-r--r-- | tests/stdlib/tmemfiles2.nim | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/tests/stdlib/tmemfiles2.nim b/tests/stdlib/tmemfiles2.nim index 6fee3c1ae..c79f85ebf 100644 --- a/tests/stdlib/tmemfiles2.nim +++ b/tests/stdlib/tmemfiles2.nim @@ -15,8 +15,9 @@ var if fileExists(fn): removeFile(fn) -# Create a new file, data all zeros -mm = memfiles.open(fn, mode = fmReadWrite, newFileSize = 20) +# Create a new file, data all zeros, starting at size 10 +mm = memfiles.open(fn, mode = fmReadWrite, newFileSize = 10, allowRemap=true) +mm.resize 20 # resize up to 20 mm.close() # read, change |