Commit 26cd6e79 authored by Ruslan Sayfutdinov's avatar Ruslan Sayfutdinov Committed by Facebook GitHub Bot

folly/portability: ftruncate shouldn't change file offset

Summary:
From documentation in https://linux.die.net/man/2/ftruncate
> The file offset is not changed.

Reviewed By: Orvid, Skory

Differential Revision: D30843563

fbshipit-source-id: 9314576d927d9ddc07df6d0ceae394d148d7af94
parent 50200930
......@@ -93,6 +93,10 @@ int fsync(int fd) {
}
int ftruncate(int fd, off_t len) {
off_t origLoc = _lseek(fd, 0, SEEK_CUR);
if (origLoc == -1) {
return -1;
}
if (_lseek(fd, len, SEEK_SET) == -1) {
return -1;
}
......@@ -104,6 +108,9 @@ int ftruncate(int fd, off_t len) {
if (!SetEndOfFile(h)) {
return -1;
}
if (_lseek(fd, origLoc, SEEK_SET) == -1) {
return -1;
}
return 0;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment