sdl3_sys/generated/
filesystem.rs

1//! SDL offers an API for examining and manipulating the system's filesystem.
2//! This covers most things one would need to do with directories, except for
3//! actual file I/O (which is covered by [CategoryIOStream](CategoryIOStream)
4//! and [CategoryAsyncIO](CategoryAsyncIO) instead).
5//!
6//! There are functions to answer necessary path questions:
7//!
8//! - Where is my app's data? [`SDL_GetBasePath()`].
9//! - Where can I safely write files? [`SDL_GetPrefPath()`].
10//! - Where are paths like Downloads, Desktop, Music? [`SDL_GetUserFolder()`].
11//! - What is this thing at this location? [`SDL_GetPathInfo()`].
12//! - What items live in this folder? [`SDL_EnumerateDirectory()`].
13//! - What items live in this folder by wildcard? [`SDL_GlobDirectory()`].
14//! - What is my current working directory? [`SDL_GetCurrentDirectory()`].
15//!
16//! SDL also offers functions to manipulate the directory tree: renaming,
17//! removing, copying files.
18
19use super::stdinc::*;
20
21use super::error::*;
22
23unsafe extern "C" {
24    /// Get the directory where the application was run from.
25    ///
26    /// SDL caches the result of this call internally, but the first call to this
27    /// function is not necessarily fast, so plan accordingly.
28    ///
29    /// **macOS and iOS Specific Functionality**: If the application is in a ".app"
30    /// bundle, this function returns the Resource directory (e.g.
31    /// MyApp.app/Contents/Resources/). This behaviour can be overridden by adding
32    /// a property to the Info.plist file. Adding a string key with the name
33    /// SDL_FILESYSTEM_BASE_DIR_TYPE with a supported value will change the
34    /// behaviour.
35    ///
36    /// Supported values for the SDL_FILESYSTEM_BASE_DIR_TYPE property (Given an
37    /// application in /Applications/SDLApp/MyApp.app):
38    ///
39    /// - `resource`: bundle resource directory (the default). For example:
40    ///   `/Applications/SDLApp/MyApp.app/Contents/Resources`
41    /// - `bundle`: the Bundle directory. For example:
42    ///   `/Applications/SDLApp/MyApp.app/`
43    /// - `parent`: the containing directory of the bundle. For example:
44    ///   `/Applications/SDLApp/`
45    ///
46    /// **Android Specific Functionality**: This function returns "./", which
47    /// allows filesystem operations to use internal storage and the asset system.
48    ///
49    /// **Nintendo 3DS Specific Functionality**: This function returns "romfs"
50    /// directory of the application as it is uncommon to store resources outside
51    /// the executable. As such it is not a writable directory.
52    ///
53    /// The returned path is guaranteed to end with a path separator ('\\' on
54    /// Windows, '/' on most other platforms).
55    ///
56    /// ## Return value
57    /// Returns an absolute path in UTF-8 encoding to the application data
58    ///   directory. NULL will be returned on error or when the platform
59    ///   doesn't implement this functionality, call [`SDL_GetError()`] for more
60    ///   information.
61    ///
62    /// ## Thread safety
63    /// It is safe to call this function from any thread.
64    ///
65    /// ## Availability
66    /// This function is available since SDL 3.2.0.
67    ///
68    /// ## See also
69    /// - [`SDL_GetPrefPath`]
70    pub fn SDL_GetBasePath() -> *const ::core::ffi::c_char;
71}
72
73unsafe extern "C" {
74    /// Get the user-and-app-specific path where files can be written.
75    ///
76    /// Get the "pref dir". This is meant to be where users can write personal
77    /// files (preferences and save games, etc) that are specific to your
78    /// application. This directory is unique per user, per application.
79    ///
80    /// This function will decide the appropriate location in the native
81    /// filesystem, create the directory if necessary, and return a string of the
82    /// absolute path to the directory in UTF-8 encoding.
83    ///
84    /// On Windows, the string might look like:
85    ///
86    /// `C:\\Users\\bob\\AppData\\Roaming\\My Company\\My Program Name\\`
87    ///
88    /// On Linux, the string might look like:
89    ///
90    /// `/home/bob/.local/share/My Program Name/`
91    ///
92    /// On macOS, the string might look like:
93    ///
94    /// `/Users/bob/Library/Application Support/My Program Name/`
95    ///
96    /// You should assume the path returned by this function is the only safe place
97    /// to write files (and that [`SDL_GetBasePath()`], while it might be writable, or
98    /// even the parent of the returned path, isn't where you should be writing
99    /// things).
100    ///
101    /// Both the org and app strings may become part of a directory name, so please
102    /// follow these rules:
103    ///
104    /// - Try to use the same org string (_including case-sensitivity_) for all
105    ///   your applications that use this function.
106    /// - Always use a unique app string for each one, and make sure it never
107    ///   changes for an app once you've decided on it.
108    /// - Unicode characters are legal, as long as they are UTF-8 encoded, but...
109    /// - ...only use letters, numbers, and spaces. Avoid punctuation like "Game
110    ///   Name 2: Bad Guy's Revenge!" ... "Game Name 2" is sufficient.
111    ///
112    /// Due to historical mistakes, `org` is allowed to be NULL or "". In such
113    /// cases, SDL will omit the org subdirectory, including on platforms where it
114    /// shouldn't, and including on platforms where this would make your app fail
115    /// certification for an app store. New apps should definitely specify a real
116    /// string for `org`.
117    ///
118    /// The returned path is guaranteed to end with a path separator ('\\' on
119    /// Windows, '/' on most other platforms).
120    ///
121    /// ## Parameters
122    /// - `org`: the name of your organization.
123    /// - `app`: the name of your application.
124    ///
125    /// ## Return value
126    /// Returns a UTF-8 string of the user directory in platform-dependent
127    ///   notation. NULL if there's a problem (creating directory failed,
128    ///   etc.). This should be freed with [`SDL_free()`] when it is no longer
129    ///   needed.
130    ///
131    /// ## Thread safety
132    /// It is safe to call this function from any thread.
133    ///
134    /// ## Availability
135    /// This function is available since SDL 3.2.0.
136    ///
137    /// ## See also
138    /// - [`SDL_GetBasePath`]
139    pub fn SDL_GetPrefPath(
140        org: *const ::core::ffi::c_char,
141        app: *const ::core::ffi::c_char,
142    ) -> *mut ::core::ffi::c_char;
143}
144
145/// The type of the OS-provided default folder for a specific purpose.
146///
147/// Note that the Trash folder isn't included here, because trashing files
148/// usually involves extra OS-specific functionality to remember the file's
149/// original location.
150///
151/// The folders supported per platform are:
152///
153/// |             | Windows | macOS/iOS | tvOS | Unix (XDG) | Haiku | Emscripten |
154/// | ----------- | ------- | --------- | ---- | ---------- | ----- | ---------- |
155/// | HOME        | X       | X         |      | X          | X     | X          |
156/// | DESKTOP     | X       | X         |      | X          | X     |            |
157/// | DOCUMENTS   | X       | X         |      | X          |       |            |
158/// | DOWNLOADS   | Vista+  | X         |      | X          |       |            |
159/// | MUSIC       | X       | X         |      | X          |       |            |
160/// | PICTURES    | X       | X         |      | X          |       |            |
161/// | PUBLICSHARE |         | X         |      | X          |       |            |
162/// | SAVEDGAMES  | Vista+  |           |      |            |       |            |
163/// | SCREENSHOTS | Vista+  |           |      |            |       |            |
164/// | TEMPLATES   | X       | X         |      | X          |       |            |
165/// | VIDEOS      | X       | X*        |      | X          |       |            |
166///
167/// Note that on macOS/iOS, the Videos folder is called "Movies".
168///
169/// ## Availability
170/// This enum is available since SDL 3.2.0.
171///
172/// ## See also
173/// - [`SDL_GetUserFolder`]
174///
175/// ## Known values (`sdl3-sys`)
176/// | Associated constant | Global constant | Description |
177/// | ------------------- | --------------- | ----------- |
178/// | [`HOME`](SDL_Folder::HOME) | [`SDL_FOLDER_HOME`] | The folder which contains all of the current user's data, preferences, and documents. It usually contains most of the other folders. If a requested folder does not exist, the home folder can be considered a safe fallback to store a user's documents. |
179/// | [`DESKTOP`](SDL_Folder::DESKTOP) | [`SDL_FOLDER_DESKTOP`] | The folder of files that are displayed on the desktop. Note that the existence of a desktop folder does not guarantee that the system does show icons on its desktop; certain GNU/Linux distros with a graphical environment may not have desktop icons. |
180/// | [`DOCUMENTS`](SDL_Folder::DOCUMENTS) | [`SDL_FOLDER_DOCUMENTS`] | User document files, possibly application-specific. This is a good place to save a user's projects. |
181/// | [`DOWNLOADS`](SDL_Folder::DOWNLOADS) | [`SDL_FOLDER_DOWNLOADS`] | Standard folder for user files downloaded from the internet. |
182/// | [`MUSIC`](SDL_Folder::MUSIC) | [`SDL_FOLDER_MUSIC`] | Music files that can be played using a standard music player (mp3, ogg...). |
183/// | [`PICTURES`](SDL_Folder::PICTURES) | [`SDL_FOLDER_PICTURES`] | Image files that can be displayed using a standard viewer (png, jpg...). |
184/// | [`PUBLICSHARE`](SDL_Folder::PUBLICSHARE) | [`SDL_FOLDER_PUBLICSHARE`] | Files that are meant to be shared with other users on the same computer. |
185/// | [`SAVEDGAMES`](SDL_Folder::SAVEDGAMES) | [`SDL_FOLDER_SAVEDGAMES`] | Save files for games. |
186/// | [`SCREENSHOTS`](SDL_Folder::SCREENSHOTS) | [`SDL_FOLDER_SCREENSHOTS`] | Application screenshots. |
187/// | [`TEMPLATES`](SDL_Folder::TEMPLATES) | [`SDL_FOLDER_TEMPLATES`] | Template files to be used when the user requests the desktop environment to create a new file in a certain folder, such as "New Text File.txt".  Any file in the Templates folder can be used as a starting point for a new file. |
188/// | [`VIDEOS`](SDL_Folder::VIDEOS) | [`SDL_FOLDER_VIDEOS`] | Video files that can be played using a standard video player (mp4, webm...). |
189/// | [`COUNT`](SDL_Folder::COUNT) | [`SDL_FOLDER_COUNT`] | Total number of types in this enum, not a folder type by itself. |
190#[repr(transparent)]
191#[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
192pub struct SDL_Folder(pub ::core::ffi::c_int);
193
194impl ::core::cmp::PartialEq<::core::ffi::c_int> for SDL_Folder {
195    #[inline(always)]
196    fn eq(&self, other: &::core::ffi::c_int) -> bool {
197        &self.0 == other
198    }
199}
200
201impl ::core::cmp::PartialEq<SDL_Folder> for ::core::ffi::c_int {
202    #[inline(always)]
203    fn eq(&self, other: &SDL_Folder) -> bool {
204        self == &other.0
205    }
206}
207
208impl From<SDL_Folder> for ::core::ffi::c_int {
209    #[inline(always)]
210    fn from(value: SDL_Folder) -> Self {
211        value.0
212    }
213}
214
215#[cfg(feature = "debug-impls")]
216impl ::core::fmt::Debug for SDL_Folder {
217    fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
218        #[allow(unreachable_patterns)]
219        f.write_str(match *self {
220            Self::HOME => "SDL_FOLDER_HOME",
221            Self::DESKTOP => "SDL_FOLDER_DESKTOP",
222            Self::DOCUMENTS => "SDL_FOLDER_DOCUMENTS",
223            Self::DOWNLOADS => "SDL_FOLDER_DOWNLOADS",
224            Self::MUSIC => "SDL_FOLDER_MUSIC",
225            Self::PICTURES => "SDL_FOLDER_PICTURES",
226            Self::PUBLICSHARE => "SDL_FOLDER_PUBLICSHARE",
227            Self::SAVEDGAMES => "SDL_FOLDER_SAVEDGAMES",
228            Self::SCREENSHOTS => "SDL_FOLDER_SCREENSHOTS",
229            Self::TEMPLATES => "SDL_FOLDER_TEMPLATES",
230            Self::VIDEOS => "SDL_FOLDER_VIDEOS",
231            Self::COUNT => "SDL_FOLDER_COUNT",
232
233            _ => return write!(f, "SDL_Folder({})", self.0),
234        })
235    }
236}
237
238impl SDL_Folder {
239    /// The folder which contains all of the current user's data, preferences, and documents. It usually contains most of the other folders. If a requested folder does not exist, the home folder can be considered a safe fallback to store a user's documents.
240    pub const HOME: Self = Self((0 as ::core::ffi::c_int));
241    /// The folder of files that are displayed on the desktop. Note that the existence of a desktop folder does not guarantee that the system does show icons on its desktop; certain GNU/Linux distros with a graphical environment may not have desktop icons.
242    pub const DESKTOP: Self = Self((1 as ::core::ffi::c_int));
243    /// User document files, possibly application-specific. This is a good place to save a user's projects.
244    pub const DOCUMENTS: Self = Self((2 as ::core::ffi::c_int));
245    /// Standard folder for user files downloaded from the internet.
246    pub const DOWNLOADS: Self = Self((3 as ::core::ffi::c_int));
247    /// Music files that can be played using a standard music player (mp3, ogg...).
248    pub const MUSIC: Self = Self((4 as ::core::ffi::c_int));
249    /// Image files that can be displayed using a standard viewer (png, jpg...).
250    pub const PICTURES: Self = Self((5 as ::core::ffi::c_int));
251    /// Files that are meant to be shared with other users on the same computer.
252    pub const PUBLICSHARE: Self = Self((6 as ::core::ffi::c_int));
253    /// Save files for games.
254    pub const SAVEDGAMES: Self = Self((7 as ::core::ffi::c_int));
255    /// Application screenshots.
256    pub const SCREENSHOTS: Self = Self((8 as ::core::ffi::c_int));
257    /// Template files to be used when the user requests the desktop environment to create a new file in a certain folder, such as "New Text File.txt".  Any file in the Templates folder can be used as a starting point for a new file.
258    pub const TEMPLATES: Self = Self((9 as ::core::ffi::c_int));
259    /// Video files that can be played using a standard video player (mp4, webm...).
260    pub const VIDEOS: Self = Self((10 as ::core::ffi::c_int));
261    /// Total number of types in this enum, not a folder type by itself.
262    pub const COUNT: Self = Self((11 as ::core::ffi::c_int));
263}
264
265/// The folder which contains all of the current user's data, preferences, and documents. It usually contains most of the other folders. If a requested folder does not exist, the home folder can be considered a safe fallback to store a user's documents.
266pub const SDL_FOLDER_HOME: SDL_Folder = SDL_Folder::HOME;
267/// The folder of files that are displayed on the desktop. Note that the existence of a desktop folder does not guarantee that the system does show icons on its desktop; certain GNU/Linux distros with a graphical environment may not have desktop icons.
268pub const SDL_FOLDER_DESKTOP: SDL_Folder = SDL_Folder::DESKTOP;
269/// User document files, possibly application-specific. This is a good place to save a user's projects.
270pub const SDL_FOLDER_DOCUMENTS: SDL_Folder = SDL_Folder::DOCUMENTS;
271/// Standard folder for user files downloaded from the internet.
272pub const SDL_FOLDER_DOWNLOADS: SDL_Folder = SDL_Folder::DOWNLOADS;
273/// Music files that can be played using a standard music player (mp3, ogg...).
274pub const SDL_FOLDER_MUSIC: SDL_Folder = SDL_Folder::MUSIC;
275/// Image files that can be displayed using a standard viewer (png, jpg...).
276pub const SDL_FOLDER_PICTURES: SDL_Folder = SDL_Folder::PICTURES;
277/// Files that are meant to be shared with other users on the same computer.
278pub const SDL_FOLDER_PUBLICSHARE: SDL_Folder = SDL_Folder::PUBLICSHARE;
279/// Save files for games.
280pub const SDL_FOLDER_SAVEDGAMES: SDL_Folder = SDL_Folder::SAVEDGAMES;
281/// Application screenshots.
282pub const SDL_FOLDER_SCREENSHOTS: SDL_Folder = SDL_Folder::SCREENSHOTS;
283/// Template files to be used when the user requests the desktop environment to create a new file in a certain folder, such as "New Text File.txt".  Any file in the Templates folder can be used as a starting point for a new file.
284pub const SDL_FOLDER_TEMPLATES: SDL_Folder = SDL_Folder::TEMPLATES;
285/// Video files that can be played using a standard video player (mp4, webm...).
286pub const SDL_FOLDER_VIDEOS: SDL_Folder = SDL_Folder::VIDEOS;
287/// Total number of types in this enum, not a folder type by itself.
288pub const SDL_FOLDER_COUNT: SDL_Folder = SDL_Folder::COUNT;
289
290#[cfg(feature = "metadata")]
291impl sdl3_sys::metadata::GroupMetadata for SDL_Folder {
292    const GROUP_METADATA: &'static sdl3_sys::metadata::Group =
293        &crate::metadata::filesystem::METADATA_SDL_Folder;
294}
295
296unsafe extern "C" {
297    /// Finds the most suitable user folder for a specific purpose.
298    ///
299    /// Many OSes provide certain standard folders for certain purposes, such as
300    /// storing pictures, music or videos for a certain user. This function gives
301    /// the path for many of those special locations.
302    ///
303    /// This function is specifically for _user_ folders, which are meant for the
304    /// user to access and manage. For application-specific folders, meant to hold
305    /// data for the application to manage, see [`SDL_GetBasePath()`] and
306    /// [`SDL_GetPrefPath()`].
307    ///
308    /// The returned path is guaranteed to end with a path separator ('\\' on
309    /// Windows, '/' on most other platforms).
310    ///
311    /// If NULL is returned, the error may be obtained with [`SDL_GetError()`].
312    ///
313    /// ## Parameters
314    /// - `folder`: the type of folder to find.
315    ///
316    /// ## Return value
317    /// Returns either a null-terminated C string containing the full path to the
318    ///   folder, or NULL if an error happened.
319    ///
320    /// ## Thread safety
321    /// It is safe to call this function from any thread.
322    ///
323    /// ## Availability
324    /// This function is available since SDL 3.2.0.
325    pub fn SDL_GetUserFolder(folder: SDL_Folder) -> *const ::core::ffi::c_char;
326}
327
328/// Types of filesystem entries.
329///
330/// Note that there may be other sorts of items on a filesystem: devices,
331/// symlinks, named pipes, etc. They are currently reported as
332/// [`SDL_PATHTYPE_OTHER`].
333///
334/// ## Availability
335/// This enum is available since SDL 3.2.0.
336///
337/// ## See also
338/// - [`SDL_PathInfo`]
339///
340/// ## Known values (`sdl3-sys`)
341/// | Associated constant | Global constant | Description |
342/// | ------------------- | --------------- | ----------- |
343/// | [`NONE`](SDL_PathType::NONE) | [`SDL_PATHTYPE_NONE`] | path does not exist |
344/// | [`FILE`](SDL_PathType::FILE) | [`SDL_PATHTYPE_FILE`] | a normal file |
345/// | [`DIRECTORY`](SDL_PathType::DIRECTORY) | [`SDL_PATHTYPE_DIRECTORY`] | a directory |
346/// | [`OTHER`](SDL_PathType::OTHER) | [`SDL_PATHTYPE_OTHER`] | something completely different like a device node (not a symlink, those are always followed) |
347#[repr(transparent)]
348#[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
349pub struct SDL_PathType(pub ::core::ffi::c_int);
350
351impl ::core::cmp::PartialEq<::core::ffi::c_int> for SDL_PathType {
352    #[inline(always)]
353    fn eq(&self, other: &::core::ffi::c_int) -> bool {
354        &self.0 == other
355    }
356}
357
358impl ::core::cmp::PartialEq<SDL_PathType> for ::core::ffi::c_int {
359    #[inline(always)]
360    fn eq(&self, other: &SDL_PathType) -> bool {
361        self == &other.0
362    }
363}
364
365impl From<SDL_PathType> for ::core::ffi::c_int {
366    #[inline(always)]
367    fn from(value: SDL_PathType) -> Self {
368        value.0
369    }
370}
371
372#[cfg(feature = "debug-impls")]
373impl ::core::fmt::Debug for SDL_PathType {
374    fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
375        #[allow(unreachable_patterns)]
376        f.write_str(match *self {
377            Self::NONE => "SDL_PATHTYPE_NONE",
378            Self::FILE => "SDL_PATHTYPE_FILE",
379            Self::DIRECTORY => "SDL_PATHTYPE_DIRECTORY",
380            Self::OTHER => "SDL_PATHTYPE_OTHER",
381
382            _ => return write!(f, "SDL_PathType({})", self.0),
383        })
384    }
385}
386
387impl SDL_PathType {
388    /// path does not exist
389    pub const NONE: Self = Self((0 as ::core::ffi::c_int));
390    /// a normal file
391    pub const FILE: Self = Self((1 as ::core::ffi::c_int));
392    /// a directory
393    pub const DIRECTORY: Self = Self((2 as ::core::ffi::c_int));
394    /// something completely different like a device node (not a symlink, those are always followed)
395    pub const OTHER: Self = Self((3 as ::core::ffi::c_int));
396}
397
398/// path does not exist
399pub const SDL_PATHTYPE_NONE: SDL_PathType = SDL_PathType::NONE;
400/// a normal file
401pub const SDL_PATHTYPE_FILE: SDL_PathType = SDL_PathType::FILE;
402/// a directory
403pub const SDL_PATHTYPE_DIRECTORY: SDL_PathType = SDL_PathType::DIRECTORY;
404/// something completely different like a device node (not a symlink, those are always followed)
405pub const SDL_PATHTYPE_OTHER: SDL_PathType = SDL_PathType::OTHER;
406
407#[cfg(feature = "metadata")]
408impl sdl3_sys::metadata::GroupMetadata for SDL_PathType {
409    const GROUP_METADATA: &'static sdl3_sys::metadata::Group =
410        &crate::metadata::filesystem::METADATA_SDL_PathType;
411}
412
413/// Information about a path on the filesystem.
414///
415/// ## Availability
416/// This datatype is available since SDL 3.2.0.
417///
418/// ## See also
419/// - [`SDL_GetPathInfo`]
420/// - [`SDL_GetStoragePathInfo`]
421#[repr(C)]
422#[derive(Clone, Copy, Default, PartialEq, Eq, Hash)]
423#[cfg_attr(feature = "debug-impls", derive(Debug))]
424pub struct SDL_PathInfo {
425    /// the path type
426    pub r#type: SDL_PathType,
427    /// the file size in bytes
428    pub size: Uint64,
429    /// the time when the path was created
430    pub create_time: SDL_Time,
431    /// the last time the path was modified
432    pub modify_time: SDL_Time,
433    /// the last time the path was read
434    pub access_time: SDL_Time,
435}
436
437/// Flags for path matching.
438///
439/// ## Availability
440/// This datatype is available since SDL 3.2.0.
441///
442/// ## See also
443/// - [`SDL_GlobDirectory`]
444/// - [`SDL_GlobStorageDirectory`]
445///
446/// ## Known values (`sdl3-sys`)
447/// | Associated constant | Global constant | Description |
448/// | ------------------- | --------------- | ----------- |
449/// | [`CASEINSENSITIVE`](SDL_GlobFlags::CASEINSENSITIVE) | [`SDL_GLOB_CASEINSENSITIVE`] | |
450#[repr(transparent)]
451#[derive(Clone, Copy, Default, PartialEq, Eq, Hash)]
452pub struct SDL_GlobFlags(pub Uint32);
453
454impl ::core::cmp::PartialEq<Uint32> for SDL_GlobFlags {
455    #[inline(always)]
456    fn eq(&self, other: &Uint32) -> bool {
457        &self.0 == other
458    }
459}
460
461impl ::core::cmp::PartialEq<SDL_GlobFlags> for Uint32 {
462    #[inline(always)]
463    fn eq(&self, other: &SDL_GlobFlags) -> bool {
464        self == &other.0
465    }
466}
467
468impl From<SDL_GlobFlags> for Uint32 {
469    #[inline(always)]
470    fn from(value: SDL_GlobFlags) -> Self {
471        value.0
472    }
473}
474
475#[cfg(feature = "debug-impls")]
476impl ::core::fmt::Debug for SDL_GlobFlags {
477    fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
478        let mut first = true;
479        let all_bits = 0;
480        write!(f, "SDL_GlobFlags(")?;
481        let all_bits = all_bits | Self::CASEINSENSITIVE.0;
482        if (Self::CASEINSENSITIVE != 0 || self.0 == 0)
483            && *self & Self::CASEINSENSITIVE == Self::CASEINSENSITIVE
484        {
485            if !first {
486                write!(f, " | ")?;
487            }
488            first = false;
489            write!(f, "CASEINSENSITIVE")?;
490        }
491
492        if self.0 & !all_bits != 0 {
493            if !first {
494                write!(f, " | ")?;
495            }
496            write!(f, "{:#x}", self.0)?;
497        } else if first {
498            write!(f, "0")?;
499        }
500        write!(f, ")")
501    }
502}
503
504impl ::core::ops::BitAnd for SDL_GlobFlags {
505    type Output = Self;
506
507    #[inline(always)]
508    fn bitand(self, rhs: Self) -> Self::Output {
509        Self(self.0 & rhs.0)
510    }
511}
512
513impl ::core::ops::BitAndAssign for SDL_GlobFlags {
514    #[inline(always)]
515    fn bitand_assign(&mut self, rhs: Self) {
516        self.0 &= rhs.0;
517    }
518}
519
520impl ::core::ops::BitOr for SDL_GlobFlags {
521    type Output = Self;
522
523    #[inline(always)]
524    fn bitor(self, rhs: Self) -> Self::Output {
525        Self(self.0 | rhs.0)
526    }
527}
528
529impl ::core::ops::BitOrAssign for SDL_GlobFlags {
530    #[inline(always)]
531    fn bitor_assign(&mut self, rhs: Self) {
532        self.0 |= rhs.0;
533    }
534}
535
536impl ::core::ops::BitXor for SDL_GlobFlags {
537    type Output = Self;
538
539    #[inline(always)]
540    fn bitxor(self, rhs: Self) -> Self::Output {
541        Self(self.0 ^ rhs.0)
542    }
543}
544
545impl ::core::ops::BitXorAssign for SDL_GlobFlags {
546    #[inline(always)]
547    fn bitxor_assign(&mut self, rhs: Self) {
548        self.0 ^= rhs.0;
549    }
550}
551
552impl ::core::ops::Not for SDL_GlobFlags {
553    type Output = Self;
554
555    #[inline(always)]
556    fn not(self) -> Self::Output {
557        Self(!self.0)
558    }
559}
560
561impl SDL_GlobFlags {
562    pub const CASEINSENSITIVE: Self = Self((1_u32 as Uint32));
563}
564
565pub const SDL_GLOB_CASEINSENSITIVE: SDL_GlobFlags = SDL_GlobFlags::CASEINSENSITIVE;
566
567#[cfg(feature = "metadata")]
568impl sdl3_sys::metadata::GroupMetadata for SDL_GlobFlags {
569    const GROUP_METADATA: &'static sdl3_sys::metadata::Group =
570        &crate::metadata::filesystem::METADATA_SDL_GlobFlags;
571}
572
573unsafe extern "C" {
574    /// Create a directory, and any missing parent directories.
575    ///
576    /// This reports success if `path` already exists as a directory.
577    ///
578    /// If parent directories are missing, it will also create them. Note that if
579    /// this fails, it will not remove any parent directories it already made.
580    ///
581    /// ## Parameters
582    /// - `path`: the path of the directory to create.
583    ///
584    /// ## Return value
585    /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
586    ///   information.
587    ///
588    /// ## Thread safety
589    /// It is safe to call this function from any thread.
590    ///
591    /// ## Availability
592    /// This function is available since SDL 3.2.0.
593    pub fn SDL_CreateDirectory(path: *const ::core::ffi::c_char) -> ::core::primitive::bool;
594}
595
596/// Possible results from an enumeration callback.
597///
598/// ## Availability
599/// This enum is available since SDL 3.2.0.
600///
601/// ## See also
602/// - [`SDL_EnumerateDirectoryCallback`]
603///
604/// ## Known values (`sdl3-sys`)
605/// | Associated constant | Global constant | Description |
606/// | ------------------- | --------------- | ----------- |
607/// | [`CONTINUE`](SDL_EnumerationResult::CONTINUE) | [`SDL_ENUM_CONTINUE`] | Value that requests that enumeration continue. |
608/// | [`SUCCESS`](SDL_EnumerationResult::SUCCESS) | [`SDL_ENUM_SUCCESS`] | Value that requests that enumeration stop, successfully. |
609/// | [`FAILURE`](SDL_EnumerationResult::FAILURE) | [`SDL_ENUM_FAILURE`] | Value that requests that enumeration stop, as a failure. |
610#[repr(transparent)]
611#[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
612pub struct SDL_EnumerationResult(pub ::core::ffi::c_int);
613
614impl ::core::cmp::PartialEq<::core::ffi::c_int> for SDL_EnumerationResult {
615    #[inline(always)]
616    fn eq(&self, other: &::core::ffi::c_int) -> bool {
617        &self.0 == other
618    }
619}
620
621impl ::core::cmp::PartialEq<SDL_EnumerationResult> for ::core::ffi::c_int {
622    #[inline(always)]
623    fn eq(&self, other: &SDL_EnumerationResult) -> bool {
624        self == &other.0
625    }
626}
627
628impl From<SDL_EnumerationResult> for ::core::ffi::c_int {
629    #[inline(always)]
630    fn from(value: SDL_EnumerationResult) -> Self {
631        value.0
632    }
633}
634
635#[cfg(feature = "debug-impls")]
636impl ::core::fmt::Debug for SDL_EnumerationResult {
637    fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
638        #[allow(unreachable_patterns)]
639        f.write_str(match *self {
640            Self::CONTINUE => "SDL_ENUM_CONTINUE",
641            Self::SUCCESS => "SDL_ENUM_SUCCESS",
642            Self::FAILURE => "SDL_ENUM_FAILURE",
643
644            _ => return write!(f, "SDL_EnumerationResult({})", self.0),
645        })
646    }
647}
648
649impl SDL_EnumerationResult {
650    /// Value that requests that enumeration continue.
651    pub const CONTINUE: Self = Self((0 as ::core::ffi::c_int));
652    /// Value that requests that enumeration stop, successfully.
653    pub const SUCCESS: Self = Self((1 as ::core::ffi::c_int));
654    /// Value that requests that enumeration stop, as a failure.
655    pub const FAILURE: Self = Self((2 as ::core::ffi::c_int));
656}
657
658/// Value that requests that enumeration continue.
659pub const SDL_ENUM_CONTINUE: SDL_EnumerationResult = SDL_EnumerationResult::CONTINUE;
660/// Value that requests that enumeration stop, successfully.
661pub const SDL_ENUM_SUCCESS: SDL_EnumerationResult = SDL_EnumerationResult::SUCCESS;
662/// Value that requests that enumeration stop, as a failure.
663pub const SDL_ENUM_FAILURE: SDL_EnumerationResult = SDL_EnumerationResult::FAILURE;
664
665#[cfg(feature = "metadata")]
666impl sdl3_sys::metadata::GroupMetadata for SDL_EnumerationResult {
667    const GROUP_METADATA: &'static sdl3_sys::metadata::Group =
668        &crate::metadata::filesystem::METADATA_SDL_EnumerationResult;
669}
670
671/// Callback for directory enumeration.
672///
673/// Enumeration of directory entries will continue until either all entries
674/// have been provided to the callback, or the callback has requested a stop
675/// through its return value.
676///
677/// Returning [`SDL_ENUM_CONTINUE`] will let enumeration proceed, calling the
678/// callback with further entries. [`SDL_ENUM_SUCCESS`] and [`SDL_ENUM_FAILURE`] will
679/// terminate the enumeration early, and dictate the return value of the
680/// enumeration function itself.
681///
682/// `dirname` is guaranteed to end with a path separator ('\\' on Windows, '/'
683/// on most other platforms).
684///
685/// ## Parameters
686/// - `userdata`: an app-controlled pointer that is passed to the callback.
687/// - `dirname`: the directory that is being enumerated.
688/// - `fname`: the next entry in the enumeration.
689///
690/// ## Return value
691/// Returns how the enumeration should proceed.
692///
693/// ## Availability
694/// This datatype is available since SDL 3.2.0.
695///
696/// ## See also
697/// - [`SDL_EnumerateDirectory`]
698pub type SDL_EnumerateDirectoryCallback = ::core::option::Option<
699    unsafe extern "C" fn(
700        userdata: *mut ::core::ffi::c_void,
701        dirname: *const ::core::ffi::c_char,
702        fname: *const ::core::ffi::c_char,
703    ) -> SDL_EnumerationResult,
704>;
705
706unsafe extern "C" {
707    /// Enumerate a directory through a callback function.
708    ///
709    /// This function provides every directory entry through an app-provided
710    /// callback, called once for each directory entry, until all results have been
711    /// provided or the callback returns either [`SDL_ENUM_SUCCESS`] or
712    /// [`SDL_ENUM_FAILURE`].
713    ///
714    /// This will return false if there was a system problem in general, or if a
715    /// callback returns [`SDL_ENUM_FAILURE`]. A successful return means a callback
716    /// returned [`SDL_ENUM_SUCCESS`] to halt enumeration, or all directory entries
717    /// were enumerated.
718    ///
719    /// ## Parameters
720    /// - `path`: the path of the directory to enumerate.
721    /// - `callback`: a function that is called for each entry in the directory.
722    /// - `userdata`: a pointer that is passed to `callback`.
723    ///
724    /// ## Return value
725    /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
726    ///   information.
727    ///
728    /// ## Thread safety
729    /// It is safe to call this function from any thread.
730    ///
731    /// ## Availability
732    /// This function is available since SDL 3.2.0.
733    pub fn SDL_EnumerateDirectory(
734        path: *const ::core::ffi::c_char,
735        callback: SDL_EnumerateDirectoryCallback,
736        userdata: *mut ::core::ffi::c_void,
737    ) -> ::core::primitive::bool;
738}
739
740unsafe extern "C" {
741    /// Remove a file or an empty directory.
742    ///
743    /// Directories that are not empty will fail; this function will not recursely
744    /// delete directory trees.
745    ///
746    /// ## Parameters
747    /// - `path`: the path to remove from the filesystem.
748    ///
749    /// ## Return value
750    /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
751    ///   information.
752    ///
753    /// ## Thread safety
754    /// It is safe to call this function from any thread.
755    ///
756    /// ## Availability
757    /// This function is available since SDL 3.2.0.
758    pub fn SDL_RemovePath(path: *const ::core::ffi::c_char) -> ::core::primitive::bool;
759}
760
761unsafe extern "C" {
762    /// Rename a file or directory.
763    ///
764    /// If the file at `newpath` already exists, it will be replaced.
765    ///
766    /// Note that this will not copy files across filesystems/drives/volumes, as
767    /// that is a much more complicated (and possibly time-consuming) operation.
768    ///
769    /// Which is to say, if this function fails, [`SDL_CopyFile()`] to a temporary file
770    /// in the same directory as `newpath`, then [`SDL_RenamePath()`] from the
771    /// temporary file to `newpath` and [`SDL_RemovePath()`] on `oldpath` might work
772    /// for files. Renaming a non-empty directory across filesystems is
773    /// dramatically more complex, however.
774    ///
775    /// ## Parameters
776    /// - `oldpath`: the old path.
777    /// - `newpath`: the new path.
778    ///
779    /// ## Return value
780    /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
781    ///   information.
782    ///
783    /// ## Thread safety
784    /// It is safe to call this function from any thread.
785    ///
786    /// ## Availability
787    /// This function is available since SDL 3.2.0.
788    pub fn SDL_RenamePath(
789        oldpath: *const ::core::ffi::c_char,
790        newpath: *const ::core::ffi::c_char,
791    ) -> ::core::primitive::bool;
792}
793
794unsafe extern "C" {
795    /// Copy a file.
796    ///
797    /// If the file at `newpath` already exists, it will be overwritten with the
798    /// contents of the file at `oldpath`.
799    ///
800    /// This function will block until the copy is complete, which might be a
801    /// significant time for large files on slow disks. On some platforms, the copy
802    /// can be handed off to the OS itself, but on others SDL might just open both
803    /// paths, and read from one and write to the other.
804    ///
805    /// Note that this is not an atomic operation! If something tries to read from
806    /// `newpath` while the copy is in progress, it will see an incomplete copy of
807    /// the data, and if the calling thread terminates (or the power goes out)
808    /// during the copy, `newpath`'s previous contents will be gone, replaced with
809    /// an incomplete copy of the data. To avoid this risk, it is recommended that
810    /// the app copy to a temporary file in the same directory as `newpath`, and if
811    /// the copy is successful, use [`SDL_RenamePath()`] to replace `newpath` with the
812    /// temporary file. This will ensure that reads of `newpath` will either see a
813    /// complete copy of the data, or it will see the pre-copy state of `newpath`.
814    ///
815    /// This function attempts to synchronize the newly-copied data to disk before
816    /// returning, if the platform allows it, so that the renaming trick will not
817    /// have a problem in a system crash or power failure, where the file could be
818    /// renamed but the contents never made it from the system file cache to the
819    /// physical disk.
820    ///
821    /// If the copy fails for any reason, the state of `newpath` is undefined. It
822    /// might be half a copy, it might be the untouched data of what was already
823    /// there, or it might be a zero-byte file, etc.
824    ///
825    /// ## Parameters
826    /// - `oldpath`: the old path.
827    /// - `newpath`: the new path.
828    ///
829    /// ## Return value
830    /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
831    ///   information.
832    ///
833    /// ## Thread safety
834    /// It is safe to call this function from any thread, but this
835    ///   operation is not atomic, so the app might need to protect
836    ///   access to specific paths from other threads if appropriate.
837    ///
838    /// ## Availability
839    /// This function is available since SDL 3.2.0.
840    pub fn SDL_CopyFile(
841        oldpath: *const ::core::ffi::c_char,
842        newpath: *const ::core::ffi::c_char,
843    ) -> ::core::primitive::bool;
844}
845
846unsafe extern "C" {
847    /// Get information about a filesystem path.
848    ///
849    /// ## Parameters
850    /// - `path`: the path to query.
851    /// - `info`: a pointer filled in with information about the path, or NULL to
852    ///   check for the existence of a file.
853    ///
854    /// ## Return value
855    /// Returns true on success or false if the file doesn't exist, or another
856    ///   failure; call [`SDL_GetError()`] for more information.
857    ///
858    /// ## Thread safety
859    /// It is safe to call this function from any thread.
860    ///
861    /// ## Availability
862    /// This function is available since SDL 3.2.0.
863    pub fn SDL_GetPathInfo(
864        path: *const ::core::ffi::c_char,
865        info: *mut SDL_PathInfo,
866    ) -> ::core::primitive::bool;
867}
868
869unsafe extern "C" {
870    /// Enumerate a directory tree, filtered by pattern, and return a list.
871    ///
872    /// Files are filtered out if they don't match the string in `pattern`, which
873    /// may contain wildcard characters `*` (match everything) and `?` (match one
874    /// character). If pattern is NULL, no filtering is done and all results are
875    /// returned. Subdirectories are permitted, and are specified with a path
876    /// separator of `/`. Wildcard characters `*` and `?` never match a path
877    /// separator.
878    ///
879    /// `flags` may be set to [`SDL_GLOB_CASEINSENSITIVE`] to make the pattern matching
880    /// case-insensitive.
881    ///
882    /// The returned array is always NULL-terminated, for your iterating
883    /// convenience, but if `count` is non-NULL, on return it will contain the
884    /// number of items in the array, not counting the NULL terminator.
885    ///
886    /// ## Parameters
887    /// - `path`: the path of the directory to enumerate.
888    /// - `pattern`: the pattern that files in the directory must match. Can be
889    ///   NULL.
890    /// - `flags`: `SDL_GLOB_*` bitflags that affect this search.
891    /// - `count`: on return, will be set to the number of items in the returned
892    ///   array. Can be NULL.
893    ///
894    /// ## Return value
895    /// Returns an array of strings on success or NULL on failure; call
896    ///   [`SDL_GetError()`] for more information. This is a single allocation
897    ///   that should be freed with [`SDL_free()`] when it is no longer needed.
898    ///
899    /// ## Thread safety
900    /// It is safe to call this function from any thread.
901    ///
902    /// ## Availability
903    /// This function is available since SDL 3.2.0.
904    pub fn SDL_GlobDirectory(
905        path: *const ::core::ffi::c_char,
906        pattern: *const ::core::ffi::c_char,
907        flags: SDL_GlobFlags,
908        count: *mut ::core::ffi::c_int,
909    ) -> *mut *mut ::core::ffi::c_char;
910}
911
912unsafe extern "C" {
913    /// Get what the system believes is the "current working directory."
914    ///
915    /// For systems without a concept of a current working directory, this will
916    /// still attempt to provide something reasonable.
917    ///
918    /// SDL does not provide a means to _change_ the current working directory; for
919    /// platforms without this concept, this would cause surprises with file access
920    /// outside of SDL.
921    ///
922    /// The returned path is guaranteed to end with a path separator ('\\' on
923    /// Windows, '/' on most other platforms).
924    ///
925    /// ## Return value
926    /// Returns a UTF-8 string of the current working directory in
927    ///   platform-dependent notation. NULL if there's a problem. This
928    ///   should be freed with [`SDL_free()`] when it is no longer needed.
929    ///
930    /// ## Thread safety
931    /// It is safe to call this function from any thread.
932    ///
933    /// ## Availability
934    /// This function is available since SDL 3.2.0.
935    pub fn SDL_GetCurrentDirectory() -> *mut ::core::ffi::c_char;
936}
937
938#[cfg(doc)]
939use crate::everything::*;