LLVM 22.0.0git
FileSystem.h
Go to the documentation of this file.
1//===- llvm/Support/FileSystem.h - File System OS Concept -------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file declares the llvm::sys::fs namespace. It is designed after
10// TR2/boost filesystem (v3), but modified to remove exception handling and the
11// path class.
12//
13// All functions return an error_code and their actual work via the last out
14// argument. The out argument is defined if and only if errc::success is
15// returned. A function may return any error code in the generic or system
16// category. However, they shall be equivalent to any error conditions listed
17// in each functions respective documentation if the condition applies. [ note:
18// this does not guarantee that error_code will be in the set of explicitly
19// listed codes, but it does guarantee that if any of the explicitly listed
20// errors occur, the correct error_code will be used ]. All functions may
21// return errc::not_enough_memory if there is not enough memory to complete the
22// operation.
23//
24//===----------------------------------------------------------------------===//
25
26#ifndef LLVM_SUPPORT_FILESYSTEM_H
27#define LLVM_SUPPORT_FILESYSTEM_H
28
30#include "llvm/ADT/StringRef.h"
31#include "llvm/ADT/Twine.h"
32#include "llvm/Config/llvm-config.h"
33#include "llvm/Support/Chrono.h"
35#include "llvm/Support/Error.h"
39#include "llvm/Support/MD5.h"
40#include <cassert>
41#include <cstdint>
42#include <ctime>
43#include <memory>
44#include <string>
45#include <system_error>
46#include <vector>
47
48namespace llvm {
49namespace sys {
50namespace fs {
51
52#if defined(_WIN32)
53// A Win32 HANDLE is a typedef of void*
54using file_t = void *;
55#else
56using file_t = int;
57#endif
58
59LLVM_ABI extern const file_t kInvalidFile;
60
61/// An enumeration for the file system's view of the type.
62enum class file_type {
73};
74
75/// space_info - Self explanatory.
76struct space_info {
80};
81
82enum perms {
84 owner_read = 0400,
86 owner_exe = 0100,
90 group_exe = 010,
102 sticky_bit = 01000,
104 perms_not_known = 0xFFFF
106
107// Helper functions so that you can use & and | to manipulate perms bits:
109 return static_cast<perms>(static_cast<unsigned short>(l) |
110 static_cast<unsigned short>(r));
111}
113 return static_cast<perms>(static_cast<unsigned short>(l) &
114 static_cast<unsigned short>(r));
115}
116inline perms &operator|=(perms &l, perms r) {
117 l = l | r;
118 return l;
119}
120inline perms &operator&=(perms &l, perms r) {
121 l = l & r;
122 return l;
123}
125 // Avoid UB by explicitly truncating the (unsigned) ~ result.
126 return static_cast<perms>(
127 static_cast<unsigned short>(~static_cast<unsigned short>(x)));
128}
129
130/// Represents the result of a call to directory_iterator::status(). This is a
131/// subset of the information returned by a regular sys::fs::status() call, and
132/// represents the information provided by Windows FileFirstFile/FindNextFile.
134protected:
135 #if defined(LLVM_ON_UNIX)
136 time_t fs_st_atime = 0;
137 time_t fs_st_mtime = 0;
140 uid_t fs_st_uid = 0;
141 gid_t fs_st_gid = 0;
142 off_t fs_st_size = 0;
143 #elif defined (_WIN32)
144 uint32_t LastAccessedTimeHigh = 0;
145 uint32_t LastAccessedTimeLow = 0;
146 uint32_t LastWriteTimeHigh = 0;
147 uint32_t LastWriteTimeLow = 0;
148 uint32_t FileSizeHigh = 0;
149 uint32_t FileSizeLow = 0;
150 #endif
153
154public:
155 basic_file_status() = default;
156
158
159 #if defined(LLVM_ON_UNIX)
161 uint32_t ATimeNSec, time_t MTime, uint32_t MTimeNSec,
162 uid_t UID, gid_t GID, off_t Size)
163 : fs_st_atime(ATime), fs_st_mtime(MTime),
164 fs_st_atime_nsec(ATimeNSec), fs_st_mtime_nsec(MTimeNSec),
165 fs_st_uid(UID), fs_st_gid(GID),
167#elif defined(_WIN32)
168 basic_file_status(file_type Type, perms Perms, uint32_t LastAccessTimeHigh,
169 uint32_t LastAccessTimeLow, uint32_t LastWriteTimeHigh,
170 uint32_t LastWriteTimeLow, uint32_t FileSizeHigh,
171 uint32_t FileSizeLow)
172 : LastAccessedTimeHigh(LastAccessTimeHigh),
173 LastAccessedTimeLow(LastAccessTimeLow),
174 LastWriteTimeHigh(LastWriteTimeHigh),
175 LastWriteTimeLow(LastWriteTimeLow), FileSizeHigh(FileSizeHigh),
176 FileSizeLow(FileSizeLow), Type(Type), Perms(Perms) {}
177 #endif
178
179 // getters
180 file_type type() const { return Type; }
181 perms permissions() const { return Perms; }
182
183 /// The file access time as reported from the underlying file system.
184 ///
185 /// Also see comments on \c getLastModificationTime() related to the precision
186 /// of the returned value.
188
189 /// The file modification time as reported from the underlying file system.
190 ///
191 /// The returned value allows for nanosecond precision but the actual
192 /// resolution is an implementation detail of the underlying file system.
193 /// There is no guarantee for what kind of resolution you can expect, the
194 /// resolution can differ across platforms and even across mountpoints on the
195 /// same machine.
197
198#if defined(LLVM_ON_UNIX)
199 uint32_t getUser() const { return fs_st_uid; }
200 uint32_t getGroup() const { return fs_st_gid; }
201 uint64_t getSize() const { return fs_st_size; }
202#elif defined(_WIN32)
203 uint32_t getUser() const {
204 return 9999; // Not applicable to Windows, so...
205 }
206
207 uint32_t getGroup() const {
208 return 9999; // Not applicable to Windows, so...
209 }
210
211 uint64_t getSize() const {
212 return (uint64_t(FileSizeHigh) << 32) + FileSizeLow;
213 }
214#endif
215
216 // setters
217 void type(file_type v) { Type = v; }
218 void permissions(perms p) { Perms = p; }
219};
220
221/// Represents the result of a call to sys::fs::status().
224
225#if defined(LLVM_ON_UNIX)
226 dev_t fs_st_dev = 0;
227 nlink_t fs_st_nlinks = 0;
228 ino_t fs_st_ino = 0;
229#elif defined(_WIN32)
230 uint32_t NumLinks = 0;
231 uint32_t VolumeSerialNumber = 0;
232 uint64_t PathHash = 0;
233#endif
234
235public:
236 file_status() = default;
237
239
240 #if defined(LLVM_ON_UNIX)
241 file_status(file_type Type, perms Perms, dev_t Dev, nlink_t Links, ino_t Ino,
242 time_t ATime, uint32_t ATimeNSec,
243 time_t MTime, uint32_t MTimeNSec,
244 uid_t UID, gid_t GID, off_t Size)
245 : basic_file_status(Type, Perms, ATime, ATimeNSec, MTime, MTimeNSec,
246 UID, GID, Size),
247 fs_st_dev(Dev), fs_st_nlinks(Links), fs_st_ino(Ino) {}
248 #elif defined(_WIN32)
250 uint32_t LastAccessTimeHigh, uint32_t LastAccessTimeLow,
251 uint32_t LastWriteTimeHigh, uint32_t LastWriteTimeLow,
252 uint32_t VolumeSerialNumber, uint32_t FileSizeHigh,
253 uint32_t FileSizeLow, uint64_t PathHash)
254 : basic_file_status(Type, Perms, LastAccessTimeHigh, LastAccessTimeLow,
255 LastWriteTimeHigh, LastWriteTimeLow, FileSizeHigh,
256 FileSizeLow),
257 NumLinks(LinkCount), VolumeSerialNumber(VolumeSerialNumber),
258 PathHash(PathHash) {}
259 #endif
260
263};
264
265/// @}
266/// @name Physical Operators
267/// @{
268
269/// Make \a path an absolute path.
270///
271/// Makes \a path absolute using the \a current_directory if it is not already.
272/// An empty \a path will result in the \a current_directory.
273///
274/// /absolute/path => /absolute/path
275/// relative/../path => <current-directory>/relative/../path
276///
277/// @param path A path that is modified to be an absolute path.
278LLVM_ABI void make_absolute(const Twine &current_directory,
280
281/// Make \a path an absolute path.
282///
283/// Makes \a path absolute using the current directory if it is not already. An
284/// empty \a path will result in the current directory.
285///
286/// /absolute/path => /absolute/path
287/// relative/../path => <current-directory>/relative/../path
288///
289/// @param path A path that is modified to be an absolute path.
290/// @returns errc::success if \a path has been made absolute, otherwise a
291/// platform-specific error_code.
292LLVM_ABI std::error_code make_absolute(SmallVectorImpl<char> &path);
293
294/// Create all the non-existent directories in path.
295///
296/// @param path Directories to create.
297/// @returns errc::success if is_directory(path), otherwise a platform
298/// specific error_code. If IgnoreExisting is false, also returns
299/// error if the directory already existed.
300LLVM_ABI std::error_code
301create_directories(const Twine &path, bool IgnoreExisting = true,
302 perms Perms = owner_all | group_all);
303
304/// Create the directory in path.
305///
306/// @param path Directory to create.
307/// @returns errc::success if is_directory(path), otherwise a platform
308/// specific error_code. If IgnoreExisting is false, also returns
309/// error if the directory already existed.
310LLVM_ABI std::error_code create_directory(const Twine &path,
311 bool IgnoreExisting = true,
312 perms Perms = owner_all | group_all);
313
314/// Create a link from \a from to \a to.
315///
316/// The link may be a soft or a hard link, depending on the platform. The caller
317/// may not assume which one. Currently on windows it creates a hard link since
318/// soft links require extra privileges. On unix, it creates a soft link since
319/// hard links don't work on SMB file systems.
320///
321/// @param to The path to hard link to.
322/// @param from The path to hard link from. This is created.
323/// @returns errc::success if the link was created, otherwise a platform
324/// specific error_code.
325LLVM_ABI std::error_code create_link(const Twine &to, const Twine &from);
326
327/// Create a hard link from \a from to \a to, or return an error.
328///
329/// @param to The path to hard link to.
330/// @param from The path to hard link from. This is created.
331/// @returns errc::success if the link was created, otherwise a platform
332/// specific error_code.
333LLVM_ABI std::error_code create_hard_link(const Twine &to, const Twine &from);
334
335/// Collapse all . and .. patterns, resolve all symlinks, and optionally
336/// expand ~ expressions to the user's home directory.
337///
338/// @param path The path to resolve.
339/// @param output The location to store the resolved path.
340/// @param expand_tilde If true, resolves ~ expressions to the user's home
341/// directory.
342LLVM_ABI std::error_code real_path(const Twine &path,
343 SmallVectorImpl<char> &output,
344 bool expand_tilde = false);
345
346/// Expands ~ expressions to the user's home directory. On Unix ~user
347/// directories are resolved as well.
348///
349/// @param path The path to resolve.
351
352/// Get the current path.
353///
354/// @param result Holds the current path on return.
355/// @returns errc::success if the current path has been stored in result,
356/// otherwise a platform-specific error_code.
358
359/// Set the current path.
360///
361/// @param path The path to set.
362/// @returns errc::success if the current path was successfully set,
363/// otherwise a platform-specific error_code.
364LLVM_ABI std::error_code set_current_path(const Twine &path);
365
366/// Remove path. Equivalent to POSIX remove().
367///
368/// @param path Input path.
369/// @returns errc::success if path has been removed or didn't exist, otherwise a
370/// platform-specific error code. If IgnoreNonExisting is false, also
371/// returns error if the file didn't exist.
372LLVM_ABI std::error_code remove(const Twine &path,
373 bool IgnoreNonExisting = true);
374
375/// Recursively delete a directory.
376///
377/// @param path Input path.
378/// @returns errc::success if path has been removed or didn't exist, otherwise a
379/// platform-specific error code.
380LLVM_ABI std::error_code remove_directories(const Twine &path,
381 bool IgnoreErrors = true);
382
383/// Rename \a from to \a to.
384///
385/// Files are renamed as if by POSIX rename(), except that on Windows there may
386/// be a short interval of time during which the destination file does not
387/// exist.
388///
389/// @param from The path to rename from.
390/// @param to The path to rename to. This is created.
391LLVM_ABI std::error_code rename(const Twine &from, const Twine &to);
392
393/// Copy the contents of \a From to \a To.
394///
395/// @param From The path to copy from.
396/// @param To The path to copy to. This is created.
397LLVM_ABI std::error_code copy_file(const Twine &From, const Twine &To);
398
399/// Copy the contents of \a From to \a To.
400///
401/// @param From The path to copy from.
402/// @param ToFD The open file descriptor of the destination file.
403LLVM_ABI std::error_code copy_file(const Twine &From, int ToFD);
404
405/// Resize path to size. File is resized as if by POSIX truncate().
406///
407/// @param FD Input file descriptor.
408/// @param Size Size to resize to.
409/// @returns errc::success if \a path has been resized to \a size, otherwise a
410/// platform-specific error_code.
411LLVM_ABI std::error_code resize_file(int FD, uint64_t Size);
412
413/// Resize \p FD to \p Size before mapping \a mapped_file_region::readwrite. On
414/// non-Windows, this calls \a resize_file(). On Windows, this is a no-op,
415/// since the subsequent mapping (via \c CreateFileMapping) automatically
416/// extends the file.
417inline std::error_code resize_file_before_mapping_readwrite(int FD,
418 uint64_t Size) {
419#ifdef _WIN32
420 (void)FD;
421 (void)Size;
422 return std::error_code();
423#else
424 return resize_file(FD, Size);
425#endif
426}
427
428/// Compute an MD5 hash of a file's contents.
429///
430/// @param FD Input file descriptor.
431/// @returns An MD5Result with the hash computed, if successful, otherwise a
432/// std::error_code.
434
435/// Version of compute_md5 that doesn't require an open file descriptor.
437
438/// @}
439/// @name Physical Observers
440/// @{
441
442/// Does file exist?
443///
444/// @param status A basic_file_status previously returned from stat.
445/// @returns True if the file represented by status exists, false if it does
446/// not.
447LLVM_ABI bool exists(const basic_file_status &status);
448
449enum class AccessMode { Exist, Write, Execute };
450
451/// Can the file be accessed?
452///
453/// @param Path Input path.
454/// @returns errc::success if the path can be accessed, otherwise a
455/// platform-specific error_code.
456LLVM_ABI std::error_code access(const Twine &Path, AccessMode Mode);
457
458/// Does file exist?
459///
460/// @param Path Input path.
461/// @returns True if it exists, false otherwise.
462inline bool exists(const Twine &Path) {
463 return !access(Path, AccessMode::Exist);
464}
465
466/// Can we execute this file?
467///
468/// @param Path Input path.
469/// @returns True if we can execute it, false otherwise.
470LLVM_ABI bool can_execute(const Twine &Path);
471
472/// Can we write this file?
473///
474/// @param Path Input path.
475/// @returns True if we can write to it, false otherwise.
476inline bool can_write(const Twine &Path) {
477 return !access(Path, AccessMode::Write);
478}
479
480/// Do file_status's represent the same thing?
481///
482/// @param A Input file_status.
483/// @param B Input file_status.
484///
485/// assert(status_known(A) || status_known(B));
486///
487/// @returns True if A and B both represent the same file system entity, false
488/// otherwise.
490
491/// Do paths represent the same thing?
492///
493/// assert(status_known(A) || status_known(B));
494///
495/// @param A Input path A.
496/// @param B Input path B.
497/// @param result Set to true if stat(A) and stat(B) have the same device and
498/// inode (or equivalent).
499/// @returns errc::success if result has been successfully set, otherwise a
500/// platform-specific error_code.
501LLVM_ABI std::error_code equivalent(const Twine &A, const Twine &B,
502 bool &result);
503
504/// Simpler version of equivalent for clients that don't need to
505/// differentiate between an error and false.
506inline bool equivalent(const Twine &A, const Twine &B) {
507 bool result;
508 return !equivalent(A, B, result) && result;
509}
510
511/// Is the file mounted on a local filesystem?
512///
513/// @param path Input path.
514/// @param result Set to true if \a path is on fixed media such as a hard disk,
515/// false if it is not.
516/// @returns errc::success if result has been successfully set, otherwise a
517/// platform specific error_code.
518LLVM_ABI std::error_code is_local(const Twine &path, bool &result);
519
520/// Version of is_local accepting an open file descriptor.
521LLVM_ABI std::error_code is_local(int FD, bool &result);
522
523/// Simpler version of is_local for clients that don't need to
524/// differentiate between an error and false.
525inline bool is_local(const Twine &Path) {
526 bool Result;
527 return !is_local(Path, Result) && Result;
528}
529
530/// Simpler version of is_local accepting an open file descriptor for
531/// clients that don't need to differentiate between an error and false.
532inline bool is_local(int FD) {
533 bool Result;
534 return !is_local(FD, Result) && Result;
535}
536
537/// Does status represent a directory?
538///
539/// @param Path The path to get the type of.
540/// @param Follow For symbolic links, indicates whether to return the file type
541/// of the link itself, or of the target.
542/// @returns A value from the file_type enumeration indicating the type of file.
543LLVM_ABI file_type get_file_type(const Twine &Path, bool Follow = true);
544
545/// Does status represent a directory?
546///
547/// @param status A basic_file_status previously returned from status.
548/// @returns status.type() == file_type::directory_file.
549LLVM_ABI bool is_directory(const basic_file_status &status);
550
551/// Is path a directory?
552///
553/// @param path Input path.
554/// @param result Set to true if \a path is a directory (after following
555/// symlinks, false if it is not. Undefined otherwise.
556/// @returns errc::success if result has been successfully set, otherwise a
557/// platform-specific error_code.
558LLVM_ABI std::error_code is_directory(const Twine &path, bool &result);
559
560/// Simpler version of is_directory for clients that don't need to
561/// differentiate between an error and false.
562inline bool is_directory(const Twine &Path) {
563 bool Result;
564 return !is_directory(Path, Result) && Result;
565}
566
567/// Does status represent a regular file?
568///
569/// @param status A basic_file_status previously returned from status.
570/// @returns status_known(status) && status.type() == file_type::regular_file.
571LLVM_ABI bool is_regular_file(const basic_file_status &status);
572
573/// Is path a regular file?
574///
575/// @param path Input path.
576/// @param result Set to true if \a path is a regular file (after following
577/// symlinks), false if it is not. Undefined otherwise.
578/// @returns errc::success if result has been successfully set, otherwise a
579/// platform-specific error_code.
580LLVM_ABI std::error_code is_regular_file(const Twine &path, bool &result);
581
582/// Simpler version of is_regular_file for clients that don't need to
583/// differentiate between an error and false.
584inline bool is_regular_file(const Twine &Path) {
585 bool Result;
586 if (is_regular_file(Path, Result))
587 return false;
588 return Result;
589}
590
591/// Does status represent a symlink file?
592///
593/// @param status A basic_file_status previously returned from status.
594/// @returns status_known(status) && status.type() == file_type::symlink_file.
595LLVM_ABI bool is_symlink_file(const basic_file_status &status);
596
597/// Is path a symlink file?
598///
599/// @param path Input path.
600/// @param result Set to true if \a path is a symlink file, false if it is not.
601/// Undefined otherwise.
602/// @returns errc::success if result has been successfully set, otherwise a
603/// platform-specific error_code.
604LLVM_ABI std::error_code is_symlink_file(const Twine &path, bool &result);
605
606/// Simpler version of is_symlink_file for clients that don't need to
607/// differentiate between an error and false.
608inline bool is_symlink_file(const Twine &Path) {
609 bool Result;
610 if (is_symlink_file(Path, Result))
611 return false;
612 return Result;
613}
614
615/// Does this status represent something that exists but is not a
616/// directory or regular file?
617///
618/// @param status A basic_file_status previously returned from status.
619/// @returns exists(s) && !is_regular_file(s) && !is_directory(s)
620LLVM_ABI bool is_other(const basic_file_status &status);
621
622/// Is path something that exists but is not a directory,
623/// regular file, or symlink?
624///
625/// @param path Input path.
626/// @param result Set to true if \a path exists, but is not a directory, regular
627/// file, or a symlink, false if it does not. Undefined otherwise.
628/// @returns errc::success if result has been successfully set, otherwise a
629/// platform-specific error_code.
630LLVM_ABI std::error_code is_other(const Twine &path, bool &result);
631
632/// Get file status as if by POSIX stat().
633///
634/// @param path Input path.
635/// @param result Set to the file status.
636/// @param follow When true, follows symlinks. Otherwise, the symlink itself is
637/// statted.
638/// @returns errc::success if result has been successfully set, otherwise a
639/// platform-specific error_code.
640LLVM_ABI std::error_code status(const Twine &path, file_status &result,
641 bool follow = true);
642
643/// A version for when a file descriptor is already available.
644LLVM_ABI std::error_code status(int FD, file_status &Result);
645
646#ifdef _WIN32
647/// A version for when a file descriptor is already available.
648LLVM_ABI std::error_code status(file_t FD, file_status &Result);
649#endif
650
651/// Get file creation mode mask of the process.
652///
653/// @returns Mask reported by umask(2)
654/// @note There is no umask on Windows. This function returns 0 always
655/// on Windows. This function does not return an error_code because
656/// umask(2) never fails. It is not thread safe.
658
659/// Set file permissions.
660///
661/// @param Path File to set permissions on.
662/// @param Permissions New file permissions.
663/// @returns errc::success if the permissions were successfully set, otherwise
664/// a platform-specific error_code.
665/// @note On Windows, all permissions except *_write are ignored. Using any of
666/// owner_write, group_write, or all_write will make the file writable.
667/// Otherwise, the file will be marked as read-only.
668LLVM_ABI std::error_code setPermissions(const Twine &Path, perms Permissions);
669
670/// Vesion of setPermissions accepting a file descriptor.
671/// TODO Delete the path based overload once we implement the FD based overload
672/// on Windows.
673LLVM_ABI std::error_code setPermissions(int FD, perms Permissions);
674
675/// Get file permissions.
676///
677/// @param Path File to get permissions from.
678/// @returns the permissions if they were successfully retrieved, otherwise a
679/// platform-specific error_code.
680/// @note On Windows, if the file does not have the FILE_ATTRIBUTE_READONLY
681/// attribute, all_all will be returned. Otherwise, all_read | all_exe
682/// will be returned.
684
685/// Get file size.
686///
687/// @param Path Input path.
688/// @param Result Set to the size of the file in \a Path.
689/// @returns errc::success if result has been successfully set, otherwise a
690/// platform-specific error_code.
691inline std::error_code file_size(const Twine &Path, uint64_t &Result) {
693 std::error_code EC = status(Path, Status);
694 if (EC)
695 return EC;
696 Result = Status.getSize();
697 return std::error_code();
698}
699
700/// Set the file modification and access time.
701///
702/// @returns errc::success if the file times were successfully set, otherwise a
703/// platform-specific error_code or errc::function_not_supported on
704/// platforms where the functionality isn't available.
705LLVM_ABI std::error_code
707 TimePoint<> ModificationTime);
708
709/// Simpler version that sets both file modification and access time to the same
710/// time.
711inline std::error_code setLastAccessAndModificationTime(int FD,
712 TimePoint<> Time) {
713 return setLastAccessAndModificationTime(FD, Time, Time);
714}
715
716/// Is status available?
717///
718/// @param s Input file status.
719/// @returns True if status() != status_error.
720LLVM_ABI bool status_known(const basic_file_status &s);
721
722/// Is status available?
723///
724/// @param path Input path.
725/// @param result Set to true if status() != status_error.
726/// @returns errc::success if result has been successfully set, otherwise a
727/// platform-specific error_code.
728LLVM_ABI std::error_code status_known(const Twine &path, bool &result);
729
730enum CreationDisposition : unsigned {
731 /// CD_CreateAlways - When opening a file:
732 /// * If it already exists, truncate it.
733 /// * If it does not already exist, create a new file.
735
736 /// CD_CreateNew - When opening a file:
737 /// * If it already exists, fail.
738 /// * If it does not already exist, create a new file.
740
741 /// CD_OpenExisting - When opening a file:
742 /// * If it already exists, open the file with the offset set to 0.
743 /// * If it does not already exist, fail.
745
746 /// CD_OpenAlways - When opening a file:
747 /// * If it already exists, open the file with the offset set to 0.
748 /// * If it does not already exist, create a new file.
750};
751
752enum FileAccess : unsigned {
755};
756
757enum OpenFlags : unsigned {
759
760 /// The file should be opened in text mode on platforms like z/OS that make
761 /// this distinction.
763
764 /// The file should use a carriage linefeed '\r\n'. This flag should only be
765 /// used with OF_Text. Only makes a difference on Windows.
767
768 /// The file should be opened in text mode and use a carriage linefeed '\r\n'.
769 /// This flag has the same functionality as OF_Text on z/OS but adds a
770 /// carriage linefeed on Windows.
772
773 /// The file should be opened in append mode.
775
776 /// The returned handle can be used for deleting the file. Only makes a
777 /// difference on windows.
779
780 /// When a child process is launched, this file should remain open in the
781 /// child process.
783
784 /// Force files Atime to be updated on access. Only makes a difference on
785 /// Windows.
787};
788
789/// Create a potentially unique file name but does not create it.
790///
791/// Generates a unique path suitable for a temporary file but does not
792/// open or create the file. The name is based on \a Model with '%'
793/// replaced by a random char in [0-9a-f]. If \a MakeAbsolute is true
794/// then the system's temp directory is prepended first. If \a MakeAbsolute
795/// is false the current directory will be used instead.
796///
797/// This function does not check if the file exists. If you want to be sure
798/// that the file does not yet exist, you should use enough '%' characters
799/// in your model to ensure this. Each '%' gives 4-bits of entropy so you can
800/// use 32 of them to get 128 bits of entropy.
801///
802/// Example: clang-%%-%%-%%-%%-%%.s => clang-a0-b1-c2-d3-e4.s
803///
804/// @param Model Name to base unique path off of.
805/// @param ResultPath Set to the file's path.
806/// @param MakeAbsolute Whether to use the system temp directory.
807LLVM_ABI void createUniquePath(const Twine &Model,
808 SmallVectorImpl<char> &ResultPath,
809 bool MakeAbsolute);
810
811/// Create a uniquely named file.
812///
813/// Generates a unique path suitable for a temporary file and then opens it as a
814/// file. The name is based on \a Model with '%' replaced by a random char in
815/// [0-9a-f]. If \a Model is not an absolute path, the temporary file will be
816/// created in the current directory.
817///
818/// Example: clang-%%-%%-%%-%%-%%.s => clang-a0-b1-c2-d3-e4.s
819///
820/// This is an atomic operation. Either the file is created and opened, or the
821/// file system is left untouched.
822///
823/// The intended use is for files that are to be kept, possibly after
824/// renaming them. For example, when running 'clang -c foo.o', the file can
825/// be first created as foo-abc123.o and then renamed.
826///
827/// @param Model Name to base unique path off of.
828/// @param ResultFD Set to the opened file's file descriptor.
829/// @param ResultPath Set to the opened file's absolute path.
830/// @param Flags Set to the opened file's flags.
831/// @param Mode Set to the opened file's permissions.
832/// @returns errc::success if Result{FD,Path} have been successfully set,
833/// otherwise a platform-specific error_code.
834LLVM_ABI std::error_code createUniqueFile(const Twine &Model, int &ResultFD,
835 SmallVectorImpl<char> &ResultPath,
836 OpenFlags Flags = OF_None,
837 unsigned Mode = all_read | all_write);
838
839/// Simpler version for clients that don't want an open file. An empty
840/// file will still be created.
841LLVM_ABI std::error_code createUniqueFile(const Twine &Model,
842 SmallVectorImpl<char> &ResultPath,
843 unsigned Mode = all_read | all_write);
844
845/// Represents a temporary file.
846///
847/// The temporary file must be eventually discarded or given a final name and
848/// kept.
849///
850/// The destructor doesn't implicitly discard because there is no way to
851/// properly handle errors in a destructor.
852class TempFile {
853 bool Done = false;
855
856public:
857 /// This creates a temporary file with createUniqueFile and schedules it for
858 /// deletion with sys::RemoveFileOnSignal.
860 create(const Twine &Model, unsigned Mode = all_read | all_write,
861 OpenFlags ExtraFlags = OF_None);
864
865 // Name of the temporary file.
866 std::string TmpName;
867
868 // The open file descriptor.
869 int FD = -1;
870
871#ifdef _WIN32
872 // Whether we need to manually remove the file on close.
873 bool RemoveOnClose = false;
874#endif
875
876 // Keep this with the given name.
877 LLVM_ABI Error keep(const Twine &Name);
878
879 // Keep this with the temporary name.
881
882 // Delete the file.
884
885 // This checks that keep or delete was called.
887};
888
889/// Create a file in the system temporary directory.
890///
891/// The filename is of the form prefix-random_chars.suffix. Since the directory
892/// is not know to the caller, Prefix and Suffix cannot have path separators.
893/// The files are created with mode 0600.
894///
895/// This should be used for things like a temporary .s that is removed after
896/// running the assembler.
897LLVM_ABI std::error_code createTemporaryFile(const Twine &Prefix,
898 StringRef Suffix, int &ResultFD,
899 SmallVectorImpl<char> &ResultPath,
900 OpenFlags Flags = OF_None);
901
902/// Simpler version for clients that don't want an open file. An empty
903/// file will still be created.
904LLVM_ABI std::error_code createTemporaryFile(const Twine &Prefix,
905 StringRef Suffix,
906 SmallVectorImpl<char> &ResultPath,
907 OpenFlags Flags = OF_None);
908
909LLVM_ABI std::error_code
910createUniqueDirectory(const Twine &Prefix, SmallVectorImpl<char> &ResultPath);
911
912/// Get a unique name, not currently exisiting in the filesystem. Subject
913/// to race conditions, prefer to use createUniqueFile instead.
914///
915/// Similar to createUniqueFile, but instead of creating a file only
916/// checks if it exists. This function is subject to race conditions, if you
917/// want to use the returned name to actually create a file, use
918/// createUniqueFile instead.
919LLVM_ABI std::error_code
921 SmallVectorImpl<char> &ResultPath);
922
923/// Get a unique temporary file name, not currently exisiting in the
924/// filesystem. Subject to race conditions, prefer to use createTemporaryFile
925/// instead.
926///
927/// Similar to createTemporaryFile, but instead of creating a file only
928/// checks if it exists. This function is subject to race conditions, if you
929/// want to use the returned name to actually create a file, use
930/// createTemporaryFile instead.
931LLVM_ABI std::error_code
933 SmallVectorImpl<char> &ResultPath);
934
936 return OpenFlags(unsigned(A) | unsigned(B));
937}
938
940 A = A | B;
941 return A;
942}
943
945 return FileAccess(unsigned(A) | unsigned(B));
946}
947
949 A = A | B;
950 return A;
951}
952
953/// @brief Opens a file with the specified creation disposition, access mode,
954/// and flags and returns a file descriptor.
955///
956/// The caller is responsible for closing the file descriptor once they are
957/// finished with it.
958///
959/// @param Name The path of the file to open, relative or absolute.
960/// @param ResultFD If the file could be opened successfully, its descriptor
961/// is stored in this location. Otherwise, this is set to -1.
962/// @param Disp Value specifying the existing-file behavior.
963/// @param Access Value specifying whether to open the file in read, write, or
964/// read-write mode.
965/// @param Flags Additional flags.
966/// @param Mode The access permissions of the file, represented in octal.
967/// @returns errc::success if \a Name has been opened, otherwise a
968/// platform-specific error_code.
969LLVM_ABI std::error_code openFile(const Twine &Name, int &ResultFD,
971 OpenFlags Flags, unsigned Mode = 0666);
972
973/// @brief Opens a file with the specified creation disposition, access mode,
974/// and flags and returns a platform-specific file object.
975///
976/// The caller is responsible for closing the file object once they are
977/// finished with it.
978///
979/// @param Name The path of the file to open, relative or absolute.
980/// @param Disp Value specifying the existing-file behavior.
981/// @param Access Value specifying whether to open the file in read, write, or
982/// read-write mode.
983/// @param Flags Additional flags.
984/// @param Mode The access permissions of the file, represented in octal.
985/// @returns errc::success if \a Name has been opened, otherwise a
986/// platform-specific error_code.
990 unsigned Mode = 0666);
991
992/// Converts from a Posix file descriptor number to a native file handle.
993/// On Windows, this retreives the underlying handle. On non-Windows, this is a
994/// no-op.
996
997#ifndef _WIN32
998inline file_t convertFDToNativeFile(int FD) { return FD; }
999#endif
1000
1001/// Return an open handle to standard in. On Unix, this is typically FD 0.
1002/// Returns kInvalidFile when the stream is closed.
1004
1005/// Return an open handle to standard out. On Unix, this is typically FD 1.
1006/// Returns kInvalidFile when the stream is closed.
1008
1009/// Return an open handle to standard error. On Unix, this is typically FD 2.
1010/// Returns kInvalidFile when the stream is closed.
1012
1013/// Reads \p Buf.size() bytes from \p FileHandle into \p Buf. Returns the number
1014/// of bytes actually read. On Unix, this is equivalent to `return ::read(FD,
1015/// Buf.data(), Buf.size())`, with error reporting. Returns 0 when reaching EOF.
1016///
1017/// @param FileHandle File to read from.
1018/// @param Buf Buffer to read into.
1019/// @returns The number of bytes read, or error.
1022
1023/// Default chunk size for \a readNativeFileToEOF().
1024enum : size_t { DefaultReadChunkSize = 4 * 4096 };
1025
1026/// Reads from \p FileHandle until EOF, appending to \p Buffer in chunks of
1027/// size \p ChunkSize.
1028///
1029/// This calls \a readNativeFile() in a loop. On Error, previous chunks that
1030/// were read successfully are left in \p Buffer and returned.
1031///
1032/// Note: For reading the final chunk at EOF, \p Buffer's capacity needs extra
1033/// storage of \p ChunkSize.
1034///
1035/// \param FileHandle File to read from.
1036/// \param Buffer Where to put the file content.
1037/// \param ChunkSize Size of chunks.
1038/// \returns The error if EOF was not found.
1040 SmallVectorImpl<char> &Buffer,
1041 ssize_t ChunkSize = DefaultReadChunkSize);
1042
1043/// Reads \p Buf.size() bytes from \p FileHandle at offset \p Offset into \p
1044/// Buf. If 'pread' is available, this will use that, otherwise it will use
1045/// 'lseek'. Returns the number of bytes actually read. Returns 0 when reaching
1046/// EOF.
1047///
1048/// @param FileHandle File to read from.
1049/// @param Buf Buffer to read into.
1050/// @param Offset Offset into the file at which the read should occur.
1051/// @returns The number of bytes read, or error.
1055
1056/// @brief Opens the file with the given name in a write-only or read-write
1057/// mode, returning its open file descriptor. If the file does not exist, it
1058/// is created.
1059///
1060/// The caller is responsible for closing the file descriptor once they are
1061/// finished with it.
1062///
1063/// @param Name The path of the file to open, relative or absolute.
1064/// @param ResultFD If the file could be opened successfully, its descriptor
1065/// is stored in this location. Otherwise, this is set to -1.
1066/// @param Flags Additional flags used to determine whether the file should be
1067/// opened in, for example, read-write or in write-only mode.
1068/// @param Mode The access permissions of the file, represented in octal.
1069/// @returns errc::success if \a Name has been opened, otherwise a
1070/// platform-specific error_code.
1071inline std::error_code
1072openFileForWrite(const Twine &Name, int &ResultFD,
1074 OpenFlags Flags = OF_None, unsigned Mode = 0666) {
1075 return openFile(Name, ResultFD, Disp, FA_Write, Flags, Mode);
1076}
1077
1078/// @brief Opens the file with the given name in a write-only or read-write
1079/// mode, returning its open file descriptor. If the file does not exist, it
1080/// is created.
1081///
1082/// The caller is responsible for closing the freeing the file once they are
1083/// finished with it.
1084///
1085/// @param Name The path of the file to open, relative or absolute.
1086/// @param Flags Additional flags used to determine whether the file should be
1087/// opened in, for example, read-write or in write-only mode.
1088/// @param Mode The access permissions of the file, represented in octal.
1089/// @returns a platform-specific file descriptor if \a Name has been opened,
1090/// otherwise an error object.
1093 OpenFlags Flags,
1094 unsigned Mode = 0666) {
1095 return openNativeFile(Name, Disp, FA_Write, Flags, Mode);
1096}
1097
1098/// @brief Opens the file with the given name in a write-only or read-write
1099/// mode, returning its open file descriptor. If the file does not exist, it
1100/// is created.
1101///
1102/// The caller is responsible for closing the file descriptor once they are
1103/// finished with it.
1104///
1105/// @param Name The path of the file to open, relative or absolute.
1106/// @param ResultFD If the file could be opened successfully, its descriptor
1107/// is stored in this location. Otherwise, this is set to -1.
1108/// @param Flags Additional flags used to determine whether the file should be
1109/// opened in, for example, read-write or in write-only mode.
1110/// @param Mode The access permissions of the file, represented in octal.
1111/// @returns errc::success if \a Name has been opened, otherwise a
1112/// platform-specific error_code.
1113inline std::error_code openFileForReadWrite(const Twine &Name, int &ResultFD,
1115 OpenFlags Flags,
1116 unsigned Mode = 0666) {
1117 return openFile(Name, ResultFD, Disp, FA_Write | FA_Read, Flags, Mode);
1118}
1119
1120/// @brief Opens the file with the given name in a write-only or read-write
1121/// mode, returning its open file descriptor. If the file does not exist, it
1122/// is created.
1123///
1124/// The caller is responsible for closing the freeing the file once they are
1125/// finished with it.
1126///
1127/// @param Name The path of the file to open, relative or absolute.
1128/// @param Flags Additional flags used to determine whether the file should be
1129/// opened in, for example, read-write or in write-only mode.
1130/// @param Mode The access permissions of the file, represented in octal.
1131/// @returns a platform-specific file descriptor if \a Name has been opened,
1132/// otherwise an error object.
1135 OpenFlags Flags,
1136 unsigned Mode = 0666) {
1137 return openNativeFile(Name, Disp, FA_Write | FA_Read, Flags, Mode);
1138}
1139
1140/// @brief Opens the file with the given name in a read-only mode, returning
1141/// its open file descriptor.
1142///
1143/// The caller is responsible for closing the file descriptor once they are
1144/// finished with it.
1145///
1146/// @param Name The path of the file to open, relative or absolute.
1147/// @param ResultFD If the file could be opened successfully, its descriptor
1148/// is stored in this location. Otherwise, this is set to -1.
1149/// @param RealPath If nonnull, extra work is done to determine the real path
1150/// of the opened file, and that path is stored in this
1151/// location.
1152/// @returns errc::success if \a Name has been opened, otherwise a
1153/// platform-specific error_code.
1154LLVM_ABI std::error_code
1155openFileForRead(const Twine &Name, int &ResultFD, OpenFlags Flags = OF_None,
1156 SmallVectorImpl<char> *RealPath = nullptr);
1157
1158/// @brief Opens the file with the given name in a read-only mode, returning
1159/// its open file descriptor.
1160///
1161/// The caller is responsible for closing the freeing the file once they are
1162/// finished with it.
1163///
1164/// @param Name The path of the file to open, relative or absolute.
1165/// @param RealPath If nonnull, extra work is done to determine the real path
1166/// of the opened file, and that path is stored in this
1167/// location.
1168/// @returns a platform-specific file descriptor if \a Name has been opened,
1169/// otherwise an error object.
1172 SmallVectorImpl<char> *RealPath = nullptr);
1173
1174/// An enumeration for the lock kind.
1175enum class LockKind {
1176 Exclusive, // Exclusive/writer lock
1177 Shared // Shared/reader lock
1178};
1179
1180/// Try to locks the file during the specified time.
1181///
1182/// This function implements advisory locking on entire file. If it returns
1183/// <em>errc::success</em>, the file is locked by the calling process. Until the
1184/// process unlocks the file by calling \a unlockFile, all attempts to lock the
1185/// same file will fail/block. The process that locked the file may assume that
1186/// none of other processes read or write this file, provided that all processes
1187/// lock the file prior to accessing its content.
1188///
1189/// @param FD The descriptor representing the file to lock.
1190/// @param Timeout Time in milliseconds that the process should wait before
1191/// reporting lock failure. Zero value means try to get lock only
1192/// once.
1193/// @param Kind The kind of the lock used (exclusive/shared).
1194/// @returns errc::success if lock is successfully obtained,
1195/// errc::no_lock_available if the file cannot be locked, or platform-specific
1196/// error_code otherwise.
1197///
1198/// @note Care should be taken when using this function in a multithreaded
1199/// context, as it may not prevent other threads in the same process from
1200/// obtaining a lock on the same file, even if they are using a different file
1201/// descriptor.
1202LLVM_ABI std::error_code
1204 std::chrono::milliseconds Timeout = std::chrono::milliseconds(0),
1206
1207/// Lock the file.
1208///
1209/// This function acts as @ref tryLockFile but it waits infinitely.
1210/// \param FD file descriptor to use for locking.
1211/// \param Kind of lock to used (exclusive/shared).
1212LLVM_ABI std::error_code lockFile(int FD, LockKind Kind = LockKind::Exclusive);
1213
1214/// Unlock the file.
1215///
1216/// @param FD The descriptor representing the file to unlock.
1217/// @returns errc::success if lock is successfully released or platform-specific
1218/// error_code otherwise.
1219LLVM_ABI std::error_code unlockFile(int FD);
1220
1221/// @brief Close the file object. This should be used instead of ::close for
1222/// portability. On error, the caller should assume the file is closed, as is
1223/// the case for Process::SafelyCloseFileDescriptor
1224///
1225/// @param F On input, this is the file to close. On output, the file is
1226/// set to kInvalidFile.
1227///
1228/// @returns An error code if closing the file failed. Typically, an error here
1229/// means that the filesystem may have failed to perform some buffered writes.
1230LLVM_ABI std::error_code closeFile(file_t &F);
1231
1232#ifdef LLVM_ON_UNIX
1233/// @brief Change ownership of a file.
1234///
1235/// @param Owner The owner of the file to change to.
1236/// @param Group The group of the file to change to.
1237/// @returns errc::success if successfully updated file ownership, otherwise an
1238/// error code is returned.
1239LLVM_ABI std::error_code changeFileOwnership(int FD, uint32_t Owner,
1240 uint32_t Group);
1241#endif
1242
1243/// RAII class that facilitates file locking.
1245 int FD; ///< Locked file handle.
1246 FileLocker(int FD) : FD(FD) {}
1248
1249public:
1250 FileLocker(const FileLocker &L) = delete;
1251 FileLocker(FileLocker &&L) : FD(L.FD) { L.FD = -1; }
1253 if (FD != -1)
1254 unlockFile(FD);
1255 }
1257 FD = L.FD;
1258 L.FD = -1;
1259 return *this;
1260 }
1261 FileLocker &operator=(const FileLocker &L) = delete;
1262 std::error_code unlock() {
1263 if (FD != -1) {
1264 std::error_code Result = unlockFile(FD);
1265 FD = -1;
1266 return Result;
1267 }
1268 return std::error_code();
1269 }
1270};
1271
1272LLVM_ABI std::error_code getUniqueID(const Twine Path, UniqueID &Result);
1273
1274/// Get disk space usage information.
1275///
1276/// Note: Users must be careful about "Time Of Check, Time Of Use" kind of bug.
1277/// Note: Windows reports results according to the quota allocated to the user.
1278///
1279/// @param Path Input path.
1280/// @returns a space_info structure filled with the capacity, free, and
1281/// available space on the device \a Path is on. A platform specific error_code
1282/// is returned on error.
1284
1285/// This class represents a memory mapped file. It is based on
1286/// boost::iostreams::mapped_file.
1288public:
1289 enum mapmode {
1290 readonly, ///< May only access map via const_data as read only.
1291 readwrite, ///< May access map via data and modify it. Written to path.
1292 priv ///< May modify via data, but changes are lost on destruction.
1294
1295private:
1296 /// Platform-specific mapping state.
1297 size_t Size = 0;
1298 void *Mapping = nullptr;
1299#ifdef _WIN32
1300 sys::fs::file_t FileHandle = nullptr;
1301#endif
1302 mapmode Mode = readonly;
1303
1304 void copyFrom(const mapped_file_region &Copied) {
1305 Size = Copied.Size;
1306 Mapping = Copied.Mapping;
1307#ifdef _WIN32
1308 FileHandle = Copied.FileHandle;
1309#endif
1310 Mode = Copied.Mode;
1311 }
1312
1313 void moveFromImpl(mapped_file_region &Moved) {
1314 copyFrom(Moved);
1315 Moved.copyFrom(mapped_file_region());
1316 }
1317
1318 LLVM_ABI void unmapImpl();
1319 LLVM_ABI void dontNeedImpl();
1320
1321 LLVM_ABI std::error_code init(sys::fs::file_t FD, uint64_t Offset,
1322 mapmode Mode);
1323
1324public:
1326 mapped_file_region(mapped_file_region &&Moved) { moveFromImpl(Moved); }
1328 unmap();
1329 moveFromImpl(Moved);
1330 return *this;
1331 }
1332
1335
1336 /// \param fd An open file descriptor to map. Does not take ownership of fd.
1338 uint64_t offset, std::error_code &ec);
1339
1340 ~mapped_file_region() { unmapImpl(); }
1341
1342 /// Check if this is a valid mapping.
1343 explicit operator bool() const { return Mapping; }
1344
1345 /// Unmap.
1346 void unmap() {
1347 unmapImpl();
1348 copyFrom(mapped_file_region());
1349 }
1350 void dontNeed() { dontNeedImpl(); }
1351
1352 LLVM_ABI size_t size() const;
1353 LLVM_ABI char *data() const;
1354
1355 /// Write changes to disk and synchronize. Equivalent to POSIX msync. This
1356 /// will wait for flushing memory-mapped region back to disk and can be very
1357 /// slow.
1358 LLVM_ABI std::error_code sync() const;
1359
1360 /// Get a const view of the data. Modifying this memory has undefined
1361 /// behavior.
1362 LLVM_ABI const char *const_data() const;
1363
1364 /// \returns The minimum alignment offset must be.
1365 LLVM_ABI static int alignment();
1366};
1367
1368/// Return the path to the main executable, given the value of argv[0] from
1369/// program startup and the address of main itself. In extremis, this function
1370/// may fail and return an empty path.
1371LLVM_ABI std::string getMainExecutable(const char *argv0, void *MainExecAddr);
1372
1373/// @}
1374/// @name Iterators
1375/// @{
1376
1377/// directory_entry - A single entry in a directory.
1379 // FIXME: different platforms make different information available "for free"
1380 // when traversing a directory. The design of this class wraps most of the
1381 // information in basic_file_status, so on platforms where we can't populate
1382 // that whole structure, callers end up paying for a stat().
1383 // std::filesystem::directory_entry may be a better model.
1384 std::string Path;
1385 file_type Type = file_type::type_unknown; // Most platforms can provide this.
1386 bool FollowSymlinks = true; // Affects the behavior of status().
1387 basic_file_status Status; // If available.
1388
1389public:
1390 explicit directory_entry(const Twine &Path, bool FollowSymlinks = true,
1393 : Path(Path.str()), Type(Type), FollowSymlinks(FollowSymlinks),
1394 Status(Status) {}
1395
1396 directory_entry() = default;
1397
1398 LLVM_ABI void
1399 replace_filename(const Twine &Filename, file_type Type,
1401
1402 const std::string &path() const { return Path; }
1403 // Get basic information about entry file (a subset of fs::status()).
1404 // On most platforms this is a stat() call.
1405 // On windows the information was already retrieved from the directory.
1407 // Get the type of this file.
1408 // On most platforms (Linux/Mac/Windows/BSD), this was already retrieved.
1409 // On some platforms (e.g. Solaris) this is a stat() call.
1410 file_type type() const {
1412 return Type;
1413 auto S = status();
1414 return S ? S->type() : file_type::type_unknown;
1415 }
1416
1417 bool operator==(const directory_entry& RHS) const { return Path == RHS.Path; }
1418 bool operator!=(const directory_entry& RHS) const { return !(*this == RHS); }
1423};
1424
1425namespace detail {
1426
1427 struct DirIterState;
1428
1430 StringRef, bool);
1433
1434 /// Keeps state for the directory_iterator.
1438 }
1439
1440 intptr_t IterationHandle = 0;
1442 };
1443
1444} // end namespace detail
1445
1446/// directory_iterator - Iterates through the entries in path. There is no
1447/// operator++ because we need an error_code. If it's really needed we can make
1448/// it call report_fatal_error on error.
1450 std::shared_ptr<detail::DirIterState> State;
1451 bool FollowSymlinks = true;
1452
1453public:
1454 explicit directory_iterator(const Twine &path, std::error_code &ec,
1455 bool follow_symlinks = true)
1456 : FollowSymlinks(follow_symlinks) {
1457 State = std::make_shared<detail::DirIterState>();
1458 SmallString<128> path_storage;
1460 *State, path.toStringRef(path_storage), FollowSymlinks);
1461 }
1462
1463 explicit directory_iterator(const directory_entry &de, std::error_code &ec,
1464 bool follow_symlinks = true)
1465 : FollowSymlinks(follow_symlinks) {
1466 State = std::make_shared<detail::DirIterState>();
1468 *State, de.path(), FollowSymlinks);
1469 }
1470
1471 /// Construct end iterator.
1473
1474 // No operator++ because we need error_code.
1475 directory_iterator &increment(std::error_code &ec) {
1476 ec = directory_iterator_increment(*State);
1477 return *this;
1478 }
1479
1480 const directory_entry &operator*() const { return State->CurrentEntry; }
1481 const directory_entry *operator->() const { return &State->CurrentEntry; }
1482
1483 bool operator==(const directory_iterator &RHS) const {
1484 if (State == RHS.State)
1485 return true;
1486 if (!RHS.State)
1487 return State->CurrentEntry == directory_entry();
1488 if (!State)
1489 return RHS.State->CurrentEntry == directory_entry();
1490 return State->CurrentEntry == RHS.State->CurrentEntry;
1491 }
1492
1493 bool operator!=(const directory_iterator &RHS) const {
1494 return !(*this == RHS);
1495 }
1496};
1497
1498namespace detail {
1499
1500 /// Keeps state for the recursive_directory_iterator.
1502 std::vector<directory_iterator> Stack;
1503 uint16_t Level = 0;
1504 bool HasNoPushRequest = false;
1505 };
1506
1507} // end namespace detail
1508
1509/// recursive_directory_iterator - Same as directory_iterator except for it
1510/// recurses down into child directories.
1512 std::shared_ptr<detail::RecDirIterState> State;
1513 bool Follow;
1514
1515public:
1517 explicit recursive_directory_iterator(const Twine &path, std::error_code &ec,
1518 bool follow_symlinks = true)
1519 : State(std::make_shared<detail::RecDirIterState>()),
1520 Follow(follow_symlinks) {
1521 State->Stack.push_back(directory_iterator(path, ec, Follow));
1522 if (State->Stack.back() == directory_iterator())
1523 State.reset();
1524 }
1525
1526 // No operator++ because we need error_code.
1528 const directory_iterator end_itr = {};
1529
1530 if (State->HasNoPushRequest)
1531 State->HasNoPushRequest = false;
1532 else {
1533 file_type type = State->Stack.back()->type();
1534 if (type == file_type::symlink_file && Follow) {
1535 // Resolve the symlink: is it a directory to recurse into?
1536 ErrorOr<basic_file_status> status = State->Stack.back()->status();
1537 if (status)
1538 type = status->type();
1539 // Otherwise broken symlink, and we'll continue.
1540 }
1541 if (type == file_type::directory_file) {
1542 State->Stack.push_back(
1543 directory_iterator(*State->Stack.back(), ec, Follow));
1544 if (State->Stack.back() != end_itr) {
1545 ++State->Level;
1546 return *this;
1547 }
1548 State->Stack.pop_back();
1549 }
1550 }
1551
1552 while (!State->Stack.empty()
1553 && State->Stack.back().increment(ec) == end_itr) {
1554 State->Stack.pop_back();
1555 --State->Level;
1556 }
1557
1558 // Check if we are done. If so, create an end iterator.
1559 if (State->Stack.empty())
1560 State.reset();
1561
1562 return *this;
1563 }
1564
1565 const directory_entry &operator*() const { return *State->Stack.back(); }
1566 const directory_entry *operator->() const { return &*State->Stack.back(); }
1567
1568 // observers
1569 /// Gets the current level. Starting path is at level 0.
1570 int level() const { return State->Level; }
1571
1572 /// Returns true if no_push has been called for this directory_entry.
1573 bool no_push_request() const { return State->HasNoPushRequest; }
1574
1575 // modifiers
1576 /// Goes up one level if Level > 0.
1577 void pop() {
1578 assert(State && "Cannot pop an end iterator!");
1579 assert(State->Level > 0 && "Cannot pop an iterator with level < 1");
1580
1581 const directory_iterator end_itr = {};
1582 std::error_code ec;
1583 do {
1584 if (ec)
1585 report_fatal_error("Error incrementing directory iterator.");
1586 State->Stack.pop_back();
1587 --State->Level;
1588 } while (!State->Stack.empty()
1589 && State->Stack.back().increment(ec) == end_itr);
1590
1591 // Check if we are done. If so, create an end iterator.
1592 if (State->Stack.empty())
1593 State.reset();
1594 }
1595
1596 /// Does not go down into the current directory_entry.
1597 void no_push() { State->HasNoPushRequest = true; }
1598
1600 return State == RHS.State;
1601 }
1602
1604 return !(*this == RHS);
1605 }
1606};
1607
1608/// @}
1609
1610} // end namespace fs
1611} // end namespace sys
1612} // end namespace llvm
1613
1614#endif // LLVM_SUPPORT_FILESYSTEM_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
BlockVerifier::State From
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
#define LLVM_ABI
Definition: Compiler.h:213
DXIL Resource Access
std::string Name
uint64_t Size
Provides ErrorOr<T> smart pointer.
amode Optimize addressing mode
#define F(x, y, z)
Definition: MD5.cpp:55
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 SmallString class.
Value * RHS
Represents either an error or a value T.
Definition: ErrorOr.h:56
Lightweight error class with error context and mandatory checking.
Definition: Error.h:159
Tagged union holding either a T or a Error.
Definition: Error.h:485
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
Definition: ArrayRef.h:303
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition: SmallString.h:26
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:574
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:55
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:82
StringRef toStringRef(SmallVectorImpl< char > &Out) const
This returns the twine as a single StringRef if it can be represented as such.
Definition: Twine.h:494
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
A raw_ostream that writes to a file descriptor.
Definition: raw_ostream.h:461
RAII class that facilitates file locking.
Definition: FileSystem.h:1244
FileLocker & operator=(FileLocker &&L)
Definition: FileSystem.h:1256
FileLocker(const FileLocker &L)=delete
FileLocker & operator=(const FileLocker &L)=delete
FileLocker(FileLocker &&L)
Definition: FileSystem.h:1251
std::error_code unlock()
Definition: FileSystem.h:1262
Represents a temporary file.
Definition: FileSystem.h:852
LLVM_ABI Error keep()
Definition: Path.cpp:1305
LLVM_ABI ~TempFile()
Definition: Path.cpp:1224
LLVM_ABI TempFile & operator=(TempFile &&Other)
Definition: Path.cpp:1212
LLVM_ABI Error discard()
Definition: Path.cpp:1226
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...
Definition: Path.cpp:1325
Represents the result of a call to directory_iterator::status().
Definition: FileSystem.h:133
basic_file_status(file_type Type, perms Perms, time_t ATime, uint32_t ATimeNSec, time_t MTime, uint32_t MTimeNSec, uid_t UID, gid_t GID, off_t Size)
Definition: FileSystem.h:160
LLVM_ABI TimePoint getLastModificationTime() const
The file modification time as reported from the underlying file system.
LLVM_ABI TimePoint getLastAccessedTime() const
The file access time as reported from the underlying file system.
basic_file_status(file_type Type)
Definition: FileSystem.h:157
directory_entry - A single entry in a directory.
Definition: FileSystem.h:1378
directory_entry(const Twine &Path, bool FollowSymlinks=true, file_type Type=file_type::type_unknown, basic_file_status Status=basic_file_status())
Definition: FileSystem.h:1390
LLVM_ABI bool operator<=(const directory_entry &RHS) const
LLVM_ABI bool operator>(const directory_entry &RHS) const
LLVM_ABI bool operator>=(const directory_entry &RHS) const
LLVM_ABI bool operator<(const directory_entry &RHS) const
LLVM_ABI ErrorOr< basic_file_status > status() const
bool operator==(const directory_entry &RHS) const
Definition: FileSystem.h:1417
bool operator!=(const directory_entry &RHS) const
Definition: FileSystem.h:1418
file_type type() const
Definition: FileSystem.h:1410
const std::string & path() const
Definition: FileSystem.h:1402
directory_entry()=default
LLVM_ABI void replace_filename(const Twine &Filename, file_type Type, basic_file_status Status=basic_file_status())
Definition: Path.cpp:1142
directory_iterator - Iterates through the entries in path.
Definition: FileSystem.h:1449
bool operator!=(const directory_iterator &RHS) const
Definition: FileSystem.h:1493
directory_iterator(const directory_entry &de, std::error_code &ec, bool follow_symlinks=true)
Definition: FileSystem.h:1463
directory_iterator(const Twine &path, std::error_code &ec, bool follow_symlinks=true)
Definition: FileSystem.h:1454
directory_iterator()=default
Construct end iterator.
const directory_entry & operator*() const
Definition: FileSystem.h:1480
directory_iterator & increment(std::error_code &ec)
Definition: FileSystem.h:1475
bool operator==(const directory_iterator &RHS) const
Definition: FileSystem.h:1483
const directory_entry * operator->() const
Definition: FileSystem.h:1481
Represents the result of a call to sys::fs::status().
Definition: FileSystem.h:222
file_status(file_type Type, perms Perms, dev_t Dev, nlink_t Links, ino_t Ino, time_t ATime, uint32_t ATimeNSec, time_t MTime, uint32_t MTimeNSec, uid_t UID, gid_t GID, off_t Size)
Definition: FileSystem.h:241
LLVM_ABI uint32_t getLinkCount() const
LLVM_ABI friend bool equivalent(file_status A, file_status B)
Do file_status's represent the same thing?
file_status(file_type Type)
Definition: FileSystem.h:238
LLVM_ABI UniqueID getUniqueID() const
This class represents a memory mapped file.
Definition: FileSystem.h:1287
LLVM_ABI size_t size() const
Definition: Path.cpp:1159
LLVM_ABI std::error_code sync() const
Write changes to disk and synchronize.
mapped_file_region(mapped_file_region &&Moved)
Definition: FileSystem.h:1326
static LLVM_ABI int alignment()
@ priv
May modify via data, but changes are lost on destruction.
Definition: FileSystem.h:1292
@ readonly
May only access map via const_data as read only.
Definition: FileSystem.h:1290
@ readwrite
May access map via data and modify it. Written to path.
Definition: FileSystem.h:1291
mapped_file_region & operator=(mapped_file_region &&Moved)
Definition: FileSystem.h:1327
LLVM_ABI const char * const_data() const
Get a const view of the data.
Definition: Path.cpp:1169
mapped_file_region(const mapped_file_region &)=delete
LLVM_ABI char * data() const
Definition: Path.cpp:1164
mapped_file_region & operator=(const mapped_file_region &)=delete
LLVM_ABI mapped_file_region(sys::fs::file_t fd, mapmode mode, size_t length, uint64_t offset, std::error_code &ec)
recursive_directory_iterator - Same as directory_iterator except for it recurses down into child dire...
Definition: FileSystem.h:1511
void pop()
Goes up one level if Level > 0.
Definition: FileSystem.h:1577
bool operator==(const recursive_directory_iterator &RHS) const
Definition: FileSystem.h:1599
void no_push()
Does not go down into the current directory_entry.
Definition: FileSystem.h:1597
int level() const
Gets the current level. Starting path is at level 0.
Definition: FileSystem.h:1570
const directory_entry * operator->() const
Definition: FileSystem.h:1566
recursive_directory_iterator & increment(std::error_code &ec)
Definition: FileSystem.h:1527
recursive_directory_iterator(const Twine &path, std::error_code &ec, bool follow_symlinks=true)
Definition: FileSystem.h:1517
const directory_entry & operator*() const
Definition: FileSystem.h:1565
bool no_push_request() const
Returns true if no_push has been called for this directory_entry.
Definition: FileSystem.h:1573
bool operator!=(const recursive_directory_iterator &RHS) const
Definition: FileSystem.h:1603
LLVM_ABI std::error_code directory_iterator_construct(DirIterState &, StringRef, bool)
LLVM_ABI std::error_code directory_iterator_destruct(DirIterState &)
LLVM_ABI std::error_code directory_iterator_increment(DirIterState &)
LLVM_ABI bool is_regular_file(const basic_file_status &status)
Does status represent a regular file?
Definition: Path.cpp:1104
LLVM_ABI bool can_execute(const Twine &Path)
Can we execute this file?
LLVM_ABI bool is_symlink_file(const basic_file_status &status)
Does status represent a symlink file?
Definition: Path.cpp:1116
perms operator&(perms l, perms r)
Definition: FileSystem.h:112
LLVM_ABI void make_absolute(const Twine &current_directory, SmallVectorImpl< char > &path)
Make path an absolute path.
Definition: Path.cpp:906
LLVM_ABI std::error_code closeFile(file_t &F)
Close the file object.
perms operator|(perms l, perms r)
Definition: FileSystem.h:108
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...
Definition: FileSystem.h:1113
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
perms & operator&=(perms &l, perms r)
Definition: FileSystem.h:120
LLVM_ABI ErrorOr< perms > getPermissions(const Twine &Path)
Get file permissions.
Definition: Path.cpp:1151
bool can_write(const Twine &Path)
Can we write this file?
Definition: FileSystem.h:476
LLVM_ABI std::error_code create_hard_link(const Twine &to, const Twine &from)
Create a hard link from from to to, or return an error.
perms operator~(perms x)
Definition: FileSystem.h:124
LLVM_ABI std::error_code openFile(const Twine &Name, int &ResultFD, CreationDisposition Disp, FileAccess Access, OpenFlags Flags, unsigned Mode=0666)
Opens a file with the specified creation disposition, access mode, and flags and returns a file descr...
LLVM_ABI const file_t kInvalidFile
std::error_code resize_file_before_mapping_readwrite(int FD, uint64_t Size)
Resize FD to Size before mapping mapped_file_region::readwrite.
Definition: FileSystem.h:417
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:893
LLVM_ABI std::error_code access(const Twine &Path, AccessMode Mode)
Can the file be accessed?
LLVM_ABI ErrorOr< space_info > disk_space(const Twine &Path)
Get disk space usage information.
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:900
perms & operator|=(perms &l, perms r)
Definition: FileSystem.h:116
LLVM_ABI Expected< size_t > readNativeFile(file_t FileHandle, MutableArrayRef< char > Buf)
Reads Buf.size() bytes from FileHandle into Buf.
LLVM_ABI unsigned getUmask()
Get file creation mode mask of the process.
LLVM_ABI bool exists(const basic_file_status &status)
Does file exist?
Definition: Path.cpp:1077
LLVM_ABI Expected< file_t > openNativeFile(const Twine &Name, CreationDisposition Disp, FileAccess Access, OpenFlags Flags, unsigned Mode=0666)
Opens a file with the specified creation disposition, access mode, and flags and returns a platform-s...
@ OF_Delete
The returned handle can be used for deleting the file.
Definition: FileSystem.h:778
@ OF_ChildInherit
When a child process is launched, this file should remain open in the child process.
Definition: FileSystem.h:782
@ OF_Text
The file should be opened in text mode on platforms like z/OS that make this distinction.
Definition: FileSystem.h:762
@ OF_CRLF
The file should use a carriage linefeed '\r '.
Definition: FileSystem.h:766
@ OF_UpdateAtime
Force files Atime to be updated on access.
Definition: FileSystem.h:786
@ OF_TextWithCRLF
The file should be opened in text mode and use a carriage linefeed '\r '.
Definition: FileSystem.h:771
@ OF_Append
The file should be opened in append mode.
Definition: FileSystem.h:774
LLVM_ABI file_t getStdoutHandle()
Return an open handle to standard out.
file_type
An enumeration for the file system's view of the type.
Definition: FileSystem.h:62
LLVM_ABI std::error_code create_link(const Twine &to, const Twine &from)
Create a link from from to to.
Expected< file_t > openNativeFileForWrite(const Twine &Name, 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...
Definition: FileSystem.h:1091
LLVM_ABI void expand_tilde(const Twine &path, SmallVectorImpl< char > &output)
Expands ~ expressions to the user's home directory.
LLVM_ABI std::error_code getUniqueID(const Twine Path, UniqueID &Result)
Definition: Path.cpp:787
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:822
LLVM_ABI std::error_code lockFile(int FD, LockKind Kind=LockKind::Exclusive)
Lock the file.
LLVM_ABI std::error_code remove(const Twine &path, bool IgnoreNonExisting=true)
Remove path.
LLVM_ABI std::error_code set_current_path(const Twine &path)
Set the current path.
LLVM_ABI std::error_code real_path(const Twine &path, SmallVectorImpl< char > &output, bool expand_tilde=false)
Collapse all .
@ CD_OpenExisting
CD_OpenExisting - When opening a file:
Definition: FileSystem.h:744
@ CD_OpenAlways
CD_OpenAlways - When opening a file:
Definition: FileSystem.h:749
@ CD_CreateAlways
CD_CreateAlways - When opening a file:
Definition: FileSystem.h:734
@ CD_CreateNew
CD_CreateNew - When opening a file:
Definition: FileSystem.h:739
LLVM_ABI Expected< size_t > readNativeFileSlice(file_t FileHandle, MutableArrayRef< char > Buf, uint64_t Offset)
Reads Buf.size() bytes from FileHandle at offset Offset into Buf.
LLVM_ABI std::error_code changeFileOwnership(int FD, uint32_t Owner, uint32_t Group)
Change ownership of a file.
Expected< file_t > openNativeFileForReadWrite(const Twine &Name, 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...
Definition: FileSystem.h:1133
LLVM_ABI std::string getMainExecutable(const char *argv0, void *MainExecAddr)
Return the path to the main executable, given the value of argv[0] from program startup and the addre...
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:796
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...
Definition: FileSystem.h:1072
LLVM_ABI Expected< file_t > openNativeFileForRead(const Twine &Name, 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 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:863
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 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:885
LLVM_ABI std::error_code tryLockFile(int FD, std::chrono::milliseconds Timeout=std::chrono::milliseconds(0), LockKind Kind=LockKind::Exclusive)
Try to locks the file during the specified time.
LLVM_ABI std::error_code current_path(SmallVectorImpl< char > &result)
Get the current path.
LockKind
An enumeration for the lock kind.
Definition: FileSystem.h:1175
LLVM_ABI std::error_code resize_file(int FD, uint64_t Size)
Resize path to size.
LLVM_ABI file_t convertFDToNativeFile(int FD)
Converts from a Posix file descriptor number to a native file handle.
Definition: FileSystem.h:998
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 is_local(const Twine &path, bool &result)
Is the file mounted on a local filesystem?
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 std::error_code remove_directories(const Twine &path, bool IgnoreErrors=true)
Recursively delete a directory.
LLVM_ABI bool equivalent(file_status A, file_status B)
Do file_status's represent the same thing?
LLVM_ABI file_t getStderrHandle()
Return an open handle to standard error.
LLVM_ABI std::error_code setLastAccessAndModificationTime(int FD, TimePoint<> AccessTime, TimePoint<> ModificationTime)
Set the file modification and access time.
LLVM_ABI ErrorOr< MD5::MD5Result > md5_contents(int FD)
Compute an MD5 hash of a file's contents.
Definition: Path.cpp:1047
LLVM_ABI file_t getStdinHandle()
Return an open handle to standard in.
LLVM_ABI std::error_code unlockFile(int FD)
Unlock the file.
std::error_code file_size(const Twine &Path, uint64_t &Result)
Get file size.
Definition: FileSystem.h:691
LLVM_ABI std::error_code setPermissions(const Twine &Path, perms Permissions)
Set file permissions.
LLVM_ABI bool is_directory(const basic_file_status &status)
Does status represent a directory?
Definition: Path.cpp:1092
std::chrono::time_point< std::chrono::system_clock, D > TimePoint
A time point on the system clock.
Definition: Chrono.h:34
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Offset
Definition: DWP.cpp:477
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
Definition: Error.cpp:167
@ Timeout
Reached timeout while waiting for the owner to release the lock.
@ Other
Any other memory.
Implement std::hash so that hash_code can be used in STL containers.
Definition: BitVector.h:856
Keeps state for the directory_iterator.
Definition: FileSystem.h:1435
Keeps state for the recursive_directory_iterator.
Definition: FileSystem.h:1501
std::vector< directory_iterator > Stack
Definition: FileSystem.h:1502
space_info - Self explanatory.
Definition: FileSystem.h:76