58 memcpy(Hdr.
Magic,
"ustar", 5);
71 int Len =
Key.size() + Val.
size() + 3;
95 for (
size_t I = 0;
I <
sizeof(Hdr); ++
I)
96 Chksum +=
reinterpret_cast<uint8_t *
>(&Hdr)[
I];
111 const uint64_t MaxSize = 077777777777;
112 assert(
Size <= MaxSize &&
"file is too large for a ustar header");
114 snprintf(Hdr.
Size,
sizeof(Hdr.
Size),
"%011llo",
115 static_cast<unsigned long long>(
Size));
122 std::string PaxAttr =
formatPax(
"path", Path);
131 OS << StringRef(reinterpret_cast<char *>(&Hdr),
sizeof(Hdr));
161 const int MaxPrefix = 137;
162 size_t Sep = Path.rfind(
'/', MaxPrefix + 1);
168 Prefix = Path.substr(0, Sep);
169 Name = Path.substr(Sep + 1);
178 memcpy(Hdr.
Name, Name.data(), Name.size());
179 memcpy(Hdr.
Mode,
"0000664", 8);
181 memcpy(Hdr.
Prefix, Prefix.data(), Prefix.size());
183 OS << StringRef(reinterpret_cast<char *>(&Hdr),
sizeof(Hdr));
191 if (std::error_code EC =
192 openFileForWrite(OutputPath, FD, CD_CreateAlways, OF_None))
194 return std::unique_ptr<TarWriter>(
new TarWriter(FD, BaseDir));
197TarWriter::TarWriter(
int FD,
StringRef BaseDir)
199 BaseDir(
std::string(BaseDir)) {}
207 if (!Files.insert(Fullpath).second)
225 uint64_t Pos = OS.tell();
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static void writePaxHeader(raw_fd_ostream &OS, StringRef Path)
static void writeUstarHeader(raw_fd_ostream &OS, StringRef Prefix, StringRef Name, size_t Size)
static void pad(raw_fd_ostream &OS)
static std::string formatPax(StringRef Key, StringRef Val)
static UstarHeader makeUstarHeader()
static const int BlockSize
static void computeChecksum(UstarHeader &Hdr)
static void writeSize(UstarHeader &Hdr, uint64_t Size)
static bool splitUstar(StringRef Path, StringRef &Prefix, StringRef &Name)
Tagged union holding either a T or a Error.
Represent a constant reference to a string, i.e.
static constexpr size_t npos
constexpr size_t size() const
Get the string size.
static LLVM_ABI Expected< std::unique_ptr< TarWriter > > create(StringRef OutputPath, StringRef BaseDir)
LLVM_ABI void append(StringRef Path, StringRef Data)
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
LLVM_ABI std::string str() const
Return the twine contents as a std::string.
A raw_ostream that writes to a file descriptor.
uint64_t seek(uint64_t off)
Flushes the stream and repositions the underlying file descriptor position to the offset specified fr...
uint64_t tell() const
tell - Return the current offset with the file.
LLVM_ABI std::string convert_to_slash(StringRef path, Style style=Style::native)
Replaces backslashes with slashes if Windows.
This is an optimization pass for GlobalISel generic memory operations.
constexpr uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key
Error make_error(ArgTs &&... Args)
Make a Error instance representing failure using the given error info type.
Implement std::hash so that hash_code can be used in STL containers.