xref: /aosp_15_r20/external/cronet/net/third_party/quiche/src/quiche/common/platform/api/quiche_file_utils.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2021 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 // This header contains basic filesystem functions for use in unit tests and CLI
6 // tools.  Note that those are not 100% suitable for production use, as in, they
7 // might be prone to race conditions and not always handle non-ASCII filenames
8 // correctly.
9 #ifndef QUICHE_COMMON_PLATFORM_API_QUICHE_FILE_UTILS_H_
10 #define QUICHE_COMMON_PLATFORM_API_QUICHE_FILE_UTILS_H_
11 
12 #include <optional>
13 #include <string>
14 #include <vector>
15 
16 #include "absl/strings/string_view.h"
17 
18 namespace quiche {
19 
20 // Join two paths in a platform-specific way.  Returns |a| if |b| is empty, and
21 // vice versa.
22 std::string JoinPath(absl::string_view a, absl::string_view b);
23 
24 // Reads the entire file into the memory.
25 std::optional<std::string> ReadFileContents(absl::string_view file);
26 
27 // Lists all files and directories in the directory specified by |path|. Returns
28 // true on success, false on failure.
29 bool EnumerateDirectory(absl::string_view path,
30                         std::vector<std::string>& directories,
31                         std::vector<std::string>& files);
32 
33 // Recursively enumerates all of the files in the directory and all of the
34 // internal subdirectories.  Has a fairly small recursion limit.
35 bool EnumerateDirectoryRecursively(absl::string_view path,
36                                    std::vector<std::string>& files);
37 
38 }  // namespace quiche
39 
40 #endif  // QUICHE_COMMON_PLATFORM_API_QUICHE_FILE_UTILS_H_
41