[llvm-commits] [llvm] r120867 - in /llvm/trunk/lib/Support: Unix/PathV2.inc Windows/PathV2.inc

Michael J. Spencer bigcheesegs at gmail.com
Fri Dec 3 16:31:48 PST 2010


Author: mspencer
Date: Fri Dec  3 18:31:48 2010
New Revision: 120867

URL: http://llvm.org/viewvc/llvm-project?rev=120867&view=rev
Log:
Support/FileSystem: Add file_size 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=120867&r1=120866&r2=120867&view=diff
==============================================================================
--- llvm/trunk/lib/Support/Unix/PathV2.inc (original)
+++ llvm/trunk/lib/Support/Unix/PathV2.inc Fri Dec  3 18:31:48 2010
@@ -263,6 +263,20 @@
   return make_error_code(errc::success);
 }
 
+error_code file_size(const Twine &path, uint64_t &result) {
+  SmallString<128> path_storage;
+  StringRef p = path.toNullTerminatedStringRef(path_storage);
+
+  struct stat status;
+  if (::stat(p.begin(), &status) == -1)
+    return error_code(errno, system_category());
+  if (!S_ISREG(status.st_mode))
+    return error_code(EPERM, system_category());
+
+  result = status.st_size;
+  return make_error_code(errc::success);
+}
+
 error_code unique_file(const Twine &model, int &result_fd,
                              SmallVectorImpl<char> &result_path) {
   SmallString<128> Model;

Modified: llvm/trunk/lib/Support/Windows/PathV2.inc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Windows/PathV2.inc?rev=120867&r1=120866&r2=120867&view=diff
==============================================================================
--- llvm/trunk/lib/Support/Windows/PathV2.inc (original)
+++ llvm/trunk/lib/Support/Windows/PathV2.inc Fri Dec  3 18:31:48 2010
@@ -406,6 +406,27 @@
   return make_error_code(errc::success);
 }
 
+error_code file_size(const Twine &path, uint64_t &result) {
+  SmallString<128> path_storage;
+  SmallVector<wchar_t, 128> path_utf16;
+
+  if (error_code ec = UTF8ToUTF16(path.toStringRef(path_storage),
+                                  path_utf16))
+    return ec;
+
+  WIN32_FILE_ATTRIBUTE_DATA FileData;
+  if (!::GetFileAttributesExW(path_utf16.begin(),
+                              ::GetFileExInfoStandard,
+                              &FileData))
+    return make_error_code(windows_error(::GetLastError()));
+
+  result =
+    (uint64_t(FileData.nFileSizeHigh) << (sizeof(FileData.nFileSizeLow) * 8))
+    + FileData.nFileSizeLow;
+
+  return make_error_code(errc::success);
+}
+
 error_code unique_file(const Twine &model, int &result_fd,
                              SmallVectorImpl<char> &result_path) {
   // Use result_path as temp storage.





More information about the llvm-commits mailing list