[llvm-commits] [llvm] r120819 - in /llvm/trunk/lib/Support: Unix/PathV2.inc Windows/PathV2.inc
Michael J. Spencer
bigcheesegs at gmail.com
Fri Dec 3 09:54:07 PST 2010
Author: mspencer
Date: Fri Dec 3 11:54:07 2010
New Revision: 120819
URL: http://llvm.org/viewvc/llvm-project?rev=120819&view=rev
Log:
Support/FileSystem: Add resize_file implementation.
Modified:
llvm/trunk/lib/Support/Unix/PathV2.inc
llvm/trunk/lib/Support/Windows/PathV2.inc
Modified: llvm/trunk/lib/Support/Unix/PathV2.inc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Unix/PathV2.inc?rev=120819&r1=120818&r2=120819&view=diff
==============================================================================
--- llvm/trunk/lib/Support/Unix/PathV2.inc (original)
+++ llvm/trunk/lib/Support/Unix/PathV2.inc Fri Dec 3 11:54:07 2010
@@ -213,6 +213,16 @@
return make_error_code(errc::success);
}
+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)
+ return error_code(errno, system_category());
+
+ return make_error_code(errc::success);
+}
+
error_code exists(const Twine &path, bool &result) {
SmallString<128> path_storage;
StringRef p = path.toNullTerminatedStringRef(path_storage);
Modified: llvm/trunk/lib/Support/Windows/PathV2.inc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Windows/PathV2.inc?rev=120819&r1=120818&r2=120819&view=diff
==============================================================================
--- llvm/trunk/lib/Support/Windows/PathV2.inc (original)
+++ llvm/trunk/lib/Support/Windows/PathV2.inc Fri Dec 3 11:54:07 2010
@@ -18,7 +18,10 @@
#include "Windows.h"
#include <WinCrypt.h>
+#include <fcntl.h>
#include <io.h>
+#include <sys/stat.h>
+#include <sys/types.h>
using namespace llvm;
@@ -290,6 +293,22 @@
return make_error_code(errc::success);
}
+error_code resize_file(const Twine &path, uint64_t size) {
+ SmallString<128> path_storage;
+ SmallVector<wchar_t, 128> path_utf16;
+
+ if (error_code ec = UTF8ToUTF16(path.toStringRef(path_storage),
+ path_utf16))
+ return ec;
+
+ int fd = ::_wopen(path_utf16.begin(), O_BINARY, S_IREAD | S_IWRITE);
+ if (fd == -1)
+ return error_code(errno, generic_category());
+ errno_t error = ::_chsize_s(fd, size);
+ ::close(fd);
+ return error_code(error, generic_category());
+}
+
error_code exists(const Twine &path, bool &result) {
SmallString<128> path_storage;
SmallVector<wchar_t, 128> path_utf16;
More information about the llvm-commits
mailing list