mirror of
https://codeberg.org/landley/toybox.git
synced 2026-01-26 14:13:25 +00:00
The fallback ftruncate() call was wrong, because posix_fallocate()
will never shrink a file, but ftruncate() will. Also, if that failed,
we didn't turn errno into a return code.
Also the fcntl() was wrong. In my defense, here's the documentation:
The position modes (fst_posmode) for the F_PREALLOCATE command indicate
how to use the offset field. The modes are as follows:
F_PEOFPOSMODE Allocate from the physical end of file. In this
case, fst_length indicates the number of newly
allocated bytes desired.
F_VOLPOSMODE Allocate from the volume offset.
I think the new version is right, though it's obviously a lot more
conservative than the real posix_fallocate(), but I don't think
it's possible to do better?
Also add tests for some of the prior failures.
Fixes #472.
9 lines
268 B
Bash
Executable File
9 lines
268 B
Bash
Executable File
#!/bin/bash
|
|
|
|
#testing "name" "command" "result" "infile" "stdin"
|
|
|
|
rm -f foo
|
|
testcmd 'simple' '-l 123 foo && stat -c %s foo' '123\n' '' ''
|
|
testcmd 'shorter' '-l 12 foo && stat -c %s foo' '123\n' '' ''
|
|
testcmd 'longer' '-o 200 -l 12 foo && stat -c %s foo' '212\n' '' ''
|