HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
filesystem.h
Go to the documentation of this file.
1 // Copyright Contributors to the OpenImageIO project.
2 // SPDX-License-Identifier: Apache-2.0
3 // https://github.com/AcademySoftwareFoundation/OpenImageIO
4 
5 // clang-format off
6 
7 /// @file filesystem.h
8 ///
9 /// @brief Utilities for dealing with file names and files portably.
10 ///
11 /// Some helpful nomenclature:
12 /// - "filename" - a file or directory name, relative or absolute
13 /// - "searchpath" - a list of directories separated by ':' or ';'.
14 ///
15 
16 
17 #pragma once
18 
19 #define OIIO_FILESYSTEM_H
20 
21 #include <cstdint>
22 #include <cstdio>
23 #include <ctime>
24 #include <fstream>
25 #include <mutex>
26 #include <string>
27 #include <vector>
28 
29 #include <OpenImageIO/export.h>
31 #include <OpenImageIO/span.h>
32 #include <OpenImageIO/strutil.h>
34 
35 #if defined(_WIN32) && defined(__GLIBCXX__)
36 # define OIIO_FILESYSTEM_USE_STDIO_FILEBUF 1
38 #endif
39 
40 
41 // Define symbols that let client applications determine if newly added
42 // features are supported.
43 #define OIIO_FILESYSTEM_SUPPORTS_IOPROXY 1
44 
45 
46 
48 
49 #if OIIO_FILESYSTEM_USE_STDIO_FILEBUF
50 // MingW uses GCC to build, but does not support having a wchar_t* passed as argument
51 // of ifstream::open or ofstream::open. To properly support UTF-8 encoding on MingW we must
52 // use the __gnu_cxx::stdio_filebuf GNU extension that can be used with _wfsopen and returned
53 // into a istream which share the same API as ifsteam. The same reasoning holds for ofstream.
54 typedef basic_ifstream<char> ifstream;
55 typedef basic_ofstream<char> ofstream;
56 #else
59 #endif
60 
61 /// @namespace Filesystem
62 ///
63 /// @brief Platform-independent utilities for manipulating file names,
64 /// files, directories, and other file system miscellany.
65 
66 namespace Filesystem {
67 
68 /// Return the filename (excluding any directories, but including the
69 /// file extension, if any) of a UTF-8 encoded filepath.
70 OIIO_UTIL_API std::string filename (string_view filepath) noexcept;
71 
72 /// Return the file extension (including the last '.' if
73 /// include_dot=true) of a UTF-8 encoded filename or filepath.
74 OIIO_UTIL_API std::string extension (string_view filepath,
75  bool include_dot=true) noexcept;
76 
77 /// Return all but the last part of the UTF-8 encoded path, for example,
78 /// parent_path("foo/bar") returns "foo", and parent_path("foo")
79 /// returns "".
80 OIIO_UTIL_API std::string parent_path (string_view filepath) noexcept;
81 
82 /// Replace the file extension of a UTF-8 encoded filename or filepath. Does
83 /// not alter filepath, just returns a new string. Note that the
84 /// new_extension should contain a leading '.' dot.
85 OIIO_UTIL_API std::string replace_extension (const std::string &filepath,
86  const std::string &new_extension) noexcept;
87 
88 /// Return the filepath in generic format, not any OS-specific conventions.
89 /// Input and output are both UTF-8 encoded.
90 OIIO_UTIL_API std::string generic_filepath (string_view filepath) noexcept;
91 
92 /// Turn a searchpath (multiple UTF-8 encoded directory paths separated by ':'
93 /// or ';') into a vector<string> containing the name of each individual
94 /// directory. If validonly is true, only existing and readable directories
95 /// will end up in the list. N.B., the directory names will not have trailing
96 /// slashes.
97 OIIO_UTIL_API std::vector<std::string>
98 searchpath_split(string_view searchpath, bool validonly = false);
99 
100 inline void searchpath_split (string_view searchpath,
101  std::vector<std::string> &dirs,
102  bool validonly = false)
103 {
104  dirs = searchpath_split(searchpath, validonly);
105 }
106 
107 /// Find the first instance of a filename existing in a vector of
108 /// directories, returning the full path as a string. If the file is
109 /// not found in any of the listed directories, return an empty string.
110 /// If the filename is absolute, the directory list will not be used.
111 /// If testcwd is true, "." will be tested before the searchpath;
112 /// otherwise, "." will only be tested if it's explicitly in dirs. If
113 /// recursive is true, the directories will be searched recursively,
114 /// finding a matching file in any subdirectory of the directories
115 /// listed in dirs; otherwise. All file and directory names are presumed
116 /// to be UTF-8 encoded.
117 OIIO_UTIL_API std::string searchpath_find (const std::string &filename,
118  const std::vector<std::string> &dirs,
119  bool testcwd = true,
120  bool recursive = false);
121 
122 /// Find the given program in the `$PATH` searchpath and return its full path.
123 /// If the program is not found, return an empty string.
125 
126 /// Fill a vector-of-strings with the names of all files contained by
127 /// directory dirname. If recursive is true, it will return all files below
128 /// the directory (even in subdirectories). If filter_regex is supplied and
129 /// non-empty, only filenames matching the regular expression will be
130 /// returned. Return true if ok, false if there was an error (such as
131 /// dirname not being found or not actually being a directory). All file
132 /// and directory names are presumed to be UTF-8 encoded.
133 OIIO_UTIL_API bool get_directory_entries (const std::string &dirname,
134  std::vector<std::string> &filenames,
135  bool recursive = false,
136  const std::string &filter_regex=std::string());
137 
138 /// Return true if the UTF-8 encoded path is an "absolute" (not relative)
139 /// path. If 'dot_is_absolute' is true, consider "./foo" absolute.
141  bool dot_is_absolute=false);
142 
143 /// Return true if the UTF-8 encoded path exists.
144 ///
145 OIIO_UTIL_API bool exists (string_view path) noexcept;
146 
147 
148 /// Return true if the UTF-8 encoded path exists and is a directory.
149 ///
151 
152 /// Return true if the UTF-8 encoded path exists and is a regular file.
153 ///
154 OIIO_UTIL_API bool is_regular (string_view path) noexcept;
155 
156 /// Return true if the UTF-8 encoded path is an executable file (by any of
157 /// user, group, or owner).
159 
160 /// Create the directory, whose name is UTF-8 encoded. Return true for
161 /// success, false for failure and place an error message in err.
162 OIIO_UTIL_API bool create_directory (string_view path, std::string &err);
164  std::string err;
165  return create_directory (path, err);
166 }
167 
168 /// Copy a file, directory, or link. It is an error if 'to' already exists.
169 /// The file names are all UTF-8 encoded. Return true upon success, false upon
170 /// failure and place an error message in err.
171 OIIO_UTIL_API bool copy (string_view from, string_view to, std::string &err);
172 inline bool copy (string_view from, string_view to) {
173  std::string err;
174  return copy (from, to, err);
175 }
176 
177 /// Rename (or move) a file, directory, or link. The file names are all UTF-8
178 /// encoded. Return true upon success, false upon failure and place an error
179 /// message in err.
180 OIIO_UTIL_API bool rename (string_view from, string_view to, std::string &err);
181 inline bool rename (string_view from, string_view to) {
182  std::string err;
183  return rename (from, to, err);
184 }
185 
186 /// Remove the file or directory. The file names are all UTF-8 encoded. Return
187 /// true for success, false for failure and place an error message in err.
188 OIIO_UTIL_API bool remove (string_view path, std::string &err);
189 inline bool remove (string_view path) {
190  std::string err;
191  return remove (path, err);
192 }
193 
194 /// Remove the file or directory, including any children (recursively). The
195 /// file names are all UTF-8 encoded. Return the number of files removed.
196 /// Place an error message (if applicable in err.
197 OIIO_UTIL_API unsigned long long remove_all (string_view path, std::string &err);
198 inline unsigned long long remove_all (string_view path) {
199  std::string err;
200  return remove_all (path, err);
201 }
202 
203 /// Return a directory path (UTF-8 encoded) where temporary files can be made.
204 ///
205 OIIO_UTIL_API std::string temp_directory_path ();
206 
207 /// Return a unique filename suitable for making a temporary file or
208 /// directory. The file names are all UTF-8 encoded.
209 /// NOTE: this function is not recommended, because it's a known security
210 /// and stability issue, since another process *could* create a file of the
211 /// same name after the path is retrieved but before it is created. So in
212 /// the long run, we want to wean ourselves off this. But in practice, it's
213 /// not an emergency. We'll replace this with something else eventually.
214 OIIO_UTIL_API std::string unique_path (string_view model="%%%%-%%%%-%%%%-%%%%");
215 
216 /// Version of fopen that can handle UTF-8 paths even on Windows.
218 
219 /// Version of fseek that works with 64 bit offsets on all systems.
220 /// Like std::fseek, returns zero on success, nonzero on failure.
221 OIIO_UTIL_API int fseek (FILE *file, int64_t offset, int whence);
222 
223 /// Version of ftell that works with 64 bit offsets on all systems.
224 OIIO_UTIL_API int64_t ftell (FILE *file);
225 
226 /// Return the current (".") directory path.
227 ///
228 OIIO_UTIL_API std::string current_path ();
229 
230 /// Version of std::ifstream.open that can handle UTF-8 paths
231 ///
233  std::ios_base::openmode mode = std::ios_base::in);
234 
235 /// Version of std::ofstream.open that can handle UTF-8 paths
236 ///
238  std::ios_base::openmode mode = std::ios_base::out);
239 
240 /// Version of C open() that can handle UTF-8 paths, returning an integer
241 /// file descriptor. Note that the flags are passed to underlying calls to
242 /// open()/_open() and therefore may be OS specific -- use with caution! If
243 /// you want more OS-agnostic file opening, prefer the FILE or stream
244 /// methods of IO. (N.B.: use of this function requires the caller to
245 /// `#include <fcntl.h>` in order to get the definitions of the flags.)
247 
248 /// Read the entire contents of the named text file (as a UTF-8 encoded
249 /// filename) and place it in str, returning true on success, false on
250 /// failure. The optional size parameter gives the maximum amount to read
251 /// (for memory safety) and defaults to 16MB. Set size to 0 for no limit
252 /// (use at your own risk).
253 OIIO_UTIL_API bool read_text_file(string_view filename, std::string &str,
254  size_t size = (1UL << 24));
255 
256 /// Run a command line process and capture its console output in `str`,
257 /// returning true on success, false on failure. The optional size parameter
258 /// gives the maximum amount to read (for memory safety) and defaults to 16MB.
259 /// Set size to 0 for no limit (use at your own risk).
261  std::string &str,
262  size_t size = (1UL << 24));
263 
264 /// Write the entire contents of the string `str` to the named file (UTF-8
265 /// encoded), overwriting any prior contents of the file (if it existed),
266 /// returning true on success, false on failure.
268 
269 /// Write the entire contents of the span `data` to the file (UTF-8 encoded)
270 /// as a binary blob, overwriting any prior contents of the file (if it
271 /// existed), returning true on success, false on failure.
272 template<typename T>
274 {
275  OIIO::ofstream out;
276  Filesystem::open(out, filename, std::ios::out | std::ios::binary);
277  out.write((const char*)data.data(), data.size() * sizeof(T));
278  return out.good();
279 }
280 
281 template<typename T>
282 bool write_binary_file (string_view filename, const std::vector<T>& data)
283 {
284  return write_binary_file(filename, cspan<T>(data));
285 }
286 
287 /// Read a maximum of n bytes from the named file, starting at position pos
288 /// (which defaults to the start of the file), storing results in
289 /// buffer[0..n-1]. Return the number of bytes read, which will be n for
290 /// full success, less than n if the file was fewer than n+pos bytes long,
291 /// or 0 if the file did not exist or could not be read.
292 OIIO_UTIL_API size_t read_bytes (string_view path, void *buffer, size_t n,
293  size_t pos=0);
294 
295 /// Get last modified time of the file named by `path` (UTF-8 encoded).
296 ///
297 OIIO_UTIL_API std::time_t last_write_time (string_view path) noexcept;
298 
299 /// Set last modified time on the file named by `path` (UTF-8 encoded).
300 ///
301 OIIO_UTIL_API void last_write_time (string_view path, std::time_t time) noexcept;
302 
303 /// Return the size of the file (in bytes), or uint64_t(-1) if there is any
304 /// error. The file name is UTF-8 encoded.
305 OIIO_UTIL_API uint64_t file_size (string_view path) noexcept;
306 
307 /// Ensure command line arguments are UTF-8 everywhere.
308 OIIO_UTIL_API void convert_native_arguments (int argc, const char *argv[]);
309 
310 /// Turn a sequence description string into a vector of integers.
311 /// The sequence description can be any of the following
312 /// * A value (e.g., "3")
313 /// * A value range ("1-10", "10-1", "1-10x3", "1-10y3"):
314 /// START-FINISH A range, inclusive of start & finish
315 /// START-FINISHxSTEP A range with step size
316 /// START-FINISHySTEP The complement of a stepped range, that is,
317 /// all numbers within the range that would
318 /// NOT have been selected by 'x'.
319 /// Note that START may be > FINISH, or STEP may be negative.
320 /// * Multiple values or ranges, separated by a comma (e.g., "3,4,10-20x2")
321 /// Return true upon success, false if the description was too malformed
322 /// to generate a sequence.
324  std::vector<int> &numbers);
325 
326 /// Given a pattern (such as "foo.#.tif" or "bar.1-10#.exr"), return a
327 /// normalized pattern in printf format (such as "foo.%04d.tif") and a
328 /// framespec (such as "1-10").
329 ///
330 /// If framepadding_override is > 0, it overrides any specific padding amount
331 /// in the original pattern.
332 ///
333 /// Return true upon success, false if the description was too malformed
334 /// to generate a sequence.
335 OIIO_UTIL_API bool parse_pattern (const char *pattern,
336  int framepadding_override,
337  std::string &normalized_pattern,
338  std::string &framespec);
339 
340 
341 /// Given a normalized pattern (such as "foo.%04d.tif") and a list of frame
342 /// numbers, generate a list of filenames. All the filename strings will be
343 /// presumed to be UTF-8 encoded.
344 ///
345 /// Return true upon success, false if the description was too malformed
346 /// to generate a sequence.
347 OIIO_UTIL_API bool enumerate_file_sequence (const std::string &pattern,
348  const std::vector<int> &numbers,
349  std::vector<std::string> &filenames);
350 
351 /// Given a normalized pattern (such as "foo_%V.%04d.tif") and a list of frame
352 /// numbers, generate a list of filenames. "views" is list of per-frame views,
353 /// or empty. In each frame filename, "%V" is replaced with the view, and "%v"
354 /// is replaced with the first character of the view. All the filename strings
355 /// will be presumed to be UTF-8 encoded.
356 ///
357 /// Return true upon success, false if the description was too malformed to
358 /// generate a sequence.
359 OIIO_UTIL_API bool enumerate_file_sequence (const std::string &pattern,
360  const std::vector<int> &numbers,
361  const std::vector<string_view> &views,
362  std::vector<std::string> &filenames);
363 
364 /// Given a normalized pattern (such as "/path/to/foo.%04d.tif") scan the
365 /// containing directory (/path/to) for matching frame numbers, views and
366 /// files. "%V" in the pattern matches views, while "%v" matches the first
367 /// character of each entry in views. All the filename strings will be
368 /// presumed to be UTF-8 encoded.
369 ///
370 /// Return true upon success, false if the directory doesn't exist or the
371 /// pattern can't be parsed.
372 OIIO_UTIL_API bool scan_for_matching_filenames (const std::string &pattern,
373  const std::vector<string_view> &views,
374  std::vector<int> &frame_numbers,
375  std::vector<string_view> &frame_views,
376  std::vector<std::string> &filenames);
377 
378 /// Given a normalized pattern (such as "/path/to/foo.%04d.tif") scan the
379 /// containing directory (/path/to) for matching frame numbers and files. All
380 /// the filename strings will be presumed to be UTF-8 encoded.
381 ///
382 /// Return true upon success, false if the directory doesn't exist or the
383 /// pattern can't be parsed.
384 OIIO_UTIL_API bool scan_for_matching_filenames (const std::string &pattern,
385  std::vector<int> &numbers,
386  std::vector<std::string> &filenames);
387 
388 /// Convert a UTF-8 encoded filename into a regex-safe pattern -- any special
389 /// regex characters `.`, `(`, `)`, `[`, `]`, `{`, `}` are backslashed. If
390 /// `simple_glob` is also true, then replace `?` with `.?` and `*` with `.*`.
391 /// This doesn't support full Unix command line glob syntax (no char sets
392 /// `[abc]` or string sets `{ab,cd,ef}`), but it does handle simple globbing
393 /// of `?` to mean any single character and `*` to mean any sequence of 0 or
394 /// more characters.
396  bool simple_glob = true);
397 
398 
399 
400 /// Proxy class for I/O. This provides a simplified interface for file I/O
401 /// that can have custom overrides. All char-based filenames are assumed to be
402 /// UTF-8 encoded.
404 public:
405  enum Mode { Closed = 0, Read = 'r', Write = 'w' };
406  IOProxy () {}
408  : m_filename(filename), m_mode(mode) {}
409  IOProxy(const std::wstring& filename, Mode mode)
410  : IOProxy(Strutil::utf16_to_utf8(filename), mode) {}
411  virtual ~IOProxy () { }
412  virtual const char* proxytype () const = 0;
413  virtual void close () { }
414  virtual bool opened () const { return mode() != Closed; }
415  virtual int64_t tell () { return m_pos; }
416  // Seek to the position, returning true on success, false on failure.
417  // Note the difference between this and std::fseek() which returns 0 on
418  // success, and -1 on failure.
419  virtual bool seek (int64_t offset) { m_pos = offset; return true; }
420  // Read `size` bytes at the current position into `buf[]`, returning the
421  // number of bytes successfully read.
422  virtual size_t read (void *buf, size_t size);
423  // Write `size` bytes from `buf[]` at the current position, returning the
424  // number of bytes successfully written.
425  virtual size_t write (const void *buf, size_t size);
426 
427  /// Read `size` bytes starting at the `offset` position into `buf[]`,
428  /// returning the number of bytes successfully read. This function does
429  /// not alter the current file position. This function is thread-safe against
430  /// all other concurrent calls to pread() and pwrite(), but not against any
431  /// other function of IOProxy.
432  virtual size_t pread (void *buf, size_t size, int64_t offset);
433 
434  /// Write `size` bytes from `buf[]` to file starting at the `offset` position,
435  /// returning the number of bytes successfully written. This function does
436  /// not alter the current file position. This function is thread-safe against
437  /// all other concurrent calls to pread() and pwrite(), but not against any
438  /// other function of IOProxy.
439  virtual size_t pwrite (const void *buf, size_t size, int64_t offset);
440 
441  // Return the total size of the proxy data, in bytes.
442  virtual size_t size () const { return 0; }
443  virtual void flush () const { }
444 
445  Mode mode () const { return m_mode; }
446  const std::string& filename () const { return m_filename; }
447  template<class T> size_t read (span<T> buf) {
448  return read (buf.data(), buf.size()*sizeof(T));
449  }
450  template<class T> size_t write (span<T> buf) {
451  return write (buf.data(), buf.size()*sizeof(T));
452  }
453  size_t write (string_view buf) {
454  return write (buf.data(), buf.size());
455  }
456  bool seek (int64_t offset, int origin) {
457  return seek ((origin == SEEK_SET ? offset : 0) +
458  (origin == SEEK_CUR ? offset+tell() : 0) +
459  (origin == SEEK_END ? offset+int64_t(size()) : 0));
460  }
461 
462  #define OIIO_IOPROXY_HAS_ERROR 1
463  std::string error() const;
464  void error(string_view e);
465 
466 protected:
467  std::string m_filename;
468  int64_t m_pos = 0;
469  Mode m_mode = Closed;
470  std::string m_error;
471 };
472 
473 
474 /// IOProxy subclass for reading or writing (but not both) that wraps C
475 /// stdio 'FILE'.
476 class OIIO_UTIL_API IOFile : public IOProxy {
477 public:
478  // Construct from a filename, open, own the FILE*.
479  IOFile(string_view filename, Mode mode);
480  IOFile(const std::wstring& filename, Mode mode)
481  : IOFile(Strutil::utf16_to_utf8(filename), mode) {}
482  // Construct from an already-open FILE* that is owned by the caller.
483  // Caller is responsible for closing the FILE* after the proxy is gone.
484  IOFile(FILE* file, Mode mode);
485  ~IOFile() override;
486  const char* proxytype() const override { return "file"; }
487  void close() override;
488  bool seek(int64_t offset) override;
489  size_t read(void* buf, size_t size) override;
490  size_t write(const void* buf, size_t size) override;
491  size_t pread(void* buf, size_t size, int64_t offset) override;
492  size_t pwrite(const void* buf, size_t size, int64_t offset) override;
493  size_t size() const override;
494  void flush() const override;
495 
496  // Access the FILE*
497  FILE* handle() const { return m_file; }
498 
499 protected:
500  FILE* m_file = nullptr;
501  size_t m_size = 0;
502  bool m_auto_close = false;
503  std::mutex m_mutex;
504 };
505 
506 
507 /// IOProxy subclass for writing that wraps a std::vector<char> that will
508 /// grow as we write.
510 public:
511  // Construct, IOVecOutput owns its own vector.
513  : IOProxy("", IOProxy::Write)
514  , m_buf(m_local_buf)
515  {
516  }
517  // Construct to wrap an existing vector.
518  IOVecOutput(std::vector<unsigned char>& buf)
519  : IOProxy("", Write)
520  , m_buf(buf)
521  {
522  }
523  const char* proxytype() const override { return "vecoutput"; }
524  size_t write(const void* buf, size_t size) override;
525  size_t pwrite(const void* buf, size_t size, int64_t offset) override;
526  size_t size() const override { return m_buf.size(); }
527 
528  // Access the buffer
529  std::vector<unsigned char>& buffer() const { return m_buf; }
530 
531 protected:
532  std::vector<unsigned char>& m_buf; // reference to buffer
533  std::vector<unsigned char> m_local_buf; // our own buffer
534  std::mutex m_mutex; // protect the buffer
535 };
536 
537 
538 
539 /// IOProxy subclass for reading that wraps an cspan<char>.
541 public:
542  IOMemReader(const void* buf, size_t size)
543  : IOProxy("", Read)
544  , m_buf((const unsigned char*)buf, size)
545  {
546  }
548  : IOProxy("", Read)
549  , m_buf(buf.data(), buf.size())
550  {
551  }
552  const char* proxytype() const override { return "memreader"; }
553  bool seek(int64_t offset) override
554  {
555  m_pos = offset;
556  return true;
557  }
558  size_t read(void* buf, size_t size) override;
559  size_t pread(void* buf, size_t size, int64_t offset) override;
560  size_t size() const override { return m_buf.size(); }
561 
562  // Access the buffer (caveat emptor)
563  cspan<unsigned char> buffer() const noexcept { return m_buf; }
564 
565 protected:
567 };
568 
569 }; // namespace Filesystem
570 
GLuint GLuint stream
Definition: glcorearb.h:1832
OIIO_UTIL_API bool is_directory(string_view path) noexcept
OIIO_UTIL_API std::string filename_to_regex(string_view pattern, bool simple_glob=true)
IOMemReader(const void *buf, size_t size)
Definition: filesystem.h:542
IOProxy(const std::wstring &filename, Mode mode)
Definition: filesystem.h:409
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glcorearb.h:2540
GLbitfield flags
Definition: glcorearb.h:1596
size_t size() const override
Definition: filesystem.h:526
const char * proxytype() const override
Definition: filesystem.h:486
OIIO_NAMESPACE_BEGIN typedef std::ifstream ifstream
Definition: filesystem.h:57
OIIO_UTIL_API std::time_t last_write_time(string_view path) noexcept
#define SEEK_CUR
Definition: zconf.h:184
OIIO_UTIL_API bool parse_pattern(const char *pattern, int framepadding_override, std::string &normalized_pattern, std::string &framespec)
OIIO_UTIL_API std::string parent_path(string_view filepath) noexcept
GT_API const UT_StringHolder time
OIIO_UTIL_API bool copy(string_view from, string_view to, std::string &err)
std::ofstream ofstream
Definition: filesystem.h:58
const GLuint GLenum const void * binary
Definition: glcorearb.h:1924
GLsizei const GLchar *const * path
Definition: glcorearb.h:3341
IOProxy(string_view filename, Mode mode)
Definition: filesystem.h:407
Definition: span.h:74
OIIO_UTIL_API unsigned long long remove_all(string_view path, std::string &err)
#define SEEK_END
Definition: zconf.h:185
virtual void flush() const
Definition: filesystem.h:443
OIIO_UTIL_API bool enumerate_file_sequence(const std::string &pattern, const std::vector< int > &numbers, std::vector< std::string > &filenames)
bool seek(int64_t offset) override
Definition: filesystem.h:553
void close() override
OIIO_UTIL_API void convert_native_arguments(int argc, const char *argv[])
Ensure command line arguments are UTF-8 everywhere.
String-related utilities, all in namespace Strutil.
size_t size() const override
Definition: filesystem.h:560
GLuint buffer
Definition: glcorearb.h:660
#define OIIO_UTIL_API
Definition: export.h:71
bool write_binary_file(string_view filename, cspan< T > data)
Definition: filesystem.h:273
OIIO_UTIL_API std::string searchpath_find(const std::string &filename, const std::vector< std::string > &dirs, bool testcwd=true, bool recursive=false)
OIIO_UTIL_API bool get_directory_entries(const std::string &dirname, std::vector< std::string > &filenames, bool recursive=false, const std::string &filter_regex=std::string())
constexpr auto in(type t, int set) -> bool
Definition: core.h:611
OIIO_UTIL_API std::vector< std::string > searchpath_split(string_view searchpath, bool validonly=false)
< returns > If no error
Definition: snippets.dox:2
OIIO_UTIL_API std::string replace_extension(const std::string &filepath, const std::string &new_extension) noexcept
std::string m_filename
Definition: filesystem.h:467
GLdouble n
Definition: glcorearb.h:2008
OIIO_UTIL_API bool read_text_file(string_view filename, std::string &str, size_t size=(1UL<< 24))
size_t read(span< T > buf)
Definition: filesystem.h:447
std::string m_error
Definition: filesystem.h:470
GLintptr offset
Definition: glcorearb.h:665
OIIO_UTIL_API FILE * fopen(string_view path, string_view mode)
Version of fopen that can handle UTF-8 paths even on Windows.
OIIO_UTIL_API bool read_text_from_command(string_view command, std::string &str, size_t size=(1UL<< 24))
OIIO_UTIL_API uint64_t file_size(string_view path) noexcept
virtual bool seek(int64_t offset)
Definition: filesystem.h:419
const char * proxytype() const override
Definition: filesystem.h:552
virtual size_t size() const
Definition: filesystem.h:442
FILE * handle() const
Definition: filesystem.h:497
OIIO_UTIL_API bool scan_for_matching_filenames(const std::string &pattern, const std::vector< string_view > &views, std::vector< int > &frame_numbers, std::vector< string_view > &frame_views, std::vector< std::string > &filenames)
OIIO_UTIL_API bool write_text_file(string_view filename, string_view str)
const char * proxytype() const override
Definition: filesystem.h:523
OIIO_UTIL_API bool create_directory(string_view path, std::string &err)
OIIO_UTIL_API std::string current_path()
OIIO_UTIL_API std::string temp_directory_path()
size_t write(string_view buf)
Definition: filesystem.h:453
constexpr size_type size() const noexcept
Definition: span.h:186
OIIO_UTIL_API bool exists(string_view path) noexcept
IOFile(const std::wstring &filename, Mode mode)
Definition: filesystem.h:480
GLushort pattern
Definition: glad.h:2583
const std::string & filename() const
Definition: filesystem.h:446
virtual ~IOProxy()
Definition: filesystem.h:411
virtual int64_t tell()
Definition: filesystem.h:415
bool seek(int64_t offset, int origin)
Definition: filesystem.h:456
OIIO_UTIL_API std::string filename(string_view filepath) noexcept
GLenum mode
Definition: glcorearb.h:99
constexpr auto size() const noexcept-> size_t
Definition: core.h:443
IOProxy subclass for reading that wraps an cspan<char>.
Definition: filesystem.h:540
GLsizeiptr size
Definition: glcorearb.h:664
#define SEEK_SET
Definition: zconf.h:183
OIIO_UTIL_API int fseek(FILE *file, int64_t offset, int whence)
OIIO_UTIL_API bool path_is_absolute(string_view path, bool dot_is_absolute=false)
Mode mode() const
Definition: filesystem.h:445
OIIO_UTIL_API std::string generic_filepath(string_view filepath) noexcept
Utilities for dealing with fstream on MingW. Basically accepting wchar_t* filenames in the std::ifstr...
std::mutex m_mutex
Definition: filesystem.h:503
OIIO_UTIL_API bool rename(string_view from, string_view to, std::string &err)
virtual bool opened() const
Definition: filesystem.h:414
IOMemReader(cspan< unsigned char > buf)
Definition: filesystem.h:547
std::vector< unsigned char > & m_buf
Definition: filesystem.h:532
OIIO_UTIL_API int64_t ftell(FILE *file)
Version of ftell that works with 64 bit offsets on all systems.
size_t write(span< T > buf)
Definition: filesystem.h:450
constexpr auto data() const noexcept-> const Char *
Definition: core.h:440
OIIO_UTIL_API bool is_executable(string_view path) noexcept
OIIO_UTIL_API std::string unique_path(string_view model="%%%%-%%%%-%%%%-%%%%")
OIIO_UTIL_API void open(OIIO::ifstream &stream, string_view path, std::ios_base::openmode mode=std::ios_base::in)
#define OIIO_NAMESPACE_END
Definition: oiioversion.h:127
OIIO_UTIL_API bool is_regular(string_view path) noexcept
std::string OIIO_UTIL_API utf16_to_utf8(const std::wstring &utf16str) noexcept
virtual void close()
Definition: filesystem.h:413
OIIO_UTIL_API bool enumerate_sequence(string_view desc, std::vector< int > &numbers)
cspan< unsigned char > m_buf
Definition: filesystem.h:566
std::vector< unsigned char > & buffer() const
Definition: filesystem.h:529
constexpr pointer data() const noexcept
Definition: span.h:190
GLbitfield GLuint program
Definition: glcorearb.h:1931
cspan< unsigned char > buffer() const noexcept
Definition: filesystem.h:563
OIIO_UTIL_API std::string extension(string_view filepath, bool include_dot=true) noexcept
Definition: format.h:1821
std::vector< unsigned char > m_local_buf
Definition: filesystem.h:533
#define OIIO_NAMESPACE_BEGIN
Definition: oiioversion.h:126
IOVecOutput(std::vector< unsigned char > &buf)
Definition: filesystem.h:518
OIIO_UTIL_API std::string find_program(string_view program)
OIIO_UTIL_API size_t read_bytes(string_view path, void *buffer, size_t n, size_t pos=0)