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