]> granicus.if.org Git - llvm/commit
[Support] Improve readNativeFile(Slice) interface
authorPavel Labath <pavel@labath.sk>
Thu, 22 Aug 2019 08:13:30 +0000 (08:13 +0000)
committerPavel Labath <pavel@labath.sk>
Thu, 22 Aug 2019 08:13:30 +0000 (08:13 +0000)
commit3ffae1923a53a2532f7564a0be44e41193e7bed2
tree29de8b3ee01b069cb1f66ca3bddd76ba86db015b
parentad39372e52b556908c541e3260b4a7b38c67bf9a
[Support] Improve readNativeFile(Slice) interface

Summary:
There was a subtle, but pretty important difference between the Slice
and regular versions of this function. The Slice function was
zero-initializing the rest of the buffer when the read syscall returned
less bytes than expected, while the regular function did not.

This patch removes the inconsistency by making both functions *not*
zero-initialize the buffer. The zeroing code is moved to the
MemoryBuffer class, which is currently the only user of this code. This
makes the API more consistent, and the code shorter.

While in there, I also refactor the functions to return the number of
bytes through the regular return value (via Expected<size_t>) instead of
a separate by-ref argument.

Reviewers: aganea, rnk

Subscribers: kristina, Bigcheese, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D66471

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@369627 91177308-0d34-0410-b5e6-96231b3b80d8
include/llvm/Support/FileSystem.h
lib/Support/MemoryBuffer.cpp
lib/Support/Unix/Path.inc
lib/Support/Windows/Path.inc
unittests/Support/MemoryBufferTest.cpp
unittests/Support/Path.cpp