mirror of
https://github.com/amadvance/snapraid.git
synced 2026-10-26 19:01:57 -04:00
Uses the portable to Windows ftruncate().
This commit is contained in:
parent
c8df7d4a07
commit
42105f90b2
1 changed files with 17 additions and 1 deletions
|
|
@ -516,6 +516,7 @@ void cmd_truncate(const char* path, int size)
|
|||
|
||||
if (S_ISREG(st.st_mode)) {
|
||||
off_t off;
|
||||
int f;
|
||||
|
||||
/* if file is empty, just rewrite it */
|
||||
if (st.st_size == 0) {
|
||||
|
|
@ -528,12 +529,27 @@ void cmd_truncate(const char* path, int size)
|
|||
|
||||
off = st.st_size - size;
|
||||
|
||||
if (truncate(path, off) != 0) {
|
||||
f = open(path, O_WRONLY | O_BINARY | O_NOFOLLOW);
|
||||
if (f < 0) {
|
||||
/* LCOV_EXCL_START */
|
||||
fprintf(stderr, "Error opening file %s\n", path);
|
||||
exit(EXIT_FAILURE);
|
||||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
|
||||
if (ftruncate(f, off) != 0) {
|
||||
/* LCOV_EXCL_START */
|
||||
fprintf(stderr, "Error truncating file %s\n", path);
|
||||
exit(EXIT_FAILURE);
|
||||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
|
||||
if (close(f) != 0) {
|
||||
/* LCOV_EXCL_START */
|
||||
fprintf(stderr, "Error closing file %s\n", path);
|
||||
exit(EXIT_FAILURE);
|
||||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue