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 2008-present Contributors to the OpenImageIO project.
2 // SPDX-License-Identifier: BSD-3-Clause
3 // https://github.com/OpenImageIO/oiio
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.
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 "".
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.
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.
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 #if OIIO_VERSION_GREATER_EQUAL(2, 4, 0)
101 inline void searchpath_split (string_view searchpath,
102  std::vector<std::string> &dirs,
103  bool validonly = false)
104 {
105  dirs = searchpath_split(searchpath, validonly);
106 }
107 #else
108 OIIO_UTIL_API void searchpath_split (const std::string &searchpath,
109  std::vector<std::string> &dirs,
110  bool validonly = false);
111 #endif
112 
113 /// Find the first instance of a filename existing in a vector of
114 /// directories, returning the full path as a string. If the file is
115 /// not found in any of the listed directories, return an empty string.
116 /// If the filename is absolute, the directory list will not be used.
117 /// If testcwd is true, "." will be tested before the searchpath;
118 /// otherwise, "." will only be tested if it's explicitly in dirs. If
119 /// recursive is true, the directories will be searched recursively,
120 /// finding a matching file in any subdirectory of the directories
121 /// listed in dirs; otherwise. All file and directory names are presumed
122 /// to be UTF-8 encoded.
124  const std::vector<std::string> &dirs,
125  bool testcwd = true,
126  bool recursive = false);
127 
128 /// Fill a vector-of-strings with the names of all files contained by
129 /// directory dirname. If recursive is true, it will return all files below
130 /// the directory (even in subdirectories). If filter_regex is supplied and
131 /// non-empty, only filenames matching the regular expression will be
132 /// returned. Return true if ok, false if there was an error (such as
133 /// dirname not being found or not actually being a directory). All file
134 /// and directory names are presumed to be UTF-8 encoded.
135 OIIO_UTIL_API bool get_directory_entries (const std::string &dirname,
136  std::vector<std::string> &filenames,
137  bool recursive = false,
138  const std::string &filter_regex=std::string());
139 
140 /// Return true if the UTF-8 encoded path is an "absolute" (not relative)
141 /// path. If 'dot_is_absolute' is true, consider "./foo" absolute.
143  bool dot_is_absolute=false);
144 
145 /// Return true if the UTF-8 encoded path exists.
146 ///
147 OIIO_UTIL_API bool exists (string_view path) noexcept;
148 
149 
150 /// Return true if the UTF-8 encoded path exists and is a directory.
151 ///
152 OIIO_UTIL_API bool is_directory (string_view path) noexcept;
153 
154 /// Return true if the UTF-8 encoded path exists and is a regular file.
155 ///
156 OIIO_UTIL_API bool is_regular (string_view path) noexcept;
157 
158 /// Create the directory, whose name is UTF-8 encoded. Return true for
159 /// success, false for failure and place an error message in err.
161 inline bool create_directory (string_view path) {
162  std::string err;
163  return create_directory (path, err);
164 }
165 
166 /// Copy a file, directory, or link. It is an error if 'to' already exists.
167 /// The file names are all UTF-8 encoded. Return true upon success, false upon
168 /// failure and place an error message in err.
170 inline bool copy (string_view from, string_view to) {
171  std::string err;
172  return copy (from, to, err);
173 }
174 
175 /// Rename (or move) a file, directory, or link. The file names are all UTF-8
176 /// encoded. Return true upon success, false upon failure and place an error
177 /// message in err.
179 inline bool rename (string_view from, string_view to) {
180  std::string err;
181  return rename (from, to, err);
182 }
183 
184 /// Remove the file or directory. The file names are all UTF-8 encoded. Return
185 /// true for success, false for failure and place an error message in err.
186 OIIO_UTIL_API bool remove (string_view path, std::string &err);
187 inline bool remove (string_view path) {
188  std::string err;
189  return remove (path, err);
190 }
191 
192 /// Remove the file or directory, including any children (recursively). The
193 /// file names are all UTF-8 encoded. Return the number of files removed.
194 /// Place an error message (if applicable in err.
195 OIIO_UTIL_API unsigned long long remove_all (string_view path, std::string &err);
196 inline unsigned long long remove_all (string_view path) {
197  std::string err;
198  return remove_all (path, err);
199 }
200 
201 /// Return a directory path (UTF-8 encoded) where temporary files can be made.
202 ///
204 
205 /// Return a unique filename suitable for making a temporary file or
206 /// directory. The file names are all UTF-8 encoded.
207 OIIO_UTIL_API std::string unique_path (string_view model="%%%%-%%%%-%%%%-%%%%");
208 
209 /// Version of fopen that can handle UTF-8 paths even on Windows.
211 
212 /// Version of fseek that works with 64 bit offsets on all systems.
213 OIIO_UTIL_API int fseek (FILE *file, int64_t offset, int whence);
214 
215 /// Version of ftell that works with 64 bit offsets on all systems.
216 OIIO_UTIL_API int64_t ftell (FILE *file);
217 
218 /// Return the current (".") directory path.
219 ///
221 
222 /// Version of std::ifstream.open that can handle UTF-8 paths
223 ///
225  std::ios_base::openmode mode = std::ios_base::in);
226 
227 /// Version of std::ofstream.open that can handle UTF-8 paths
228 ///
230  std::ios_base::openmode mode = std::ios_base::out);
231 
232 /// Version of C open() that can handle UTF-8 paths, returning an integer
233 /// file descriptor. Note that the flags are passed to underlying calls to
234 /// open()/_open() and therefore may be OS specific -- use with caution! If
235 /// you want more OS-agnostic file opening, prefer the FILE or stream
236 /// methods of IO. (N.B.: use of this function requires the caller to
237 /// `#include <fcntl.h>` in order to get the definitions of the flags.)
238 OIIO_UTIL_API int open (string_view path, int flags);
239 
240 /// Read the entire contents of the named text file (as a UTF-8 encoded
241 /// filename) and place it in str, returning true on success, false on
242 /// failure.
244 
245 /// Write the entire contents of the string `str` to the named file (UTF-8
246 /// encoded), overwriting any prior contents of the file (if it existed),
247 /// returning true on success, false on failure.
249 
250 /// Write the entire contents of the span `data` to the file (UTF-8 encoded)
251 /// as a binary blob, overwriting any prior contents of the file (if it
252 /// existed), returning true on success, false on failure.
253 template<typename T>
255 {
256  OIIO::ofstream out;
257  Filesystem::open(out, filename, std::ios::out | std::ios::binary);
258  out.write((const char*)data.data(), data.size() * sizeof(T));
259  return out.good();
260 }
261 
262 template<typename T>
263 bool write_binary_file (string_view filename, const std::vector<T>& data)
264 {
265  return write_binary_file(filename, cspan<T>(data));
266 }
267 
268 /// Read a maximum of n bytes from the named file, starting at position pos
269 /// (which defaults to the start of the file), storing results in
270 /// buffer[0..n-1]. Return the number of bytes read, which will be n for
271 /// full success, less than n if the file was fewer than n+pos bytes long,
272 /// or 0 if the file did not exist or could not be read.
273 OIIO_UTIL_API size_t read_bytes (string_view path, void *buffer, size_t n,
274  size_t pos=0);
275 
276 /// Get last modified time of the file named by `path` (UTF-8 encoded).
277 ///
278 OIIO_UTIL_API std::time_t last_write_time (string_view path) noexcept;
279 
280 /// Set last modified time on the file named by `path` (UTF-8 encoded).
281 ///
282 OIIO_UTIL_API void last_write_time (string_view path, std::time_t time) noexcept;
283 
284 /// Return the size of the file (in bytes), or uint64_t(-1) if there is any
285 /// error. The file name is UTF-8 encoded.
286 OIIO_UTIL_API uint64_t file_size (string_view path) noexcept;
287 
288 /// Ensure command line arguments are UTF-8 everywhere.
289 OIIO_UTIL_API void convert_native_arguments (int argc, const char *argv[]);
290 
291 /// Turn a sequence description string into a vector of integers.
292 /// The sequence description can be any of the following
293 /// * A value (e.g., "3")
294 /// * A value range ("1-10", "10-1", "1-10x3", "1-10y3"):
295 /// START-FINISH A range, inclusive of start & finish
296 /// START-FINISHxSTEP A range with step size
297 /// START-FINISHySTEP The complement of a stepped range, that is,
298 /// all numbers within the range that would
299 /// NOT have been selected by 'x'.
300 /// Note that START may be > FINISH, or STEP may be negative.
301 /// * Multiple values or ranges, separated by a comma (e.g., "3,4,10-20x2")
302 /// Return true upon success, false if the description was too malformed
303 /// to generate a sequence.
305  std::vector<int> &numbers);
306 
307 /// Given a pattern (such as "foo.#.tif" or "bar.1-10#.exr"), return a
308 /// normalized pattern in printf format (such as "foo.%04d.tif") and a
309 /// framespec (such as "1-10").
310 ///
311 /// If framepadding_override is > 0, it overrides any specific padding amount
312 /// in the original pattern.
313 ///
314 /// Return true upon success, false if the description was too malformed
315 /// to generate a sequence.
316 OIIO_UTIL_API bool parse_pattern (const char *pattern,
317  int framepadding_override,
318  std::string &normalized_pattern,
319  std::string &framespec);
320 
321 
322 /// Given a normalized pattern (such as "foo.%04d.tif") and a list of frame
323 /// numbers, generate a list of filenames. All the filename strings will be
324 /// presumed to be UTF-8 encoded.
325 ///
326 /// Return true upon success, false if the description was too malformed
327 /// to generate a sequence.
329  const std::vector<int> &numbers,
330  std::vector<std::string> &filenames);
331 
332 /// Given a normalized pattern (such as "foo_%V.%04d.tif") and a list of frame
333 /// numbers, generate a list of filenames. "views" is list of per-frame views,
334 /// or empty. In each frame filename, "%V" is replaced with the view, and "%v"
335 /// is replaced with the first character of the view. All the filename strings
336 /// will be presumed to be UTF-8 encoded.
337 ///
338 /// Return true upon success, false if the description was too malformed to
339 /// generate a sequence.
341  const std::vector<int> &numbers,
342  const std::vector<string_view> &views,
343  std::vector<std::string> &filenames);
344 
345 /// Given a normalized pattern (such as "/path/to/foo.%04d.tif") scan the
346 /// containing directory (/path/to) for matching frame numbers, views and
347 /// files. "%V" in the pattern matches views, while "%v" matches the first
348 /// character of each entry in views. All the filename strings will be
349 /// presumed to be UTF-8 encoded.
350 ///
351 /// Return true upon success, false if the directory doesn't exist or the
352 /// pattern can't be parsed.
354  const std::vector<string_view> &views,
355  std::vector<int> &frame_numbers,
356  std::vector<string_view> &frame_views,
357  std::vector<std::string> &filenames);
358 
359 /// Given a normalized pattern (such as "/path/to/foo.%04d.tif") scan the
360 /// containing directory (/path/to) for matching frame numbers and files. All
361 /// the filename strings will be presumed to be UTF-8 encoded.
362 ///
363 /// Return true upon success, false if the directory doesn't exist or the
364 /// pattern can't be parsed.
366  std::vector<int> &numbers,
367  std::vector<std::string> &filenames);
368 
369 /// Convert a UTF-8 encoded filename into a regex-safe pattern -- any special
370 /// regex characters `.`, `(`, `)`, `[`, `]`, `{`, `}` are backslashed. If
371 /// `simple_glob` is also true, then replace `?` with `.?` and `*` with `.*`.
372 /// This doesn't support full Unix command line glob syntax (no char sets
373 /// `[abc]` or string sets `{ab,cd,ef}`), but it does handle simple globbing
374 /// of `?` to mean any single character and `*` to mean any sequence of 0 or
375 /// more characters.
377  bool simple_glob = true);
378 
379 
380 
381 /// Proxy class for I/O. This provides a simplified interface for file I/O
382 /// that can have custom overrides. All char-based filenames are assumed to be
383 /// UTF-8 encoded.
385 public:
386  enum Mode { Closed = 0, Read = 'r', Write = 'w' };
387  IOProxy () {}
389  : m_filename(filename), m_mode(mode) {}
390  IOProxy(const std::wstring& filename, Mode mode)
391  : IOProxy(Strutil::utf16_to_utf8(filename), mode) {}
392  virtual ~IOProxy () { }
393  virtual const char* proxytype () const = 0;
394  virtual void close () { }
395  virtual bool opened () const { return mode() != Closed; }
396  virtual int64_t tell () { return m_pos; }
397  virtual bool seek (int64_t offset) { m_pos = offset; return true; }
398  virtual size_t read (void *buf, size_t size);
399  virtual size_t write (const void *buf, size_t size);
400  // pread(), pwrite() are stateless, do not alter the current file
401  // position, and are thread-safe (against each other).
402  virtual size_t pread (void *buf, size_t size, int64_t offset);
403  virtual size_t pwrite (const void *buf, size_t size, int64_t offset);
404  virtual size_t size () const { return 0; }
405  virtual void flush () const { }
406 
407  Mode mode () const { return m_mode; }
408  const std::string& filename () const { return m_filename; }
409  template<class T> size_t read (span<T> buf) {
410  return read (buf.data(), buf.size()*sizeof(T));
411  }
412  template<class T> size_t write (span<T> buf) {
413  return write (buf.data(), buf.size()*sizeof(T));
414  }
415  size_t write (string_view buf) {
416  return write (buf.data(), buf.size());
417  }
418  bool seek (int64_t offset, int origin) {
419  return seek ((origin == SEEK_SET ? offset : 0) +
420  (origin == SEEK_CUR ? offset+tell() : 0) +
421  (origin == SEEK_END ? offset+int64_t(size()) : 0));
422  }
423 
424  #define OIIO_IOPROXY_HAS_ERROR 1
425  std::string error() const;
426  void error(string_view e);
427 
428 protected:
430  int64_t m_pos = 0;
431  Mode m_mode = Closed;
433 };
434 
435 
436 /// IOProxy subclass for reading or writing (but not both) that wraps C
437 /// stdio 'FILE'.
438 class OIIO_UTIL_API IOFile : public IOProxy {
439 public:
440  // Construct from a filename, open, own the FILE*.
441  IOFile(string_view filename, Mode mode);
442  IOFile(const std::wstring& filename, Mode mode)
443  : IOFile(Strutil::utf16_to_utf8(filename), mode) {}
444  // Construct from an already-open FILE* that is owned by the caller.
445  // Caller is responsible for closing the FILE* after the proxy is gone.
446  IOFile(FILE* file, Mode mode);
447  virtual ~IOFile();
448  virtual const char* proxytype() const { return "file"; }
449  virtual void close();
450  virtual bool seek(int64_t offset);
451  virtual size_t read(void* buf, size_t size);
452  virtual size_t write(const void* buf, size_t size);
453  virtual size_t pread(void* buf, size_t size, int64_t offset);
454  virtual size_t pwrite(const void* buf, size_t size, int64_t offset);
455  virtual size_t size() const;
456  virtual void flush() const;
457 
458  // Access the FILE*
459  FILE* handle() const { return m_file; }
460 
461 protected:
462  FILE* m_file = nullptr;
463  size_t m_size = 0;
464  bool m_auto_close = false;
465  std::mutex m_mutex;
466 };
467 
468 
469 /// IOProxy subclass for writing that wraps a std::vector<char> that will
470 /// grow as we write.
472 public:
473  // Construct, IOVecOutput owns its own vector.
475  : IOProxy("", IOProxy::Write)
476  , m_buf(m_local_buf)
477  {
478  }
479  // Construct to wrap an existing vector.
480  IOVecOutput(std::vector<unsigned char>& buf)
481  : IOProxy("", Write)
482  , m_buf(buf)
483  {
484  }
485  virtual const char* proxytype() const { return "vecoutput"; }
486  virtual size_t write(const void* buf, size_t size);
487  virtual size_t pwrite(const void* buf, size_t size, int64_t offset);
488  virtual size_t size() const { return m_buf.size(); }
489 
490  // Access the buffer
491  std::vector<unsigned char>& buffer() const { return m_buf; }
492 
493 protected:
494  std::vector<unsigned char>& m_buf; // reference to buffer
495  std::vector<unsigned char> m_local_buf; // our own buffer
496  std::mutex m_mutex; // protect the buffer
497 };
498 
499 
500 
501 /// IOProxy subclass for reading that wraps an cspan<char>.
503 public:
504  IOMemReader(void* buf, size_t size)
505  : IOProxy("", Read)
506  , m_buf((const unsigned char*)buf, size)
507  {
508  }
510  : IOProxy("", Read)
511  , m_buf(buf.data(), buf.size())
512  {
513  }
514  virtual const char* proxytype() const { return "memreader"; }
515  virtual bool seek(int64_t offset)
516  {
517  m_pos = offset;
518  return true;
519  }
520  virtual size_t read(void* buf, size_t size);
521  virtual size_t pread(void* buf, size_t size, int64_t offset);
522  virtual size_t size() const { return m_buf.size(); }
523 
524  // Access the buffer (caveat emptor)
525  cspan<unsigned char> buffer() const noexcept { return m_buf; }
526 
527 protected:
529 };
530 
531 }; // namespace Filesystem
532 
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)
IOProxy(const std::wstring &filename, Mode mode)
Definition: filesystem.h:390
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glcorearb.h:2540
GLbitfield flags
Definition: glcorearb.h:1596
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:471
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)
GLsizei const GLchar *const * string
Definition: glcorearb.h:814
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:388
Definition: span.h:73
OIIO_UTIL_API unsigned long long remove_all(string_view path, std::string &err)
#define SEEK_END
Definition: zconf.h:472
virtual void flush() const
Definition: filesystem.h:405
virtual const char * proxytype() const
Definition: filesystem.h:514
OIIO_UTIL_API bool enumerate_file_sequence(const std::string &pattern, const std::vector< int > &numbers, std::vector< std::string > &filenames)
void close() override
OIIO_UTIL_API void convert_native_arguments(int argc, const char *argv[])
Ensure command line arguments are UTF-8 everywhere.
void read(T &in, bool &v)
Definition: ImfXdr.h:502
String-related utilities, all in namespace Strutil.
#define OIIO_UTIL_API
Definition: export.h:71
bool write_binary_file(string_view filename, cspan< T > data)
Definition: filesystem.h:254
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())
virtual const char * proxytype() const
Definition: filesystem.h:448
constexpr const_pointer data() const noexcept
Definition: string_view.h:170
OIIO_UTIL_API std::vector< std::string > searchpath_split(string_view searchpath, bool validonly=false)
IOMemReader(void *buf, size_t size)
Definition: filesystem.h:504
< returns > If no error
Definition: snippets.dox:2
constexpr size_type size() const noexcept
Definition: string_view.h:150
OIIO_UTIL_API std::string replace_extension(const std::string &filepath, const std::string &new_extension) noexcept
std::string m_filename
Definition: filesystem.h:429
GLdouble n
Definition: glcorearb.h:2008
size_t read(span< T > buf)
Definition: filesystem.h:409
std::string m_error
Definition: filesystem.h:432
GLintptr offset
Definition: glcorearb.h:665
Definition: core.h:760
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 uint64_t file_size(string_view path) noexcept
virtual bool seek(int64_t offset)
Definition: filesystem.h:397
virtual size_t size() const
Definition: filesystem.h:404
FILE * handle() const
Definition: filesystem.h:459
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)
OIIO_UTIL_API bool create_directory(string_view path, std::string &err)
virtual const char * proxytype() const
Definition: filesystem.h:485
OIIO_UTIL_API std::string current_path()
OIIO_UTIL_API std::string temp_directory_path()
size_t write(string_view buf)
Definition: filesystem.h:415
constexpr size_type size() const noexcept
Definition: span.h:185
OIIO_UTIL_API bool exists(string_view path) noexcept
IOFile(const std::wstring &filename, Mode mode)
Definition: filesystem.h:442
GLushort pattern
Definition: glad.h:2583
const std::string & filename() const
Definition: filesystem.h:408
virtual ~IOProxy()
Definition: filesystem.h:392
virtual int64_t tell()
Definition: filesystem.h:396
bool seek(int64_t offset, int origin)
Definition: filesystem.h:418
OIIO_UTIL_API std::string filename(string_view filepath) noexcept
virtual size_t size() const
Definition: filesystem.h:488
GLenum mode
Definition: glcorearb.h:99
IOProxy subclass for reading that wraps an cspan<char>.
Definition: filesystem.h:502
GLsizeiptr size
Definition: glcorearb.h:664
#define SEEK_SET
Definition: zconf.h:470
OIIO_UTIL_API int fseek(FILE *file, int64_t offset, int whence)
Version of fseek that works with 64 bit offsets on all systems.
virtual size_t size() const
Definition: filesystem.h:522
OIIO_UTIL_API bool path_is_absolute(string_view path, bool dot_is_absolute=false)
Mode mode() const
Definition: filesystem.h:407
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:465
OIIO_UTIL_API bool rename(string_view from, string_view to, std::string &err)
virtual bool opened() const
Definition: filesystem.h:395
IOMemReader(cspan< unsigned char > buf)
Definition: filesystem.h:509
std::vector< unsigned char > & m_buf
Definition: filesystem.h:494
OIIO_UTIL_API int64_t ftell(FILE *file)
Version of ftell that works with 64 bit offsets on all systems.
virtual bool seek(int64_t offset)
Definition: filesystem.h:515
size_t write(span< T > buf)
Definition: filesystem.h:412
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 const
Definition: zconf.h:214
#define OIIO_NAMESPACE_END
Definition: oiioversion.h:94
OIIO_UTIL_API bool is_regular(string_view path) noexcept
OIIO_UTIL_API bool read_text_file(string_view filename, std::string &str)
void write(T &out, bool v)
Definition: ImfXdr.h:287
std::string OIIO_UTIL_API utf16_to_utf8(const std::wstring &utf16str) noexcept
virtual void close()
Definition: filesystem.h:394
OIIO_UTIL_API bool enumerate_sequence(string_view desc, std::vector< int > &numbers)
cspan< unsigned char > m_buf
Definition: filesystem.h:528
std::vector< unsigned char > & buffer() const
Definition: filesystem.h:491
constexpr pointer data() const noexcept
Definition: span.h:189
cspan< unsigned char > buffer() const noexcept
Definition: filesystem.h:525
OIIO_UTIL_API std::string extension(string_view filepath, bool include_dot=true) noexcept
Definition: format.h:895
std::vector< unsigned char > m_local_buf
Definition: filesystem.h:495
#define OIIO_NAMESPACE_BEGIN
Definition: oiioversion.h:93
IOVecOutput(std::vector< unsigned char > &buf)
Definition: filesystem.h:480
OIIO_UTIL_API size_t read_bytes(string_view path, void *buffer, size_t n, size_t pos=0)