summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Object/ArchiveWriter.cpp
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2017-09-21 23:00:55 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2017-09-21 23:00:55 +0000
commit540a8c7fad15ba51c12a61e10a929f247dcd49ff (patch)
tree3f2f8c8375b283f9c1ef60bc203c74afcaa25bbc /llvm/lib/Object/ArchiveWriter.cpp
parent182a8083c1e26577dfc52e78dbd95d221daed20d (diff)
downloadbcm5719-llvm-540a8c7fad15ba51c12a61e10a929f247dcd49ff.tar.gz
bcm5719-llvm-540a8c7fad15ba51c12a61e10a929f247dcd49ff.zip
Simplify the logic for truncating UID and GID. NFC.
llvm-svn: 313933
Diffstat (limited to 'llvm/lib/Object/ArchiveWriter.cpp')
-rw-r--r--llvm/lib/Object/ArchiveWriter.cpp21
1 files changed, 9 insertions, 12 deletions
diff --git a/llvm/lib/Object/ArchiveWriter.cpp b/llvm/lib/Object/ArchiveWriter.cpp
index ab86d8dbbcc..36f505d4dff 100644
--- a/llvm/lib/Object/ArchiveWriter.cpp
+++ b/llvm/lib/Object/ArchiveWriter.cpp
@@ -111,19 +111,12 @@ Expected<NewArchiveMember> NewArchiveMember::getFile(StringRef FileName,
}
template <typename T>
-static void printWithSpacePadding(raw_fd_ostream &OS, T Data, unsigned Size,
- bool MayTruncate = false) {
+static void printWithSpacePadding(raw_fd_ostream &OS, T Data, unsigned Size) {
uint64_t OldPos = OS.tell();
OS << Data;
unsigned SizeSoFar = OS.tell() - OldPos;
- if (Size > SizeSoFar) {
- OS.indent(Size - SizeSoFar);
- } else if (Size < SizeSoFar) {
- assert(MayTruncate && "Data doesn't fit in Size");
- // Some of the data this is used for (like UID) can be larger than the
- // space available in the archive format. Truncate in that case.
- OS.seek(OldPos + Size);
- }
+ assert(SizeSoFar <= Size && "Data doesn't fit in Size");
+ OS.indent(Size - SizeSoFar);
}
static bool isBSDLike(object::Archive::Kind Kind) {
@@ -153,8 +146,12 @@ static void printRestOfMemberHeader(
raw_fd_ostream &Out, const sys::TimePoint<std::chrono::seconds> &ModTime,
unsigned UID, unsigned GID, unsigned Perms, unsigned Size) {
printWithSpacePadding(Out, sys::toTimeT(ModTime), 12);
- printWithSpacePadding(Out, UID, 6, true);
- printWithSpacePadding(Out, GID, 6, true);
+
+ // The format has only 6 chars for uid and gid. Truncate if the provided
+ // values don't fit.
+ printWithSpacePadding(Out, UID % 1000000, 6);
+ printWithSpacePadding(Out, GID % 1000000, 6);
+
printWithSpacePadding(Out, format("%o", Perms), 8);
printWithSpacePadding(Out, Size, 10);
Out << "`\n";
OpenPOWER on IntegriCloud