<p dir="ltr"><br>
On Mar 25, 2016 12:42 PM, "Mehdi Amini" <<a href="mailto:mehdi.amini@apple.com">mehdi.amini@apple.com</a>> wrote:<br>
><br>
> I thought about it but the rest of the file is using std::error_code as a return. Do we want to introduce a discrepancy here?<br>
></p>
<p dir="ltr">I would prefer it, yes. Otherwise it is hard to migrate to newer APIs.</p>
<p dir="ltr">Cheers,<br>
Rafael<br><br></p>
<p dir="ltr">>> On Mar 25, 2016, at 9:41 AM, Rafael Espíndola <<a href="mailto:rafael.espindola@gmail.com">rafael.espindola@gmail.com</a>> wrote:<br>
>><br>
>> Can you return an ErrorOr or Expected?<br>
>><br>
>> On Mar 24, 2016 8:17 PM, "Mehdi AMINI via llvm-commits" <<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a>> wrote:<br>
>>><br>
>>> joker.eph created this revision.<br>
>>> joker.eph added reviewers: bruno, silvas.<br>
>>> joker.eph added a subscriber: llvm-commits.<br>
>>> Herald added subscribers: srhines, danalbert, tberghammer.<br>
>>><br>
>>> Adapted from Boost::filesystem.<br>
>>><br>
>>> <a href="http://reviews.llvm.org/D18467">http://reviews.llvm.org/D18467</a><br>
>>><br>
>>> Files:<br>
>>>   include/llvm/Support/FileSystem.h<br>
>>>   lib/Support/Unix/Path.inc<br>
>>>   lib/Support/Windows/Path.inc<br>
>>><br>
>>> Index: lib/Support/Windows/Path.inc<br>
>>> ===================================================================<br>
>>> --- lib/Support/Windows/Path.inc<br>
>>> +++ lib/Support/Windows/Path.inc<br>
>>> @@ -151,6 +151,19 @@<br>
>>>    return UniqueID(VolumeSerialNumber, FileID);<br>
>>>  }<br>
>>><br>
>>> +std::error_code disk_space(const Twine Path, space_info &SpaceInfo) {<br>
>>> +  PULARGE_INTEGER avail, total, free;<br>
>>> +  if (!::GetDiskFreeSpaceExW(Path.str().c_str(), &avail, &total, &free))<br>
>>> +      return mapWindowsError(::GetLastError());<br>
>>> +  SpaceInfo.capacity = (static_cast<uint64_t>(total.HighPart) << 32)<br>
>>> +    + total.LowPart;<br>
>>> +  SpaceInfo.free = (static_cast<uint64_t>(free.HighPart) << 32)<br>
>>> +    + free.LowPart;<br>
>>> +  SpaceInfo.available = (static_cast<uint64_t>(avail.HighPart) << 32)<br>
>>> +    + avail.LowPart;<br>
>>> +  return std::error_code();<br>
>>> +}<br>
>>> +<br>
>>>  TimeValue file_status::getLastAccessedTime() const {<br>
>>>    ULARGE_INTEGER UI;<br>
>>>    UI.LowPart = LastAccessedTimeLow;<br>
>>> Index: lib/Support/Unix/Path.inc<br>
>>> ===================================================================<br>
>>> --- lib/Support/Unix/Path.inc<br>
>>> +++ lib/Support/Unix/Path.inc<br>
>>> @@ -60,6 +60,24 @@<br>
>>>  # define PATH_MAX 4096<br>
>>>  #endif<br>
>>><br>
>>> +#include <sys/types.h><br>
>>> +#if !defined(__APPLE__) && !defined(__OpenBSD__) && !defined(__ANDROID__)<br>
>>> +#  include <sys/statvfs.h><br>
>>> +#  define STATVFS statvfs<br>
>>> +#  define STATVFS_F_FRSIZE(vfs) vfs.f_frsize<br>
>>> +#else<br>
>>> +# ifdef __OpenBSD__<br>
>>> +#  include <sys/param.h><br>
>>> +# elif defined(__ANDROID__)<br>
>>> +#  include <sys/vfs.h><br>
>>> +# else<br>
>>> +#  include <sys/mount.h><br>
>>> +# endif<br>
>>> +# define STATVFS statfs<br>
>>> +# define STATVFS_F_FRSIZE(vfs) static_cast<uint64_t>(vfs.f_bsize)<br>
>>> +#endif<br>
>>> +<br>
>>> +<br>
>>>  using namespace llvm;<br>
>>><br>
>>>  namespace llvm {<br>
>>> @@ -190,6 +208,18 @@<br>
>>>    return UniqueID(fs_st_dev, fs_st_ino);<br>
>>>  }<br>
>>><br>
>>> +std::error_code disk_space(const Twine Path, space_info &SpaceInfo) {<br>
>>> +  struct STATVFS Vfs;<br>
>>> +  if(::STATVFS(Path.str().c_str(), &Vfs))<br>
>>> +    return std::error_code(errno, std::generic_category());<br>
>>> +  SpaceInfo.capacity =<br>
>>> +      static_cast<uint64_t>(Vfs.f_blocks)* STATVFS_F_FRSIZE(Vfs);<br>
>>> +  SpaceInfo.free = static_cast<uint64_t>(Vfs.f_bfree)* STATVFS_F_FRSIZE(Vfs);<br>
>>> +  SpaceInfo.available =<br>
>>> +      static_cast<uint64_t>(Vfs.f_bavail)* STATVFS_F_FRSIZE(Vfs);<br>
>>> +  return std::error_code();<br>
>>> +}<br>
>>> +<br>
>>>  std::error_code current_path(SmallVectorImpl<char> &result) {<br>
>>>    result.clear();<br>
>>><br>
>>> Index: include/llvm/Support/FileSystem.h<br>
>>> ===================================================================<br>
>>> --- include/llvm/Support/FileSystem.h<br>
>>> +++ include/llvm/Support/FileSystem.h<br>
>>> @@ -647,6 +647,15 @@<br>
>>><br>
>>>  std::error_code getUniqueID(const Twine Path, UniqueID &Result);<br>
>>><br>
>>> +/// @brief Get disk space usage information.<br>
>>> +///<br>
>>> +/// @param Path Input path.<br>
>>> +/// @param SpaceInfo Set to the capacity, free, and available space on the<br>
>>> +///        device \a Path is on.<br>
>>> +/// @results errc::success if result has been successfully set, otherwise a<br>
>>> +///          platform specific error_code.<br>
>>> +std::error_code disk_space(const Twine Path, space_info &SpaceInfo);<br>
>>> +<br>
>>>  /// This class represents a memory mapped file. It is based on<br>
>>>  /// boost::iostreams::mapped_file.<br>
>>>  class mapped_file_region {<br>
>>><br>
>>><br>
>>><br>
>>> _______________________________________________<br>
>>> llvm-commits mailing list<br>
>>> <a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a><br>
>>> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
>>><br>
><br>
</p>