1 //===- llvm/Support/PathV2.h - Path Operating System Concept ----*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file declares the llvm::sys::{path,fs} namespaces. It is designed after
11 // TR2/boost filesystem (v3), but modified to remove exception handling and the
14 // All functions return an error_code and their actual work via the last out
15 // argument. The out argument is defined if and only if errc::success is
16 // returned. A function may return any error code in the generic or system
17 // category. However, they shall be equivalent to any error conditions listed
18 // in each functions respective documentation if the condition applies. [ note:
19 // this does not guarantee that error_code will be in the set of explicitly
20 // listed codes, but it does guarantee that if any of the explicitly listed
21 // errors occur, the correct error_code will be used ]. All functions may
22 // return errc::not_enough_memory if there is not enough memory to complete the
25 //===----------------------------------------------------------------------===//
27 #ifndef LLVM_SYSTEM_PATHV2_H
28 #define LLVM_SYSTEM_PATHV2_H
30 #include "llvm/ADT/SmallString.h"
31 #include "llvm/ADT/Twine.h"
32 #include "llvm/Support/DataTypes.h"
33 #include "llvm/Support/system_error.h"
47 /// @name Lexical Component Iterator
50 /// @brief Path iterator.
52 /// This is a bidirectional iterator that iterates over the individual
53 /// components in \a path. The forward traversal order is as follows:
54 /// * The root-name element, if present.
55 /// * The root-directory element, if present.
56 /// * Each successive filename element, if present.
57 /// * Dot, if one or more trailing non-root slash characters are present.
58 /// The backwards traversal order is the reverse of forward traversal.
60 /// Iteration examples. Each component is separated by ',':
64 /// /foo/bar => /,foo,bar
66 /// C:\foo\bar => C:,/,foo,bar
68 class const_iterator {
69 StringRef Path; //< The entire path.
70 StringRef Component; //< The current component. Not necessarily in Path.
71 size_t Position; //< The iterators current position within Path.
73 // An end iterator has Position = Path.size() + 1.
74 friend const_iterator begin(const StringRef &path);
75 friend const_iterator end(const StringRef &path);
78 typedef const StringRef value_type;
79 typedef ptrdiff_t difference_type;
80 typedef value_type &reference;
81 typedef value_type *pointer;
82 typedef std::bidirectional_iterator_tag iterator_category;
84 reference operator*() const { return Component; }
85 pointer operator->() const { return &Component; }
86 const_iterator &operator++(); // preincrement
87 const_iterator &operator++(int); // postincrement
88 const_iterator &operator--(); // predecrement
89 const_iterator &operator--(int); // postdecrement
90 bool operator==(const const_iterator &RHS) const;
91 bool operator!=(const const_iterator &RHS) const;
93 /// @brief Difference in bytes between this and RHS.
94 ptrdiff_t operator-(const const_iterator &RHS) const;
97 typedef std::reverse_iterator<const_iterator> reverse_iterator;
99 /// @brief Get begin iterator over \a path.
100 /// @param path Input path.
101 /// @returns Iterator initialized with the first component of \a path.
102 const_iterator begin(const StringRef &path);
104 /// @brief Get end iterator over \a path.
105 /// @param path Input path.
106 /// @returns Iterator initialized to the end of \a path.
107 const_iterator end(const StringRef &path);
109 /// @brief Get reverse begin iterator over \a path.
110 /// @param path Input path.
111 /// @returns Iterator initialized with the first reverse component of \a path.
112 inline reverse_iterator rbegin(const StringRef &path) {
113 return reverse_iterator(end(path));
116 /// @brief Get reverse end iterator over \a path.
117 /// @param path Input path.
118 /// @returns Iterator initialized to the reverse end of \a path.
119 inline reverse_iterator rend(const StringRef &path) {
120 return reverse_iterator(begin(path));
124 /// @name Lexical Modifiers
127 /// @brief Make \a path an absolute path.
129 /// Makes \a path absolute using the current directory if it is not already. An
130 /// empty \a path will result in the current directory.
132 /// /absolute/path => /absolute/path
133 /// relative/../path => <current-directory>/path
135 /// @param path A path that is modified to be an absolute path.
136 /// @returns errc::success if \a path has been made absolute, otherwise a
137 /// platform specific error_code.
138 error_code make_absolute(SmallVectorImpl<char> &path);
140 /// @brief Remove the last component from \a path if it exists.
142 /// directory/filename.cpp => directory/
143 /// directory/ => directory
145 /// @param path A path that is modified to not have a file component.
146 /// @returns errc::success if \a path's file name has been removed (or there was
147 /// not one to begin with), otherwise a platform specific error_code.
148 error_code remove_filename(SmallVectorImpl<char> &path);
150 /// @brief Replace the file extension of \a path with \a extension.
152 /// ./filename.cpp => ./filename.extension
153 /// ./filename => ./filename.extension
154 /// ./ => ? TODO: decide what semantics this has.
156 /// @param path A path that has its extension replaced with \a extension.
157 /// @param extension The extension to be added. It may be empty. It may also
158 /// optionally start with a '.', if it does not, one will be
160 /// @returns errc::success if \a path's extension has been replaced, otherwise a
161 /// platform specific error_code.
162 error_code replace_extension(SmallVectorImpl<char> &path,
163 const Twine &extension);
165 /// @brief Append to path.
167 /// /foo + bar/f => /foo/bar/f
168 /// /foo/ + bar/f => /foo/bar/f
169 /// foo + bar/f => foo/bar/f
171 /// @param path Set to \a path + \a component.
172 /// @param component The component to be appended to \a path.
173 /// @returns errc::success if \a component has been appended to \a path,
174 /// otherwise a platform specific error_code.
175 error_code append(SmallVectorImpl<char> &path, const Twine &a,
178 const Twine &d = "");
180 /// @brief Append to path.
182 /// /foo + [bar,f] => /foo/bar/f
183 /// /foo/ + [bar,f] => /foo/bar/f
184 /// foo + [bar,f] => foo/bar/f
186 /// @param path Set to \a path + [\a begin, \a end).
187 /// @param begin Start of components to append.
188 /// @param end One past the end of components to append.
189 /// @returns errc::success if [\a begin, \a end) has been appended to \a path,
190 /// otherwise a platform specific error_code.
191 error_code append(SmallVectorImpl<char> &path,
192 const_iterator begin, const_iterator end);
195 /// @name Transforms (or some other better name)
198 /// Convert path to the native form. This is used to give paths to users and
199 /// operating system calls in the platform's normal way. For example, on Windows
200 /// all '/' are converted to '\'.
202 /// @param path A path that is transformed to native format.
203 /// @param result Holds the result of the transformation.
204 /// @returns errc::success if \a path has been transformed and stored in result,
205 /// otherwise a platform specific error_code.
206 error_code native(const Twine &path, SmallVectorImpl<char> &result);
209 /// @name Lexical Observers
212 /// @brief Get the current path.
214 /// @param result Holds the current path on return.
215 /// @results errc::success if the current path has been stored in result,
216 /// otherwise a platform specific error_code.
217 error_code current_path(SmallVectorImpl<char> &result);
219 // The following are purely lexical.
221 /// @brief Get root name.
223 /// //net/hello => //net
224 /// c:/hello => c: (on Windows, on other platforms nothing)
225 /// /hello => <empty>
227 /// @param path Input path.
228 /// @param result Set to the root name of \a path if it has one, otherwise "".
229 /// @results errc::success if result has been successfully set, otherwise a
230 /// platform specific error_code.
231 error_code root_name(const StringRef &path, StringRef &result);
233 /// @brief Get root directory.
237 /// d/file.txt => <empty>
239 /// @param path Input path.
240 /// @param result Set to the root directory of \a path if it has one, otherwise
242 /// @results errc::success if result has been successfully set, otherwise a
243 /// platform specific error_code.
244 error_code root_directory(const StringRef &path, StringRef &result);
246 /// @brief Get root path.
248 /// Equivalent to root_name + root_directory.
250 /// @param path Input path.
251 /// @param result Set to the root path of \a path if it has one, otherwise "".
252 /// @results errc::success if result has been successfully set, otherwise a
253 /// platform specific error_code.
254 error_code root_path(const StringRef &path, StringRef &result);
256 /// @brief Get relative path.
258 /// C:\hello\world => hello\world
259 /// foo/bar => foo/bar
260 /// /foo/bar => foo/bar
262 /// @param path Input path.
263 /// @param result Set to the path starting after root_path if one exists,
265 /// @results errc::success if result has been successfully set, otherwise a
266 /// platform specific error_code.
267 error_code relative_path(const StringRef &path, StringRef &result);
269 /// @brief Get parent path.
273 /// foo/../bar => foo/..
275 /// @param path Input path.
276 /// @param result Set to the parent path of \a path if one exists, otherwise "".
277 /// @results errc::success if result has been successfully set, otherwise a
278 /// platform specific error_code.
279 error_code parent_path(const StringRef &path, StringRef &result);
281 /// @brief Get filename.
283 /// /foo.txt => foo.txt
288 /// @param path Input path.
289 /// @param result Set to the filename part of \a path. This is defined as the
290 /// last component of \a path.
291 /// @results errc::success if result has been successfully set, otherwise a
292 /// platform specific error_code.
293 error_code filename(const StringRef &path, StringRef &result);
297 /// If filename contains a dot but not solely one or two dots, result is the
298 /// substring of filename ending at (but not including) the last dot. Otherwise
301 /// /foo/bar.txt => bar
303 /// /foo/.txt => <empty>
307 /// @param path Input path.
308 /// @param result Set to the stem of \a path.
309 /// @results errc::success if result has been successfully set, otherwise a
310 /// platform specific error_code.
311 error_code stem(const StringRef &path, StringRef &result);
313 /// @brief Get extension.
315 /// If filename contains a dot but not solely one or two dots, result is the
316 /// substring of filename starting at (and including) the last dot, and ending
317 /// at the end of \a path. Otherwise "".
319 /// /foo/bar.txt => .txt
320 /// /foo/bar => <empty>
321 /// /foo/.txt => .txt
323 /// @param path Input path.
324 /// @param result Set to the extension of \a path.
325 /// @results errc::success if result has been successfully set, otherwise a
326 /// platform specific error_code.
327 error_code extension(const StringRef &path, StringRef &result);
329 /// @brief Has root name?
333 /// @param path Input path.
334 /// @param result Set to true if the path has a root name, false otherwise.
335 /// @results errc::success if result has been successfully set, otherwise a
336 /// platform specific error_code.
337 error_code has_root_name(const Twine &path, bool &result);
339 /// @brief Has root directory?
341 /// root_directory != ""
343 /// @param path Input path.
344 /// @param result Set to true if the path has a root directory, false otherwise.
345 /// @results errc::success if result has been successfully set, otherwise a
346 /// platform specific error_code.
347 error_code has_root_directory(const Twine &path, bool &result);
349 /// @brief Has root path?
353 /// @param path Input path.
354 /// @param result Set to true if the path has a root path, false otherwise.
355 /// @results errc::success if result has been successfully set, otherwise a
356 /// platform specific error_code.
357 error_code has_root_path(const Twine &path, bool &result);
359 /// @brief Has relative path?
361 /// relative_path != ""
363 /// @param path Input path.
364 /// @param result Set to true if the path has a relative path, false otherwise.
365 /// @results errc::success if result has been successfully set, otherwise a
366 /// platform specific error_code.
367 error_code has_relative_path(const Twine &path, bool &result);
369 /// @brief Has parent path?
371 /// parent_path != ""
373 /// @param path Input path.
374 /// @param result Set to true if the path has a parent path, false otherwise.
375 /// @results errc::success if result has been successfully set, otherwise a
376 /// platform specific error_code.
377 error_code has_parent_path(const Twine &path, bool &result);
379 /// @brief Has filename?
383 /// @param path Input path.
384 /// @param result Set to true if the path has a filename, false otherwise.
385 /// @results errc::success if result has been successfully set, otherwise a
386 /// platform specific error_code.
387 error_code has_filename(const Twine &path, bool &result);
393 /// @param path Input path.
394 /// @param result Set to true if the path has a stem, false otherwise.
395 /// @results errc::success if result has been successfully set, otherwise a
396 /// platform specific error_code.
397 error_code has_stem(const Twine &path, bool &result);
399 /// @brief Has extension?
403 /// @param path Input path.
404 /// @param result Set to true if the path has a extension, false otherwise.
405 /// @results errc::success if result has been successfully set, otherwise a
406 /// platform specific error_code.
407 error_code has_extension(const Twine &path, bool &result);
409 /// @brief Is path absolute?
411 /// @param path Input path.
412 /// @param result Set to true if the path is absolute, false if it is not.
413 /// @results errc::success if result has been successfully set, otherwise a
414 /// platform specific error_code.
415 error_code is_absolute(const Twine &path, bool &result);
417 /// @brief Is path relative?
419 /// @param path Input path.
420 /// @param result Set to true if the path is relative, false if it is not.
421 /// @results errc::success if result has been successfully set, otherwise a
422 /// platform specific error_code.
423 error_code is_relative(const Twine &path, bool &result);
424 // end purely lexical.
426 } // end namespace path
430 /// file_type - An "enum class" enumeration for the file system's view of the
446 file_type(_ v) : v_(v) {}
447 explicit file_type(int v) : v_(_(v)) {}
448 operator int() const {return v_;}
454 /// copy_option - An "enum class" enumeration of copy semantics for copy
462 copy_option(_ v) : v_(v) {}
463 explicit copy_option(int v) : v_(_(v)) {}
464 operator int() const {return v_;}
470 /// space_info - Self explanatory.
477 /// file_status - Represents the result of a call to stat and friends. It has
478 /// a platform specific member to store the result.
481 // implementation defined status field.
483 explicit file_status(file_type v=file_type::status_error);
485 file_type type() const;
486 void type(file_type v);
490 /// @name Physical Operators
493 /// @brief Copy the file at \a from to the path \a to.
495 /// @param from The path to copy the file from.
496 /// @param to The path to copy the file to.
497 /// @param copt Behavior if \a to already exists.
498 /// @returns errc::success if the file has been successfully copied.
499 /// errc::file_exists if \a to already exists and \a copt ==
500 /// copy_option::fail_if_exists. Otherwise a platform specific
502 error_code copy_file(const Twine &from, const Twine &to,
503 copy_option copt = copy_option::fail_if_exists);
505 /// @brief Create all the non-existent directories in path.
507 /// @param path Directories to create.
508 /// @param existed Set to true if \a path already existed, false otherwise.
509 /// @returns errc::success if is_directory(path) and existed have been set,
510 /// otherwise a platform specific error_code.
511 error_code create_directories(const Twine &path, bool &existed);
513 /// @brief Create the directory in path.
515 /// @param path Directory to create.
516 /// @param existed Set to true if \a path already existed, false otherwise.
517 /// @returns errc::success if is_directory(path) and existed have been set,
518 /// otherwise a platform specific error_code.
519 error_code create_directory(const Twine &path, bool &existed);
521 /// @brief Create a hard link from \a from to \a to.
523 /// @param to The path to hard link to.
524 /// @param from The path to hard link from. This is created.
525 /// @returns errc::success if exists(to) && exists(from) && equivalent(to, from)
526 /// , otherwise a platform specific error_code.
527 error_code create_hard_link(const Twine &to, const Twine &from);
529 /// @brief Create a symbolic link from \a from to \a to.
531 /// @param to The path to symbolically link to.
532 /// @param from The path to symbolically link from. This is created.
533 /// @returns errc::success if exists(to) && exists(from) && is_symlink(from),
534 /// otherwise a platform specific error_code.
535 error_code create_symlink(const Twine &to, const Twine &from);
537 /// @brief Remove path. Equivalent to POSIX remove().
539 /// @param path Input path.
540 /// @param existed Set to true if \a path existed, false if it did not.
541 /// undefined otherwise.
542 /// @results errc::success if path has been removed and existed has been
543 /// successfully set, otherwise a platform specific error_code.
544 error_code remove(const Twine &path, bool &existed);
546 /// @brief Recursively remove all files below \a path, then \a path. Files are
547 /// removed as if by POSIX remove().
549 /// @param path Input path.
550 /// @param num_removed Number of files removed.
551 /// @results errc::success if path has been removed and num_removed has been
552 /// successfully set, otherwise a platform specific error_code.
553 error_code remove_all(const Twine &path, uint32_t &num_removed);
555 /// @brief Rename \a from to \a to. Files are renamed as if by POSIX rename().
557 /// @param from The path to rename from.
558 /// @param to The path to rename to. This is created.
559 error_code rename(const Twine &from, const Twine &to);
561 /// @brief Resize path to size. File is resized as if by POSIX truncate().
563 /// @param path Input path.
564 /// @param size Size to resize to.
565 /// @returns errc::success if \a path has been resized to \a size, otherwise a
566 /// platform specific error_code.
567 error_code resize_file(const Twine &path, uint64_t size);
569 /// @brief Make file readable.
571 /// @param path Input path.
572 /// @param value If true, make readable, else, make unreadable.
573 /// @results errc::success if readability has been successfully set, otherwise a
574 /// platform specific error_code.
575 error_code set_read(const Twine &path, bool value);
577 /// @brief Make file writeable.
579 /// @param path Input path.
580 /// @param value If true, make writeable, else, make unwriteable.
581 /// @results errc::success if writeability has been successfully set, otherwise
582 /// a platform specific error_code.
583 error_code set_write(const Twine &path, bool value);
585 /// @brief Make file executable.
587 /// @param path Input path.
588 /// @param value If true, make executable, else, make unexecutable.
589 /// @results errc::success if executability has been successfully set, otherwise
590 /// a platform specific error_code.
591 error_code set_execute(const Twine &path, bool value);
594 /// @name Physical Observers
597 /// @brief Does file exist?
599 /// @param status A file_status previously returned from stat.
600 /// @param result Set to true if the file represented by status exists, false if
601 /// it does not. Undefined otherwise.
602 /// @results errc::success if result has been successfully set, otherwise a
603 /// platform specific error_code.
604 error_code exists(file_status status, bool &result);
606 /// @brief Does file exist?
608 /// @param path Input path.
609 /// @param result Set to true if the file represented by status exists, false if
610 /// it does not. Undefined otherwise.
611 /// @results errc::success if result has been successfully set, otherwise a
612 /// platform specific error_code.
613 error_code exists(const Twine &path, bool &result);
615 /// @brief Do paths represent the same thing?
617 /// @param A Input path A.
618 /// @param B Input path B.
619 /// @param result Set to true if stat(A) and stat(B) have the same device and
620 /// inode (or equivalent).
621 /// @results errc::success if result has been successfully set, otherwise a
622 /// platform specific error_code.
623 error_code equivalent(const Twine &A, const Twine &B, bool &result);
625 /// @brief Get file size.
627 /// @param path Input path.
628 /// @param result Set to the size of the file in \a path.
629 /// @returns errc::success if result has been successfully set, otherwise a
630 /// platform specific error_code.
631 error_code file_size(const Twine &path, uint64_t &result);
633 /// @brief Does status represent a directory?
635 /// @param status A file_status previously returned from stat.
636 /// @param result Set to true if the file represented by status is a directory,
637 /// false if it is not. Undefined otherwise.
638 /// @results errc::success if result has been successfully set, otherwise a
639 /// platform specific error_code.
640 error_code is_directory(file_status status, bool &result);
642 /// @brief Is path a directory?
644 /// @param path Input path.
645 /// @param result Set to true if \a path is a directory, false if it is not.
646 /// Undefined otherwise.
647 /// @results errc::success if result has been successfully set, otherwise a
648 /// platform specific error_code.
649 error_code is_directory(const Twine &path, bool &result);
651 /// @brief Is path an empty file?
653 /// @param path Input path.
654 /// @param result Set to true if \a path is a an empty file, false if it is not.
655 /// Undefined otherwise.
656 /// @results errc::success if result has been successfully set, otherwise a
657 /// platform specific error_code.
658 error_code is_empty(const Twine &path, bool &result);
660 /// @brief Does status represent a regular file?
662 /// @param status A file_status previously returned from stat.
663 /// @param result Set to true if the file represented by status is a regular
664 /// file, false if it is not. Undefined otherwise.
665 /// @results errc::success if result has been successfully set, otherwise a
666 /// platform specific error_code.
667 error_code is_regular_file(file_status status, bool &result);
669 /// @brief Is path a regular file?
671 /// @param path Input path.
672 /// @param result Set to true if \a path is a regular file, false if it is not.
673 /// Undefined otherwise.
674 /// @results errc::success if result has been successfully set, otherwise a
675 /// platform specific error_code.
676 error_code is_regular_file(const Twine &path, bool &result);
678 /// @brief Does status represent something that exists but is not a directory,
679 /// regular file, or symlink?
681 /// @param status A file_status previously returned from stat.
682 /// @param result Set to true if the file represented by status exists, but is
683 /// not a directory, regular file, or a symlink, false if it does
684 /// not. Undefined otherwise.
685 /// @results errc::success if result has been successfully set, otherwise a
686 /// platform specific error_code.
687 error_code is_other(file_status status, bool &result);
689 /// @brief Is path something that exists but is not a directory,
690 /// regular file, or symlink?
692 /// @param path Input path.
693 /// @param result Set to true if \a path exists, but is not a directory, regular
694 /// file, or a symlink, false if it does not. Undefined otherwise.
695 /// @results errc::success if result has been successfully set, otherwise a
696 /// platform specific error_code.
697 error_code is_other(const Twine &path, bool &result);
699 /// @brief Does status represent a symlink?
701 /// @param status A file_status previously returned from stat.
702 /// @param result Set to true if the file represented by status is a symlink,
703 /// false if it is not. Undefined otherwise.
704 /// @results errc::success if result has been successfully set, otherwise a
705 /// platform specific error_code.
706 error_code is_symlink(file_status status, bool &result);
708 /// @brief Is path a symlink?
710 /// @param path Input path.
711 /// @param result Set to true if \a path is a symlink, false if it is not.
712 /// Undefined otherwise.
713 /// @results errc::success if result has been successfully set, otherwise a
714 /// platform specific error_code.
715 error_code is_symlink(const Twine &path, bool &result);
717 /// @brief Get last write time without changing it.
719 /// @param path Input path.
720 /// @param result Set to the last write time (UNIX time) of \a path if it
722 /// @results errc::success if result has been successfully set, otherwise a
723 /// platform specific error_code.
724 error_code last_write_time(const Twine &path, std::time_t &result);
726 /// @brief Set last write time.
728 /// @param path Input path.
729 /// @param value Time to set (UNIX time) \a path's last write time to.
730 /// @results errc::success if result has been successfully set, otherwise a
731 /// platform specific error_code.
732 error_code set_last_write_time(const Twine &path, std::time_t value);
734 /// @brief Read a symlink's value.
736 /// @param path Input path.
737 /// @param result Set to the value of the symbolic link \a path.
738 /// @results errc::success if result has been successfully set, otherwise a
739 /// platform specific error_code.
740 error_code read_symlink(const Twine &path, SmallVectorImpl<char> &result);
742 /// @brief Get disk space usage information.
744 /// @param path Input path.
745 /// @param result Set to the capacity, free, and available space on the device
747 /// @results errc::success if result has been successfully set, otherwise a
748 /// platform specific error_code.
749 error_code disk_space(const Twine &path, space_info &result);
751 /// @brief Get file status as if by POSIX stat().
753 /// @param path Input path.
754 /// @param result Set to the file status.
755 /// @results errc::success if result has been successfully set, otherwise a
756 /// platform specific error_code.
757 error_code status(const Twine &path, file_status &result);
759 /// @brief Is status available?
761 /// @param path Input path.
762 /// @param result Set to true if status() != status_error.
763 /// @results errc::success if result has been successfully set, otherwise a
764 /// platform specific error_code.
765 error_code status_known(const Twine &path, bool &result);
767 /// @brief Get file status as if by POSIX lstat().
769 /// Does not resolve symlinks.
771 /// @param path Input path.
772 /// @param result Set to the file status.
773 /// @results errc::success if result has been successfully set, otherwise a
774 /// platform specific error_code.
775 error_code symlink_status(const Twine &path, file_status &result);
777 /// @brief Get the temporary directory.
779 /// @param result Set to the temporary directory.
780 /// @results errc::success if result has been successfully set, otherwise a
781 /// platform specific error_code.
783 error_code temp_directory_path(SmallVectorImpl<char> &result);
785 /// @brief Generate a unique path and open it as a file.
787 /// Generates a unique path suitable for a temporary file and then opens it as a
788 /// file. The name is based on \a model with '%' replaced by a random char in
791 /// This is an atomic operation. Either the file is created and opened, or the
792 /// file system is left untouched.
794 /// clang-%%-%%-%%-%%-%%.s => <current-directory>/clang-a0-b1-c2-d3-e4.s
796 /// @param model Name to base unique path off of.
797 /// @param result Set to the opened file.
798 /// @results errc::success if result has been successfully set, otherwise a
799 /// platform specific error_code.
800 /// @see temp_directory_path
801 error_code unique_file(const Twine &model, void* i_have_not_decided_the_ty_yet);
803 /// @brief Canonicalize path.
805 /// Sets result to the file system's idea of what path is. The result is always
806 /// absolute and has the same capitalization as the file system.
808 /// @param path Input path.
809 /// @param result Set to the canonicalized version of \a path.
810 /// @results errc::success if result has been successfully set, otherwise a
811 /// platform specific error_code.
812 error_code canonicalize(const Twine &path, SmallVectorImpl<char> &result);
814 /// @brief Are \a path's first bytes \a magic?
816 /// @param path Input path.
817 /// @param magic Byte sequence to compare \a path's first len(magic) bytes to.
818 /// @results errc::success if result has been successfully set, otherwise a
819 /// platform specific error_code.
820 error_code has_magic(const Twine &path, const Twine &magic);
822 /// @brief Get \a path's first \a len bytes.
824 /// @param path Input path.
825 /// @param len Number of magic bytes to get.
826 /// @param result Set to the first \a len bytes in the file pointed to by
828 /// @results errc::success if result has been successfully set, otherwise a
829 /// platform specific error_code.
830 error_code get_magic(const Twine &path, uint32_t len,
831 SmallVectorImpl<char> &result);
833 /// @brief Is file bitcode?
835 /// @param path Input path.
836 /// @param result Set to true if \a path is a bitcode file, false if it is not,
837 /// undefined otherwise.
838 /// @results errc::success if result has been successfully set, otherwise a
839 /// platform specific error_code.
840 error_code is_bitcode(const Twine &path, bool &result);
842 /// @brief Is file a dynamic library?
844 /// @param path Input path.
845 /// @param result Set to true if \a path is a dynamic library, false if it is
846 /// not, undefined otherwise.
847 /// @results errc::success if result has been successfully set, otherwise a
848 /// platform specific error_code.
849 error_code is_dynamic_library(const Twine &path, bool &result);
851 /// @brief Is an object file?
853 /// @param path Input path.
854 /// @param result Set to true if \a path is an object file, false if it is not,
855 /// undefined otherwise.
856 /// @results errc::success if result has been successfully set, otherwise a
857 /// platform specific error_code.
858 error_code is_object_file(const Twine &path, bool &result);
860 /// @brief Can file be read?
862 /// @param path Input path.
863 /// @param result Set to true if \a path is readable, false it it is not,
864 /// undefined otherwise.
865 /// @results errc::success if result has been successfully set, otherwise a
866 /// platform specific error_code.
867 error_code can_read(const Twine &path, bool &result);
869 /// @brief Can file be written?
871 /// @param path Input path.
872 /// @param result Set to true if \a path is writeable, false it it is not,
873 /// undefined otherwise.
874 /// @results errc::success if result has been successfully set, otherwise a
875 /// platform specific error_code.
876 error_code can_write(const Twine &path, bool &result);
878 /// @brief Can file be executed?
880 /// @param path Input path.
881 /// @param result Set to true if \a path is executable, false it it is not,
882 /// undefined otherwise.
883 /// @results errc::success if result has been successfully set, otherwise a
884 /// platform specific error_code.
885 error_code can_execute(const Twine &path, bool &result);
887 /// @brief Get library paths the system linker uses.
889 /// @param result Set to the list of system library paths.
890 /// @results errc::success if result has been successfully set, otherwise a
891 /// platform specific error_code.
892 error_code GetSystemLibraryPaths(SmallVectorImpl<std::string> &result);
894 /// @brief Get bitcode library paths the system linker uses
895 /// + LLVM_LIB_SEARCH_PATH + LLVM_LIBDIR.
897 /// @param result Set to the list of bitcode library paths.
898 /// @results errc::success if result has been successfully set, otherwise a
899 /// platform specific error_code.
900 error_code GetBitcodeLibraryPaths(SmallVectorImpl<std::string> &result);
902 /// @brief Find a library.
904 /// Find the path to a library using its short name. Use the system
905 /// dependent library paths to locate the library.
907 /// c => /usr/lib/libc.so
909 /// @param short_name Library name one would give to the system linker.
910 /// @param result Set to the absolute path \a short_name represents.
911 /// @results errc::success if result has been successfully set, otherwise a
912 /// platform specific error_code.
913 error_code FindLibrary(const Twine &short_name, SmallVectorImpl<char> &result);
915 /// @brief Get absolute path of main executable.
917 /// @param argv0 The program name as it was spelled on the command line.
918 /// @param MainAddr Address of some symbol in the executable (not in a library).
919 /// @param result Set to the absolute path of the current executable.
920 /// @results errc::success if result has been successfully set, otherwise a
921 /// platform specific error_code.
922 error_code GetMainExecutable(const char *argv0, void *MainAddr,
923 SmallVectorImpl<char> &result);
929 /// directory_entry - A single entry in a directory. Caches the status either
930 /// from the result of the iteration syscall, or the first time status or
931 /// symlink_status is called.
932 class directory_entry {
934 mutable file_status Status;
935 mutable file_status SymlinkStatus;
938 explicit directory_entry(const Twine &path, file_status st = file_status(),
939 file_status symlink_st = file_status());
941 void assign(const Twine &path, file_status st = file_status(),
942 file_status symlink_st = file_status());
943 void replace_filename(const Twine &filename, file_status st = file_status(),
944 file_status symlink_st = file_status());
946 const SmallVectorImpl<char> &path() const;
947 error_code status(file_status &result) const;
948 error_code symlink_status(file_status &result) const;
950 bool operator==(const directory_entry& rhs) const;
951 bool operator!=(const directory_entry& rhs) const;
952 bool operator< (const directory_entry& rhs) const;
953 bool operator<=(const directory_entry& rhs) const;
954 bool operator> (const directory_entry& rhs) const;
955 bool operator>=(const directory_entry& rhs) const;
958 /// directory_iterator - Iterates through the entries in path. There is no
959 /// operator++ because we need an error_code. If it's really needed we can make
960 /// it call report_fatal_error on error.
961 class directory_iterator {
962 // implementation directory iterator status
965 explicit directory_iterator(const Twine &path, error_code &ec);
966 // No operator++ because we need error_code.
967 directory_iterator &increment(error_code &ec);
969 const directory_entry &operator*() const;
970 const directory_entry *operator->() const;
972 // Other members as required by
973 // C++ Std, 24.1.1 Input iterators [input.iterators]
976 /// recursive_directory_iterator - Same as directory_iterator except for it
977 /// recurses down into child directories.
978 class recursive_directory_iterator {
980 bool HasNoPushRequest;
981 // implementation directory iterator status
984 explicit recursive_directory_iterator(const Twine &path, error_code &ec);
985 // No operator++ because we need error_code.
986 directory_iterator &increment(error_code &ec);
988 const directory_entry &operator*() const;
989 const directory_entry *operator->() const;
992 /// Gets the current level. path is at level 0.
994 /// Returns true if no_push has been called for this directory_entry.
995 bool no_push_request() const;
998 /// Goes up one level if Level > 0.
1000 /// Does not go down into the current directory_entry.
1003 // Other members as required by
1004 // C++ Std, 24.1.1 Input iterators [input.iterators]
1009 } // end namespace fs
1010 } // end namespace sys
1011 } // end namespace llvm