summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Support
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2014-12-12 17:55:12 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2014-12-12 17:55:12 +0000
commit59aaa6c06b80bd7285573b407dad4f3e008351de (patch)
tree7b2dcfc365f8e1acfde2828a092696cc9026c842 /llvm/lib/Support
parent5753cf3c6371ef269da3f645afbabb2fd92ae56e (diff)
downloadbcm5719-llvm-59aaa6c06b80bd7285573b407dad4f3e008351de.tar.gz
bcm5719-llvm-59aaa6c06b80bd7285573b407dad4f3e008351de.zip
Pass a FD to resise_file and add a testcase.
I will add a real use in another commit. llvm-svn: 224136
Diffstat (limited to 'llvm/lib/Support')
-rw-r--r--llvm/lib/Support/Unix/Path.inc7
-rw-r--r--llvm/lib/Support/Windows/Path.inc16
2 files changed, 6 insertions, 17 deletions
diff --git a/llvm/lib/Support/Unix/Path.inc b/llvm/lib/Support/Unix/Path.inc
index 1e1b911b78b..75bcc03bbd3 100644
--- a/llvm/lib/Support/Unix/Path.inc
+++ b/llvm/lib/Support/Unix/Path.inc
@@ -286,11 +286,8 @@ std::error_code rename(const Twine &from, const Twine &to) {
return std::error_code();
}
-std::error_code resize_file(const Twine &path, uint64_t size) {
- SmallString<128> path_storage;
- StringRef p = path.toNullTerminatedStringRef(path_storage);
-
- if (::truncate(p.begin(), size) == -1)
+std::error_code resize_file(int FD, uint64_t Size) {
+ if (::ftruncate(FD, Size) == -1)
return std::error_code(errno, std::generic_category());
return std::error_code();
diff --git a/llvm/lib/Support/Windows/Path.inc b/llvm/lib/Support/Windows/Path.inc
index 20eae54b181..05c0986d049 100644
--- a/llvm/lib/Support/Windows/Path.inc
+++ b/llvm/lib/Support/Windows/Path.inc
@@ -272,21 +272,13 @@ std::error_code rename(const Twine &from, const Twine &to) {
return ec;
}
-std::error_code resize_file(const Twine &path, uint64_t size) {
- SmallVector<wchar_t, 128> path_utf16;
-
- if (std::error_code ec = widenPath(path, path_utf16))
- return ec;
-
- int fd = ::_wopen(path_utf16.begin(), O_BINARY | _O_RDWR, S_IWRITE);
- if (fd == -1)
- return std::error_code(errno, std::generic_category());
+std::error_code resize_file(int FD, uint64_t Size) {
#ifdef HAVE__CHSIZE_S
- errno_t error = ::_chsize_s(fd, size);
+ errno_t error = ::_chsize_s(FD, Size);
#else
- errno_t error = ::_chsize(fd, size);
+ errno_t error = ::_chsize(FD, Size);
#endif
- ::close(fd);
+ ::close(FD);
return std::error_code(error, std::generic_category());
}
OpenPOWER on IntegriCloud