LLVM: lib/Support/Path.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
17#include "llvm/Config/config.h"
18#include "llvm/Config/llvm-config.h"
24#include
25
26#if !defined(_MSC_VER) && !defined(__MINGW32__)
27#include <unistd.h>
28#else
29#include <io.h>
30#endif
31
32using namespace llvm;
34
35namespace {
39
40 inline Style real_style(Style style) {
41 if (style != Style::native)
42 return style;
44 return Style::posix;
45 return LLVM_WINDOWS_PREFER_FORWARD_SLASH ? Style::windows_slash
46 : Style::windows_backslash;
47 }
48
49 inline const char *separators(Style style) {
51 return "\\/";
52 return "/";
53 }
54
55 inline char preferred_separator(Style style) {
56 if (real_style(style) == Style::windows)
57 return '\\';
58 return '/';
59 }
60
62
63
64
65
66
67
68 if (path.empty())
70
72
73 if (path.size() >= 2 &&
74 std::isalpha(static_cast<unsigned char>(path[0])) && path[1] == ':')
75 return path.substr(0, 2);
76 }
77
78
81
82 size_t end = path.find_first_of(separators(style), 2);
83 return path.substr(0, end);
84 }
85
86
88 return path.substr(0, 1);
89
90
91 size_t end = path.find_first_of(separators(style));
92 return path.substr(0, end);
93 }
94
95
96
97 size_t filename_pos(StringRef str, Style style) {
99 return str.size() - 1;
100
101 size_t pos = str.find_last_of(separators(style), str.size() - 1);
102
106 }
107
109 return 0;
110
111 return pos + 1;
112 }
113
114
115
116 size_t root_dir_start(StringRef str, Style style) {
117
119 if (str.size() > 2 && str[1] == ':' && is_separator(str[2], style))
120 return 2;
121 }
122
123
124 if (str.size() > 3 && is_separator(str[0], style) && str[0] == str[1] &&
127 }
128
129
131 return 0;
132
134 }
135
136
137
138
139 size_t parent_path_end(StringRef path, Style style) {
140 size_t end_pos = filename_pos(path, style);
141
142 bool filename_was_sep =
144
145
146 size_t root_dir_pos = root_dir_start(path, style);
147 while (end_pos > 0 &&
148 (root_dir_pos == StringRef::npos || end_pos > root_dir_pos) &&
150 --end_pos;
151
152 if (end_pos == root_dir_pos && !filename_was_sep) {
153
154
155 return root_dir_pos + 1;
156 }
157
158
159 return end_pos;
160 }
161}
162
168
169static std::error_code
173 unsigned Mode = 0) {
174
175
176
177
178
179 std::error_code EC;
180 for (int Retries = 128; Retries > 0; --Retries) {
182
183 switch (Type) {
187 if (EC) {
188
189
191 continue;
192 return EC;
193 }
194
195 return std::error_code();
196 }
197
201 return std::error_code();
202 if (EC)
203 return EC;
204 continue;
205 }
206
209 if (EC) {
211 continue;
212 return EC;
213 }
214 return std::error_code();
215 }
216 }
218 }
219 return EC;
220}
221
222namespace llvm {
223namespace sys {
224namespace path {
225
228 i.Path = path;
229 i.Component = find_first_component(path, style);
230 i.Position = 0;
231 i.S = style;
232 return i;
233}
234
237 i.Path = path;
238 i.Position = path.size();
239 return i;
240}
241
243 assert(Position < Path.size() && "Tried to increment past end!");
244
245
246 Position += Component.size();
247
248
249 if (Position == Path.size()) {
251 return *this;
252 }
253
254
255
256 bool was_net = Component.size() > 2 && is_separator(Component[0], S) &&
257 Component[1] == Component[0] && (Component[2], S);
258
259
261
262 if (was_net ||
263
265 Component = Path.substr(Position, 1);
266 return *this;
267 }
268
269
270 while (Position != Path.size() && is_separator(Path[Position], S)) {
271 ++Position;
272 }
273
274
275 if (Position == Path.size() && Component != "/") {
276 --Position;
277 Component = ".";
278 return *this;
279 }
280 }
281
282
283 size_t end_pos = Path.find_first_of(separators(S), Position);
284 Component = Path.slice(Position, end_pos);
285
286 return *this;
287}
288
290 return Path.begin() == RHS.Path.begin() && Position == RHS.Position;
291}
292
294 return Position - RHS.Position;
295}
296
299 I.Path = Path;
300 I.Position = Path.size();
301 I.S = style;
302 ++I;
303 return I;
304}
305
308 I.Path = Path;
309 I.Component = Path.substr(0, 0);
310 I.Position = 0;
311 return I;
312}
313
315 size_t root_dir_pos = root_dir_start(Path, S);
316
317
318 size_t end_pos = Position;
319 while (end_pos > 0 && (end_pos - 1) != root_dir_pos &&
321 --end_pos;
322
323
324 if (Position == Path.size() && !Path.empty() &&
326 (root_dir_pos == StringRef::npos || end_pos - 1 > root_dir_pos)) {
327 --Position;
328 Component = ".";
329 return *this;
330 }
331
332
333 size_t start_pos = filename_pos(Path.substr(0, end_pos), S);
334 Component = Path.slice(start_pos, end_pos);
335 Position = start_pos;
336 return *this;
337}
338
340 return Path.begin() == RHS.Path.begin() && Component == RHS.Component &&
341 Position == RHS.Position;
342}
343
345 return Position - RHS.Position;
346}
347
350 if (b != e) {
351 bool has_net =
352 b->size() > 2 && is_separator((*b)[0], style) && (*b)[1] == (*b)[0];
353 bool has_drive = is_style_windows(style) && b->ends_with(":");
354
355 if (has_net || has_drive) {
356 if ((++pos != e) && is_separator((*pos)[0], style)) {
357
358 return path.substr(0, b->size() + pos->size());
359 }
360
361 return *b;
362 }
363
364
366 return *b;
367 }
368 }
369
371}
372
375 if (b != e) {
376 bool has_net =
377 b->size() > 2 && is_separator((*b)[0], style) && (*b)[1] == (*b)[0];
378 bool has_drive = is_style_windows(style) && b->ends_with(":");
379
380 if (has_net || has_drive) {
381
382 return *b;
383 }
384 }
385
386
388}
389
392 if (b != e) {
393 bool has_net =
394 b->size() > 2 && is_separator((*b)[0], style) && (*b)[1] == (*b)[0];
395 bool has_drive = is_style_windows(style) && b->ends_with(":");
396
397 if ((has_net || has_drive) &&
398
399 (++pos != e) && is_separator((*pos)[0], style)) {
400 return *pos;
401 }
402
403
404 if (!has_net && is_separator((*b)[0], style)) {
405 return *b;
406 }
407 }
408
409
411}
412
415 return path.substr(root.size());
416}
417
424
427 if (!b.isTriviallyEmpty()) components.push_back(b.toStringRef(b_storage));
430
431 for (auto &component : components) {
432 bool path_has_sep =
434 if (path_has_sep) {
435
436 size_t loc = component.find_first_not_of(separators(style));
437 StringRef c = component.substr(loc);
438
439
441 continue;
442 }
443
444 bool component_has_sep =
445 !component.empty() && is_separator(component[0], style);
446 if (!component_has_sep &&
448
449 path.push_back(preferred_separator(style));
450 }
451
452 path.append(component.begin(), component.end());
453 }
454}
455
460
466
468 size_t end_pos = parent_path_end(path, style);
471 return path.substr(0, end_pos);
472}
473
475 size_t end_pos = parent_path_end(StringRef(path.begin(), path.size()), style);
477 path.truncate(end_pos);
478}
479
485
486
487 size_t pos = p.find_last_of('.');
488 if (pos != StringRef::npos && pos >= filename_pos(p, style))
489 path.truncate(pos);
490
491
492 if (ext.size() > 0 && ext[0] != '.')
493 path.push_back('.');
494
495
497}
498
501
503 if (Path.size() < Prefix.size())
504 return false;
505 for (size_t I = 0, E = Prefix.size(); I != E; ++I) {
508 if (SepPath != SepPrefix)
509 return false;
511 return false;
512 }
513 return true;
514 }
515 return Path.starts_with(Prefix);
516}
517
520 if (OldPrefix.empty() && NewPrefix.empty())
521 return false;
522
523 StringRef OrigPath(Path.begin(), Path.size());
524 if ((OrigPath, OldPrefix, style))
525 return false;
526
527
528 if (OldPrefix.size() == NewPrefix.size()) {
530 return true;
531 }
532
535 (Twine(NewPrefix) + RelPath).toVector(NewPath);
536 Path.swap(NewPath);
537 return true;
538}
539
542 path.getSingleStringRef().data() != result.data()) &&
543 "path and result are not allowed to overlap!");
544
546 path.toVector(result);
547 native(result, style);
548}
549
551 if (Path.empty())
552 return;
554 for (char &Ch : Path)
556 Ch = preferred_separator(style);
557 if (Path[0] == '~' && (Path.size() == 1 || is_separator(Path[1], style))) {
560 PathHome.append(Path.begin() + 1, Path.end());
561 Path = PathHome;
562 }
563 } else {
565 }
566}
567
570 return std::string(path);
571
572 std::string s = path.str();
574 return s;
575}
576
578
583 return fname;
584 if ((fname.size() == 1 && fname == ".") ||
585 (fname.size() == 2 && fname == ".."))
586 return fname;
587 return fname.substr(0, pos);
588}
589
595 if ((fname.size() == 1 && fname == ".") ||
596 (fname.size() == 2 && fname == ".."))
598 return fname.substr(pos);
599}
600
602 if (value == '/')
603 return true;
605 return value == '\\';
606 return false;
607}
608
611 return "\\";
612 return "/";
613}
614
621
628
635
642
649
656
663
670
674
677
678 return rootDir && rootName;
679}
680
684
685
686
687 if (!p.empty() && is_separator(p.front(), style))
688 return true;
689
691
692 if (p.size() >= 2 && (p[0] && p[1] == ':'))
693 return true;
694 }
695
696 return false;
697}
698
702
706
709
710
712 return;
713
714
716 current_directory.toVector(current_dir);
717
718
719 if (!rootName && !rootDirectory) {
720
721 append(current_dir, p);
722
723 path.swap(current_dir);
724 return;
725 }
726
727 if (!rootName && rootDirectory) {
730 append(curDirRootName, p);
731
732 path.swap(curDirRootName);
733 return;
734 }
735
736 if (rootName && !rootDirectory) {
741
743 append(res, pRootName, bRootDirectory, bRelativePath, pRelativePath);
744 path.swap(res);
745 return;
746 }
747
748 llvm_unreachable("All rootName and rootDirectory combinations should have "
749 "occurred above!");
750}
751
753
754 while (Path.size() > 2 && Path[0] == '.' && is_separator(Path[1], style)) {
755 Path = Path.substr(2);
756 while (Path.size() > 0 && is_separator(Path[0], style))
757 Path = Path.substr(1);
758 }
759 return Path;
760}
761
762
763
766 style = real_style(style);
768 bool needs_change = false;
770
771
773 bool absolute = !root.empty();
774 if (absolute)
776
777
778
779 while (!remaining.empty()) {
780 size_t next_slash = remaining.find_first_of(separators(style));
782 next_slash = remaining.size();
784 remaining = remaining.drop_front(next_slash);
785
786
787 if (!remaining.empty()) {
788 needs_change |= remaining.front() != preferred_separator(style);
790
791
792 needs_change |= remaining.empty();
793 }
794
795
796 if (component.empty() || component == ".") {
797 needs_change = true;
798 } else if (remove_dot_dot && component == "..") {
799 needs_change = true;
800
801
802 if (!components.empty() && components.back() != "..") {
804 } else if (!absolute) {
806 }
807 } else {
809 }
810 }
811
813
815 needs_change |= root != buffer;
816
817
818 if (!needs_change)
819 return false;
820
821 if (!components.empty()) {
822 buffer += components[0];
824 buffer += preferred_separator(style);
825 buffer += C;
826 }
827 }
828 the_path.swap(buffer);
829 return true;
830}
831
832}
833
834namespace fs {
835
839 if (EC)
840 return EC;
841 Result = Status.getUniqueID();
842 return std::error_code();
843}
844
846 bool MakeAbsolute) {
848 Model.toVector(ModelStorage);
849
850 if (MakeAbsolute) {
851
856 ModelStorage.swap(TDir);
857 }
858 }
859
860 ResultPath = ModelStorage;
863
864
865 for (unsigned i = 0, e = ModelStorage.size(); i != e; ++i) {
866 if (ModelStorage[i] == '%')
868 }
869}
870
873 OpenFlags Flags, unsigned Mode) {
875 Mode);
876}
877
880 unsigned Mode) {
881 int FD;
883 if (EC)
884 return EC;
885
886 close(FD);
887 return EC;
888}
889
890static std::error_code
895 StringRef P = Model.toNullTerminatedStringRef(Storage);
897 "Model must be a simple filename.");
898
901}
902
903static std::error_code
907 const char *Middle = Suffix.empty() ? "-%%%%%%" : "-%%%%%%.";
908 return createTemporaryFile(Prefix + Middle + Suffix, ResultFD, ResultPath,
909 Type, Flags);
910}
911
913 int &ResultFD,
917 Flags);
918}
919
923 int FD;
925 if (EC)
926 return EC;
927
928 close(FD);
929 return EC;
930}
931
932
933
936 int Dummy;
937 return createUniqueEntity(Prefix + "-%%%%%%", Dummy, ResultPath, true,
939}
940
941std::error_code
947
948std::error_code
954
957 return {};
958
960 if (std::error_code ec = current_path(current_dir))
961 return ec;
962
964 return {};
965}
966
970 StringRef P = Path.toStringRef(PathStorage);
971
972
974
975
977 return EC;
978
979
980
982 if (Parent.empty())
983 return EC;
984
986 return EC;
987
989}
990
992 const size_t BufSize = 4096;
993 char *Buf = new char[BufSize];
994 int BytesRead = 0, BytesWritten = 0;
995 for (;;) {
996 BytesRead = read(ReadFD, Buf, BufSize);
997 if (BytesRead <= 0)
998 break;
999 while (BytesRead) {
1000 BytesWritten = write(WriteFD, Buf, BytesRead);
1001 if (BytesWritten < 0)
1002 break;
1003 BytesRead -= BytesWritten;
1004 }
1005 if (BytesWritten < 0)
1006 break;
1007 }
1008 delete[] Buf;
1009
1010 if (BytesRead < 0 || BytesWritten < 0)
1012 return std::error_code();
1013}
1014
1015#ifndef __APPLE__
1017 int ReadFD, WriteFD;
1019 return EC;
1020 if (std::error_code EC =
1022 close(ReadFD);
1023 return EC;
1024 }
1025
1027
1028 close(ReadFD);
1029 close(WriteFD);
1030
1031 return EC;
1032}
1033#endif
1034
1036 int ReadFD;
1038 return EC;
1039
1041
1042 close(ReadFD);
1043
1044 return EC;
1045}
1046
1048 MD5 Hash;
1049
1050 constexpr size_t BufSize = 4096;
1051 std::vector<uint8_t> Buf(BufSize);
1052 int BytesRead = 0;
1053 for (;;) {
1054 BytesRead = read(FD, Buf.data(), BufSize);
1055 if (BytesRead <= 0)
1056 break;
1058 }
1059
1060 if (BytesRead < 0)
1063 Hash.final(Result);
1064 return Result;
1065}
1066
1068 int FD;
1070 return EC;
1071
1073 close(FD);
1074 return Result;
1075}
1076
1080
1084
1087 if (status(Path, st, Follow))
1089 return st.type();
1090}
1091
1095
1098 if (std::error_code ec = status(path, st))
1099 return ec;
1101 return std::error_code();
1102}
1103
1107
1110 if (std::error_code ec = status(path, st))
1111 return ec;
1113 return std::error_code();
1114}
1115
1119
1122 if (std::error_code ec = status(path, st, false))
1123 return ec;
1125 return std::error_code();
1126}
1127
1133
1136 if (std::error_code EC = status(Path, FileStatus))
1137 return EC;
1138 Result = is_other(FileStatus);
1139 return std::error_code();
1140}
1141
1146 this->Path = std::string(PathStr);
1147 this->Type = Type;
1148 this->Status = Status;
1149}
1150
1153 if (std::error_code EC = status(Path, Status))
1154 return EC;
1155
1156 return Status.permissions();
1157}
1158
1160 assert(Mapping && "Mapping failed but used anyway!");
1161 return Size;
1162}
1163
1165 assert(Mapping && "Mapping failed but used anyway!");
1166 return reinterpret_cast<char *>(Mapping);
1167}
1168
1170 assert(Mapping && "Mapping failed but used anyway!");
1171 return reinterpret_cast<const char *>(Mapping);
1172}
1173
1175 ssize_t ChunkSize) {
1176
1177 size_t Size = Buffer.size();
1179
1180
1181 for (;;) {
1185 if (!ReadBytes)
1187 if (*ReadBytes == 0)
1189 Size += *ReadBytes;
1190 }
1191}
1192
1193}
1194}
1195}
1196
1197
1198#if defined(LLVM_ON_UNIX)
1200#endif
1201#if defined(_WIN32)
1203#endif
1204
1205namespace llvm {
1206namespace sys {
1207namespace fs {
1208
1209TempFile::TempFile(StringRef Name, int FD)
1210 : TmpName(std::string(Name)), FD(FD) {}
1211TempFile::TempFile(TempFile &&Other) { *this = std::move(Other); }
1215 Other.Done = true;
1217#ifdef _WIN32
1218 RemoveOnClose = Other.RemoveOnClose;
1219 Other.RemoveOnClose = false;
1220#endif
1221 return *this;
1222}
1223
1225
1227 Done = true;
1228 if (FD != -1 && close(FD) == -1) {
1231 }
1232 FD = -1;
1233
1234#ifdef _WIN32
1235
1236
1237 bool Remove = RemoveOnClose;
1238#else
1239
1240 bool Remove = true;
1241#endif
1242 std::error_code RemoveEC;
1243 if (Remove && !TmpName.empty()) {
1246 if (!RemoveEC)
1247 TmpName = "";
1248 } else {
1249 TmpName = "";
1250 }
1252}
1253
1254Error TempFile::keep(const Twine &Name) {
1256 Done = true;
1257
1258#ifdef _WIN32
1259
1260 auto H = reinterpret_cast<HANDLE>(_get_osfhandle(FD));
1261 std::error_code RenameEC =
1262 RemoveOnClose ? std::error_code() : setDeleteDisposition(H, false);
1263 bool ShouldDelete = false;
1264 if (!RenameEC) {
1265 RenameEC = rename_handle(H, Name);
1266
1267 if (RenameEC ==
1268 std::error_code(ERROR_NOT_SAME_DEVICE, std::system_category())) {
1269 RenameEC = copy_file(TmpName, Name);
1270 ShouldDelete = true;
1271 }
1272 }
1273
1274
1275 if (RenameEC)
1276 ShouldDelete = true;
1277 if (ShouldDelete) {
1278 if (!RemoveOnClose)
1279 setDeleteDisposition(H, true);
1280 else
1282 }
1283#else
1284 std::error_code RenameEC = fs::rename(TmpName, Name);
1285 if (RenameEC) {
1286
1288
1289 if (RenameEC)
1291 }
1292#endif
1294
1295 if (!RenameEC)
1296 TmpName = "";
1297
1298 if (close(FD) == -1)
1300 FD = -1;
1301
1303}
1304
1307 Done = true;
1308
1309#ifdef _WIN32
1310 auto H = reinterpret_cast<HANDLE>(_get_osfhandle(FD));
1311 if (std::error_code EC = setDeleteDisposition(H, false))
1313#endif
1315
1317
1318 if (close(FD) == -1)
1320 FD = -1;
1321
1323}
1324
1327 int FD;
1329 if (std::error_code EC =
1332
1333 TempFile Ret(ResultPath, FD);
1334#ifdef _WIN32
1335 auto H = reinterpret_cast<HANDLE>(_get_osfhandle(FD));
1336 bool SetSignalHandler = false;
1337 if (std::error_code EC = setDeleteDisposition(H, true)) {
1338 Ret.RemoveOnClose = true;
1339 SetSignalHandler = true;
1340 }
1341#else
1342 bool SetSignalHandler = true;
1343#endif
1345
1349 }
1350 return std::move(Ret);
1351}
1352}
1353
1354}
1355}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
Function Alias Analysis false
static std::error_code createUniqueEntity(const Twine &Model, int &ResultFD, SmallVectorImpl< char > &ResultPath, bool MakeAbsolute, FSEntity Type, sys::fs::OpenFlags Flags=sys::fs::OF_None, unsigned Mode=0)
Definition Path.cpp:170
FSEntity
Definition Path.cpp:163
@ FS_Dir
Definition Path.cpp:164
@ FS_File
Definition Path.cpp:165
@ FS_Name
Definition Path.cpp:166
Provides a library for accessing information about this process and other processes on the operating ...
static cl::opt< RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode > Mode("regalloc-enable-advisor", cl::Hidden, cl::init(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Default), cl::desc("Enable regalloc advisor mode"), cl::values(clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Default, "default", "Default"), clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Release, "release", "precompiled"), clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Development, "development", "for training")))
This file defines the make_scope_exit function, which executes user-defined cleanup logic at scope ex...
Represents either an error or a value T.
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
Tagged union holding either a T or a Error.
Error takeError()
Take ownership of the stored error.
LLVM_ABI void update(ArrayRef< uint8_t > Data)
Updates the hash for the byte stream provided.
LLVM_ABI void final(MD5Result &Result)
Finishes off the hash and puts the result in result.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
void append(StringRef RHS)
Append from a StringRef.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void resize_for_overwrite(size_type N)
Like resize, but T is POD, the new values won't be initialized.
void truncate(size_type N)
Like resize, but requires that N is less than size().
void swap(SmallVectorImpl &RHS)
void push_back(const T &Elt)
pointer data()
Return a pointer to the vector's buffer, even if empty().
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
static constexpr size_t npos
constexpr StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
constexpr bool empty() const
empty - Check if the string is empty.
StringRef drop_front(size_t N=1) const
Return a StringRef equal to 'this' but with the first N elements dropped.
constexpr size_t size() const
size - Get the string size.
char front() const
front - Get the first character in the string.
size_t find_last_of(char C, size_t From=npos) const
Find the last character in the string that is C, or npos if not found.
size_t find_first_of(char C, size_t From=0) const
Find the first character in the string that is C, or npos if not found.
StringRef take_front(size_t N=1) const
Return a StringRef equal to 'this' but with only the first N elements remaining.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
bool isTriviallyEmpty() const
Check if this twine is trivially empty; a false return value does not necessarily mean the twine is e...
StringRef toStringRef(SmallVectorImpl< char > &Out) const
This returns the twine as a single StringRef if it can be represented as such.
LLVM_ABI void toVector(SmallVectorImpl< char > &Out) const
Append the concatenated string into the given SmallString or SmallVector.
The instances of the Type class are immutable: once they are created, they are never changed.
static LLVM_ABI unsigned GetRandomNumber()
Get the result of a process wide random number generator.
Represents a temporary file.
LLVM_ABI ~TempFile()
Definition Path.cpp:1224
LLVM_ABI TempFile & operator=(TempFile &&Other)
Definition Path.cpp:1212
LLVM_ABI Error keep(const Twine &Name)
static LLVM_ABI Expected< TempFile > create(const Twine &Model, unsigned Mode=all_read|all_write, OpenFlags ExtraFlags=OF_None)
This creates a temporary file with createUniqueFile and schedules it for deletion with sys::RemoveFil...
Represents the result of a call to directory_iterator::status().
LLVM_ABI void replace_filename(const Twine &Filename, file_type Type, basic_file_status Status=basic_file_status())
Definition Path.cpp:1142
Represents the result of a call to sys::fs::status().
LLVM_ABI size_t size() const
Definition Path.cpp:1159
LLVM_ABI const char * const_data() const
Get a const view of the data.
Definition Path.cpp:1169
LLVM_ABI char * data() const
Definition Path.cpp:1164
LLVM_ABI const_iterator & operator++()
Definition Path.cpp:242
LLVM_ABI bool operator==(const const_iterator &RHS) const
Definition Path.cpp:289
LLVM_ABI ptrdiff_t operator-(const const_iterator &RHS) const
Difference in bytes between this and RHS.
Definition Path.cpp:293
LLVM_ABI bool operator==(const reverse_iterator &RHS) const
Definition Path.cpp:339
LLVM_ABI ptrdiff_t operator-(const reverse_iterator &RHS) const
Difference in bytes between this and RHS.
Definition Path.cpp:344
LLVM_ABI reverse_iterator & operator++()
Definition Path.cpp:314
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ C
The default llvm calling convention, compatible with C.
value_type read(const void *memory, endianness endian)
Read a value of a particular endianness from memory.
LLVM_ABI bool is_regular_file(const basic_file_status &status)
Does status represent a regular file?
Definition Path.cpp:1104
LLVM_ABI bool is_symlink_file(const basic_file_status &status)
Does status represent a symlink file?
Definition Path.cpp:1116
std::error_code openFileForReadWrite(const Twine &Name, int &ResultFD, CreationDisposition Disp, OpenFlags Flags, unsigned Mode=0666)
Opens the file with the given name in a write-only or read-write mode, returning its open file descri...
LLVM_ABI std::error_code rename(const Twine &from, const Twine &to)
Rename from to to.
LLVM_ABI Error readNativeFileToEOF(file_t FileHandle, SmallVectorImpl< char > &Buffer, ssize_t ChunkSize=DefaultReadChunkSize)
Reads from FileHandle until EOF, appending to Buffer in chunks of size ChunkSize.
Definition Path.cpp:1174
LLVM_ABI ErrorOr< perms > getPermissions(const Twine &Path)
Get file permissions.
Definition Path.cpp:1151
LLVM_ABI std::error_code getPotentiallyUniqueFileName(const Twine &Model, SmallVectorImpl< char > &ResultPath)
Get a unique name, not currently exisiting in the filesystem.
Definition Path.cpp:942
LLVM_ABI std::error_code access(const Twine &Path, AccessMode Mode)
Can the file be accessed?
LLVM_ABI bool is_other(const basic_file_status &status)
Does this status represent something that exists but is not a directory or regular file?
Definition Path.cpp:1128
LLVM_ABI std::error_code getPotentiallyUniqueTempFileName(const Twine &Prefix, StringRef Suffix, SmallVectorImpl< char > &ResultPath)
Get a unique temporary file name, not currently exisiting in the filesystem.
Definition Path.cpp:949
LLVM_ABI Expected< size_t > readNativeFile(file_t FileHandle, MutableArrayRef< char > Buf)
Reads Buf.size() bytes from FileHandle into Buf.
LLVM_ABI bool exists(const basic_file_status &status)
Does file exist?
Definition Path.cpp:1077
@ OF_Delete
The returned handle can be used for deleting the file.
file_type
An enumeration for the file system's view of the type.
LLVM_ABI std::error_code getUniqueID(const Twine Path, UniqueID &Result)
Definition Path.cpp:836
LLVM_ABI std::error_code createUniqueFile(const Twine &Model, int &ResultFD, SmallVectorImpl< char > &ResultPath, OpenFlags Flags=OF_None, unsigned Mode=all_read|all_write)
Create a uniquely named file.
Definition Path.cpp:871
LLVM_ABI std::error_code remove(const Twine &path, bool IgnoreNonExisting=true)
Remove path.
@ CD_CreateAlways
CD_CreateAlways - When opening a file:
@ CD_CreateNew
CD_CreateNew - When opening a file:
LLVM_ABI void createUniquePath(const Twine &Model, SmallVectorImpl< char > &ResultPath, bool MakeAbsolute)
Create a potentially unique file name but does not create it.
Definition Path.cpp:845
std::error_code openFileForWrite(const Twine &Name, int &ResultFD, CreationDisposition Disp=CD_CreateAlways, OpenFlags Flags=OF_None, unsigned Mode=0666)
Opens the file with the given name in a write-only or read-write mode, returning its open file descri...
LLVM_ABI std::error_code create_directories(const Twine &path, bool IgnoreExisting=true, perms Perms=owner_all|group_all)
Create all the non-existent directories in path.
Definition Path.cpp:967
LLVM_ABI bool status_known(const basic_file_status &s)
Is status available?
Definition Path.cpp:1081
LLVM_ABI std::error_code createTemporaryFile(const Twine &Prefix, StringRef Suffix, int &ResultFD, SmallVectorImpl< char > &ResultPath, OpenFlags Flags=OF_None)
Create a file in the system temporary directory.
Definition Path.cpp:912
LLVM_ABI file_type get_file_type(const Twine &Path, bool Follow=true)
Does status represent a directory?
Definition Path.cpp:1085
LLVM_ABI std::error_code make_absolute(SmallVectorImpl< char > &path)
Make path an absolute path.
Definition Path.cpp:955
LLVM_ABI std::error_code copy_file(const Twine &From, const Twine &To)
Copy the contents of From to To.
Definition Path.cpp:1016
LLVM_ABI std::error_code createUniqueDirectory(const Twine &Prefix, SmallVectorImpl< char > &ResultPath)
Definition Path.cpp:934
LLVM_ABI std::error_code current_path(SmallVectorImpl< char > &result)
Get the current path.
LLVM_ABI std::error_code status(const Twine &path, file_status &result, bool follow=true)
Get file status as if by POSIX stat().
LLVM_ABI std::error_code create_directory(const Twine &path, bool IgnoreExisting=true, perms Perms=owner_all|group_all)
Create the directory in path.
LLVM_ABI std::error_code openFileForRead(const Twine &Name, int &ResultFD, OpenFlags Flags=OF_None, SmallVectorImpl< char > *RealPath=nullptr)
Opens the file with the given name in a read-only mode, returning its open file descriptor.
LLVM_ABI ErrorOr< MD5::MD5Result > md5_contents(int FD)
Compute an MD5 hash of a file's contents.
Definition Path.cpp:1047
static std::error_code copy_file_internal(int ReadFD, int WriteFD)
Definition Path.cpp:991
LLVM_ABI bool is_directory(const basic_file_status &status)
Does status represent a directory?
Definition Path.cpp:1092
LLVM_ABI StringRef get_separator(Style style=Style::native)
Return the preferred separator for this platform.
Definition Path.cpp:609
LLVM_ABI StringRef root_path(StringRef path LLVM_LIFETIME_BOUND, Style style=Style::native)
Get root path.
Definition Path.cpp:348
LLVM_ABI void remove_filename(SmallVectorImpl< char > &path, Style style=Style::native)
Remove the last component from path unless it is the root dir.
Definition Path.cpp:474
LLVM_ABI bool has_relative_path(const Twine &path, Style style=Style::native)
Has relative path?
Definition Path.cpp:636
LLVM_ABI StringRef stem(StringRef path LLVM_LIFETIME_BOUND, Style style=Style::native)
Get stem.
Definition Path.cpp:579
LLVM_ABI bool has_root_name(const Twine &path, Style style=Style::native)
Has root name?
Definition Path.cpp:615
LLVM_ABI void replace_extension(SmallVectorImpl< char > &path, const Twine &extension, Style style=Style::native)
Replace the file extension of path with extension.
Definition Path.cpp:480
LLVM_ABI const_iterator begin(StringRef path LLVM_LIFETIME_BOUND, Style style=Style::native)
Get begin iterator over path.
Definition Path.cpp:226
LLVM_ABI bool remove_dots(SmallVectorImpl< char > &path, bool remove_dot_dot=false, Style style=Style::native)
In-place remove any '.
Definition Path.cpp:764
LLVM_ABI bool has_root_path(const Twine &path, Style style=Style::native)
Has root path?
Definition Path.cpp:629
constexpr bool is_style_posix(Style S)
Check if S uses POSIX path rules.
LLVM_ABI StringRef parent_path(StringRef path LLVM_LIFETIME_BOUND, Style style=Style::native)
Get parent path.
Definition Path.cpp:467
LLVM_ABI bool has_parent_path(const Twine &path, Style style=Style::native)
Has parent path?
Definition Path.cpp:650
void make_preferred(SmallVectorImpl< char > &path, Style style=Style::native)
For Windows path styles, convert path to use the preferred path separators.
LLVM_ABI bool is_relative(const Twine &path, Style style=Style::native)
Is path relative?
Definition Path.cpp:699
LLVM_ABI void system_temp_directory(bool erasedOnReboot, SmallVectorImpl< char > &result)
Get the typical temporary directory for the system, e.g., "/var/tmp" or "C:/TEMP".
LLVM_ABI bool has_extension(const Twine &path, Style style=Style::native)
Has extension?
Definition Path.cpp:664
LLVM_ABI void make_absolute(const Twine ¤t_directory, SmallVectorImpl< char > &path)
Make path an absolute path.
Definition Path.cpp:703
LLVM_ABI bool is_absolute_gnu(const Twine &path, Style style=Style::native)
Is path absolute using GNU rules?
Definition Path.cpp:681
LLVM_ABI StringRef filename(StringRef path LLVM_LIFETIME_BOUND, Style style=Style::native)
Get filename.
Definition Path.cpp:577
LLVM_ABI StringRef remove_leading_dotslash(StringRef path LLVM_LIFETIME_BOUND, Style style=Style::native)
Remove redundant leading "./" pieces and consecutive separators.
LLVM_ABI std::string convert_to_slash(StringRef path, Style style=Style::native)
Replaces backslashes with slashes if Windows.
Definition Path.cpp:568
LLVM_ABI bool is_absolute(const Twine &path, Style style=Style::native)
Is path absolute?
Definition Path.cpp:671
LLVM_ABI bool has_stem(const Twine &path, Style style=Style::native)
Has stem?
Definition Path.cpp:657
constexpr bool is_style_windows(Style S)
Check if S uses Windows path rules.
LLVM_ABI StringRef root_name(StringRef path LLVM_LIFETIME_BOUND, Style style=Style::native)
Get root name.
Definition Path.cpp:373
LLVM_ABI StringRef root_directory(StringRef path LLVM_LIFETIME_BOUND, Style style=Style::native)
Get root directory.
Definition Path.cpp:390
LLVM_ABI bool replace_path_prefix(SmallVectorImpl< char > &Path, StringRef OldPrefix, StringRef NewPrefix, Style style=Style::native)
Replace matching path prefix with another path.
Definition Path.cpp:518
LLVM_ABI void append(SmallVectorImpl< char > &path, const Twine &a, const Twine &b="", const Twine &c="", const Twine &d="")
Append to path.
Definition Path.cpp:456
LLVM_ABI StringRef extension(StringRef path LLVM_LIFETIME_BOUND, Style style=Style::native)
Get extension.
Definition Path.cpp:590
LLVM_ABI reverse_iterator rend(StringRef path LLVM_LIFETIME_BOUND)
Get reverse end iterator over path.
LLVM_ABI reverse_iterator rbegin(StringRef path LLVM_LIFETIME_BOUND, Style style=Style::native)
Get reverse begin iterator over path.
LLVM_ABI bool has_filename(const Twine &path, Style style=Style::native)
Has filename?
Definition Path.cpp:643
LLVM_ABI const_iterator end(StringRef path LLVM_LIFETIME_BOUND)
Get end iterator over path.
Definition Path.cpp:235
LLVM_ABI bool home_directory(SmallVectorImpl< char > &result)
Get the user's home directory.
static bool starts_with(StringRef Path, StringRef Prefix, Style style=Style::native)
Definition Path.cpp:499
LLVM_ABI bool is_separator(char value, Style style=Style::native)
Check whether the given char is a path separator on the host OS.
Definition Path.cpp:601
LLVM_ABI StringRef relative_path(StringRef path LLVM_LIFETIME_BOUND, Style style=Style::native)
Get relative path.
Definition Path.cpp:413
LLVM_ABI bool has_root_directory(const Twine &path, Style style=Style::native)
Has root directory?
Definition Path.cpp:622
LLVM_ABI void DontRemoveFileOnSignal(StringRef Filename)
This function removes a file from the list of files to be removed on signal delivery.
LLVM_ABI bool RemoveFileOnSignal(StringRef Filename, std::string *ErrMsg=nullptr)
This function registers signal handlers to ensure that if a signal gets delivered that the named file...
This is an optimization pass for GlobalISel generic memory operations.
char toLower(char x)
Returns the corresponding lowercase character if x is uppercase.
detail::scope_exit< std::decay_t< Callable > > make_scope_exit(Callable &&F)
@ no_such_file_or_directory
@ operation_not_permitted
MutableArrayRef(T &OneElt) -> MutableArrayRef< T >
void replace(R &&Range, const T &OldValue, const T &NewValue)
Provide wrappers to std::replace which take ranges instead of having to pass begin/end explicitly.
ArrayRef(const T &OneElt) -> ArrayRef< T >
OutputIt copy(R &&Range, OutputIt Out)
LLVM_ABI Error write(MCStreamer &Out, ArrayRef< std::string > Inputs, OnCuIndexOverflow OverflowOptValue, Dwarf64StrOffsetsPromotion StrOffsetsOptValue)
LLVM_ABI Error errorCodeToError(std::error_code EC)
Helper for converting an std::error_code to a Error.
std::error_code errnoAsErrorCode()
Helper to get errno as an std::error_code.
void consumeError(Error Err)
Consume a Error without doing anything.