Skip to main content

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
290impl SDL_Folder {
291    /// Initialize a `SDL_Folder` from a raw value.
292    #[inline(always)]
293    pub const fn new(value: ::core::ffi::c_int) -> Self {
294        Self(value)
295    }
296}
297
298impl SDL_Folder {
299    /// Get a copy of the inner raw value.
300    #[inline(always)]
301    pub const fn value(&self) -> ::core::ffi::c_int {
302        self.0
303    }
304}
305
306#[cfg(feature = "metadata")]
307impl sdl3_sys::metadata::GroupMetadata for SDL_Folder {
308    const GROUP_METADATA: &'static sdl3_sys::metadata::Group =
309        &crate::metadata::filesystem::METADATA_SDL_Folder;
310}
311
312unsafe extern "C" {
313    /// Finds the most suitable user folder for a specific purpose.
314    ///
315    /// Many OSes provide certain standard folders for certain purposes, such as
316    /// storing pictures, music or videos for a certain user. This function gives
317    /// the path for many of those special locations.
318    ///
319    /// This function is specifically for _user_ folders, which are meant for the
320    /// user to access and manage. For application-specific folders, meant to hold
321    /// data for the application to manage, see [`SDL_GetBasePath()`] and
322    /// [`SDL_GetPrefPath()`].
323    ///
324    /// The returned path is guaranteed to end with a path separator ('\\' on
325    /// Windows, '/' on most other platforms).
326    ///
327    /// If NULL is returned, the error may be obtained with [`SDL_GetError()`].
328    ///
329    /// ## Parameters
330    /// - `folder`: the type of folder to find.
331    ///
332    /// ## Return value
333    /// Returns either a null-terminated C string containing the full path to the
334    ///   folder, or NULL if an error happened.
335    ///
336    /// ## Thread safety
337    /// It is safe to call this function from any thread.
338    ///
339    /// ## Availability
340    /// This function is available since SDL 3.2.0.
341    pub fn SDL_GetUserFolder(folder: SDL_Folder) -> *const ::core::ffi::c_char;
342}
343
344/// Types of filesystem entries.
345///
346/// Note that there may be other sorts of items on a filesystem: devices, named
347/// pipes, etc. They are currently reported as [`SDL_PATHTYPE_OTHER`].
348///
349/// ## Availability
350/// This enum is available since SDL 3.2.0.
351///
352/// ## See also
353/// - [`SDL_PathInfo`]
354///
355/// ## Known values (`sdl3-sys`)
356/// | Associated constant | Global constant | Description |
357/// | ------------------- | --------------- | ----------- |
358/// | [`NONE`](SDL_PathType::NONE) | [`SDL_PATHTYPE_NONE`] | path does not exist |
359/// | [`FILE`](SDL_PathType::FILE) | [`SDL_PATHTYPE_FILE`] | a normal file |
360/// | [`DIRECTORY`](SDL_PathType::DIRECTORY) | [`SDL_PATHTYPE_DIRECTORY`] | a directory |
361/// | [`OTHER`](SDL_PathType::OTHER) | [`SDL_PATHTYPE_OTHER`] | something completely different like a device node (not a symlink, those are always followed) |
362#[repr(transparent)]
363#[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
364pub struct SDL_PathType(pub ::core::ffi::c_int);
365
366impl ::core::cmp::PartialEq<::core::ffi::c_int> for SDL_PathType {
367    #[inline(always)]
368    fn eq(&self, other: &::core::ffi::c_int) -> bool {
369        &self.0 == other
370    }
371}
372
373impl ::core::cmp::PartialEq<SDL_PathType> for ::core::ffi::c_int {
374    #[inline(always)]
375    fn eq(&self, other: &SDL_PathType) -> bool {
376        self == &other.0
377    }
378}
379
380impl From<SDL_PathType> for ::core::ffi::c_int {
381    #[inline(always)]
382    fn from(value: SDL_PathType) -> Self {
383        value.0
384    }
385}
386
387#[cfg(feature = "debug-impls")]
388impl ::core::fmt::Debug for SDL_PathType {
389    fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
390        #[allow(unreachable_patterns)]
391        f.write_str(match *self {
392            Self::NONE => "SDL_PATHTYPE_NONE",
393            Self::FILE => "SDL_PATHTYPE_FILE",
394            Self::DIRECTORY => "SDL_PATHTYPE_DIRECTORY",
395            Self::OTHER => "SDL_PATHTYPE_OTHER",
396
397            _ => return write!(f, "SDL_PathType({})", self.0),
398        })
399    }
400}
401
402impl SDL_PathType {
403    /// path does not exist
404    pub const NONE: Self = Self((0 as ::core::ffi::c_int));
405    /// a normal file
406    pub const FILE: Self = Self((1 as ::core::ffi::c_int));
407    /// a directory
408    pub const DIRECTORY: Self = Self((2 as ::core::ffi::c_int));
409    /// something completely different like a device node (not a symlink, those are always followed)
410    pub const OTHER: Self = Self((3 as ::core::ffi::c_int));
411}
412
413/// path does not exist
414pub const SDL_PATHTYPE_NONE: SDL_PathType = SDL_PathType::NONE;
415/// a normal file
416pub const SDL_PATHTYPE_FILE: SDL_PathType = SDL_PathType::FILE;
417/// a directory
418pub const SDL_PATHTYPE_DIRECTORY: SDL_PathType = SDL_PathType::DIRECTORY;
419/// something completely different like a device node (not a symlink, those are always followed)
420pub const SDL_PATHTYPE_OTHER: SDL_PathType = SDL_PathType::OTHER;
421
422impl SDL_PathType {
423    /// Initialize a `SDL_PathType` from a raw value.
424    #[inline(always)]
425    pub const fn new(value: ::core::ffi::c_int) -> Self {
426        Self(value)
427    }
428}
429
430impl SDL_PathType {
431    /// Get a copy of the inner raw value.
432    #[inline(always)]
433    pub const fn value(&self) -> ::core::ffi::c_int {
434        self.0
435    }
436}
437
438#[cfg(feature = "metadata")]
439impl sdl3_sys::metadata::GroupMetadata for SDL_PathType {
440    const GROUP_METADATA: &'static sdl3_sys::metadata::Group =
441        &crate::metadata::filesystem::METADATA_SDL_PathType;
442}
443
444/// Information about a path on the filesystem.
445///
446/// ## Availability
447/// This datatype is available since SDL 3.2.0.
448///
449/// ## See also
450/// - [`SDL_GetPathInfo`]
451/// - [`SDL_GetStoragePathInfo`]
452#[repr(C)]
453#[derive(Clone, Copy, Default, PartialEq, Eq, Hash)]
454#[cfg_attr(feature = "debug-impls", derive(Debug))]
455pub struct SDL_PathInfo {
456    /// the path type
457    pub r#type: SDL_PathType,
458    /// the file size in bytes
459    pub size: Uint64,
460    /// the time when the path was created
461    pub create_time: SDL_Time,
462    /// the last time the path was modified
463    pub modify_time: SDL_Time,
464    /// the last time the path was read
465    pub access_time: SDL_Time,
466}
467
468/// Flags for path matching.
469///
470/// ## Availability
471/// This datatype is available since SDL 3.2.0.
472///
473/// ## See also
474/// - [`SDL_GlobDirectory`]
475/// - [`SDL_GlobStorageDirectory`]
476///
477/// ## Known values (`sdl3-sys`)
478/// | Associated constant | Global constant | Description |
479/// | ------------------- | --------------- | ----------- |
480/// | [`CASEINSENSITIVE`](SDL_GlobFlags::CASEINSENSITIVE) | [`SDL_GLOB_CASEINSENSITIVE`] | |
481#[repr(transparent)]
482#[derive(Clone, Copy, Default, PartialEq, Eq, Hash)]
483pub struct SDL_GlobFlags(pub Uint32);
484
485impl ::core::cmp::PartialEq<Uint32> for SDL_GlobFlags {
486    #[inline(always)]
487    fn eq(&self, other: &Uint32) -> bool {
488        &self.0 == other
489    }
490}
491
492impl ::core::cmp::PartialEq<SDL_GlobFlags> for Uint32 {
493    #[inline(always)]
494    fn eq(&self, other: &SDL_GlobFlags) -> bool {
495        self == &other.0
496    }
497}
498
499impl From<SDL_GlobFlags> for Uint32 {
500    #[inline(always)]
501    fn from(value: SDL_GlobFlags) -> Self {
502        value.0
503    }
504}
505
506#[cfg(feature = "debug-impls")]
507impl ::core::fmt::Debug for SDL_GlobFlags {
508    fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
509        let mut first = true;
510        let all_bits = 0;
511        write!(f, "SDL_GlobFlags(")?;
512        let all_bits = all_bits | Self::CASEINSENSITIVE.0;
513        if (Self::CASEINSENSITIVE != 0 || self.0 == 0)
514            && *self & Self::CASEINSENSITIVE == Self::CASEINSENSITIVE
515        {
516            if !first {
517                write!(f, " | ")?;
518            }
519            first = false;
520            write!(f, "CASEINSENSITIVE")?;
521        }
522
523        if self.0 & !all_bits != 0 {
524            if !first {
525                write!(f, " | ")?;
526            }
527            write!(f, "{:#x}", self.0)?;
528        } else if first {
529            write!(f, "0")?;
530        }
531        write!(f, ")")
532    }
533}
534
535impl ::core::ops::BitAnd for SDL_GlobFlags {
536    type Output = Self;
537
538    #[inline(always)]
539    fn bitand(self, rhs: Self) -> Self::Output {
540        Self(self.0 & rhs.0)
541    }
542}
543
544impl ::core::ops::BitAndAssign for SDL_GlobFlags {
545    #[inline(always)]
546    fn bitand_assign(&mut self, rhs: Self) {
547        self.0 &= rhs.0;
548    }
549}
550
551impl ::core::ops::BitOr for SDL_GlobFlags {
552    type Output = Self;
553
554    #[inline(always)]
555    fn bitor(self, rhs: Self) -> Self::Output {
556        Self(self.0 | rhs.0)
557    }
558}
559
560impl ::core::ops::BitOrAssign for SDL_GlobFlags {
561    #[inline(always)]
562    fn bitor_assign(&mut self, rhs: Self) {
563        self.0 |= rhs.0;
564    }
565}
566
567impl ::core::ops::BitXor for SDL_GlobFlags {
568    type Output = Self;
569
570    #[inline(always)]
571    fn bitxor(self, rhs: Self) -> Self::Output {
572        Self(self.0 ^ rhs.0)
573    }
574}
575
576impl ::core::ops::BitXorAssign for SDL_GlobFlags {
577    #[inline(always)]
578    fn bitxor_assign(&mut self, rhs: Self) {
579        self.0 ^= rhs.0;
580    }
581}
582
583impl ::core::ops::Not for SDL_GlobFlags {
584    type Output = Self;
585
586    #[inline(always)]
587    fn not(self) -> Self::Output {
588        Self(!self.0)
589    }
590}
591
592impl SDL_GlobFlags {
593    pub const CASEINSENSITIVE: Self = Self((1_u32 as Uint32));
594}
595
596pub const SDL_GLOB_CASEINSENSITIVE: SDL_GlobFlags = SDL_GlobFlags::CASEINSENSITIVE;
597
598impl SDL_GlobFlags {
599    /// Initialize a `SDL_GlobFlags` from a raw value.
600    #[inline(always)]
601    pub const fn new(value: Uint32) -> Self {
602        Self(value)
603    }
604}
605
606impl SDL_GlobFlags {
607    /// Get a copy of the inner raw value.
608    #[inline(always)]
609    pub const fn value(&self) -> Uint32 {
610        self.0
611    }
612}
613
614#[cfg(feature = "metadata")]
615impl sdl3_sys::metadata::GroupMetadata for SDL_GlobFlags {
616    const GROUP_METADATA: &'static sdl3_sys::metadata::Group =
617        &crate::metadata::filesystem::METADATA_SDL_GlobFlags;
618}
619
620unsafe extern "C" {
621    /// Create a directory, and any missing parent directories.
622    ///
623    /// This reports success if `path` already exists as a directory.
624    ///
625    /// If parent directories are missing, it will also create them. Note that if
626    /// this fails, it will not remove any parent directories it already made.
627    ///
628    /// ## Parameters
629    /// - `path`: the path of the directory to create.
630    ///
631    /// ## Return value
632    /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
633    ///   information.
634    ///
635    /// ## Thread safety
636    /// It is safe to call this function from any thread.
637    ///
638    /// ## Availability
639    /// This function is available since SDL 3.2.0.
640    pub fn SDL_CreateDirectory(path: *const ::core::ffi::c_char) -> ::core::primitive::bool;
641}
642
643/// Possible results from an enumeration callback.
644///
645/// ## Availability
646/// This enum is available since SDL 3.2.0.
647///
648/// ## See also
649/// - [`SDL_EnumerateDirectoryCallback`]
650///
651/// ## Known values (`sdl3-sys`)
652/// | Associated constant | Global constant | Description |
653/// | ------------------- | --------------- | ----------- |
654/// | [`CONTINUE`](SDL_EnumerationResult::CONTINUE) | [`SDL_ENUM_CONTINUE`] | Value that requests that enumeration continue. |
655/// | [`SUCCESS`](SDL_EnumerationResult::SUCCESS) | [`SDL_ENUM_SUCCESS`] | Value that requests that enumeration stop, successfully. |
656/// | [`FAILURE`](SDL_EnumerationResult::FAILURE) | [`SDL_ENUM_FAILURE`] | Value that requests that enumeration stop, as a failure. |
657#[repr(transparent)]
658#[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
659pub struct SDL_EnumerationResult(pub ::core::ffi::c_int);
660
661impl ::core::cmp::PartialEq<::core::ffi::c_int> for SDL_EnumerationResult {
662    #[inline(always)]
663    fn eq(&self, other: &::core::ffi::c_int) -> bool {
664        &self.0 == other
665    }
666}
667
668impl ::core::cmp::PartialEq<SDL_EnumerationResult> for ::core::ffi::c_int {
669    #[inline(always)]
670    fn eq(&self, other: &SDL_EnumerationResult) -> bool {
671        self == &other.0
672    }
673}
674
675impl From<SDL_EnumerationResult> for ::core::ffi::c_int {
676    #[inline(always)]
677    fn from(value: SDL_EnumerationResult) -> Self {
678        value.0
679    }
680}
681
682#[cfg(feature = "debug-impls")]
683impl ::core::fmt::Debug for SDL_EnumerationResult {
684    fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
685        #[allow(unreachable_patterns)]
686        f.write_str(match *self {
687            Self::CONTINUE => "SDL_ENUM_CONTINUE",
688            Self::SUCCESS => "SDL_ENUM_SUCCESS",
689            Self::FAILURE => "SDL_ENUM_FAILURE",
690
691            _ => return write!(f, "SDL_EnumerationResult({})", self.0),
692        })
693    }
694}
695
696impl SDL_EnumerationResult {
697    /// Value that requests that enumeration continue.
698    pub const CONTINUE: Self = Self((0 as ::core::ffi::c_int));
699    /// Value that requests that enumeration stop, successfully.
700    pub const SUCCESS: Self = Self((1 as ::core::ffi::c_int));
701    /// Value that requests that enumeration stop, as a failure.
702    pub const FAILURE: Self = Self((2 as ::core::ffi::c_int));
703}
704
705/// Value that requests that enumeration continue.
706pub const SDL_ENUM_CONTINUE: SDL_EnumerationResult = SDL_EnumerationResult::CONTINUE;
707/// Value that requests that enumeration stop, successfully.
708pub const SDL_ENUM_SUCCESS: SDL_EnumerationResult = SDL_EnumerationResult::SUCCESS;
709/// Value that requests that enumeration stop, as a failure.
710pub const SDL_ENUM_FAILURE: SDL_EnumerationResult = SDL_EnumerationResult::FAILURE;
711
712impl SDL_EnumerationResult {
713    /// Initialize a `SDL_EnumerationResult` from a raw value.
714    #[inline(always)]
715    pub const fn new(value: ::core::ffi::c_int) -> Self {
716        Self(value)
717    }
718}
719
720impl SDL_EnumerationResult {
721    /// Get a copy of the inner raw value.
722    #[inline(always)]
723    pub const fn value(&self) -> ::core::ffi::c_int {
724        self.0
725    }
726}
727
728#[cfg(feature = "metadata")]
729impl sdl3_sys::metadata::GroupMetadata for SDL_EnumerationResult {
730    const GROUP_METADATA: &'static sdl3_sys::metadata::Group =
731        &crate::metadata::filesystem::METADATA_SDL_EnumerationResult;
732}
733
734/// Callback for directory enumeration.
735///
736/// Enumeration of directory entries will continue until either all entries
737/// have been provided to the callback, or the callback has requested a stop
738/// through its return value.
739///
740/// Returning [`SDL_ENUM_CONTINUE`] will let enumeration proceed, calling the
741/// callback with further entries. [`SDL_ENUM_SUCCESS`] and [`SDL_ENUM_FAILURE`] will
742/// terminate the enumeration early, and dictate the return value of the
743/// enumeration function itself.
744///
745/// `dirname` is guaranteed to end with a path separator ('\\' on Windows, '/'
746/// on most other platforms).
747///
748/// ## Parameters
749/// - `userdata`: an app-controlled pointer that is passed to the callback.
750/// - `dirname`: the directory that is being enumerated.
751/// - `fname`: the next entry in the enumeration.
752///
753/// ## Return value
754/// Returns how the enumeration should proceed.
755///
756/// ## Availability
757/// This datatype is available since SDL 3.2.0.
758///
759/// ## See also
760/// - [`SDL_EnumerateDirectory`]
761pub type SDL_EnumerateDirectoryCallback = ::core::option::Option<
762    unsafe extern "C" fn(
763        userdata: *mut ::core::ffi::c_void,
764        dirname: *const ::core::ffi::c_char,
765        fname: *const ::core::ffi::c_char,
766    ) -> SDL_EnumerationResult,
767>;
768
769unsafe extern "C" {
770    /// Enumerate a directory through a callback function.
771    ///
772    /// This function provides every directory entry through an app-provided
773    /// callback, called once for each directory entry, until all results have been
774    /// provided or the callback returns either [`SDL_ENUM_SUCCESS`] or
775    /// [`SDL_ENUM_FAILURE`].
776    ///
777    /// This will return false if there was a system problem in general, or if a
778    /// callback returns [`SDL_ENUM_FAILURE`]. A successful return means a callback
779    /// returned [`SDL_ENUM_SUCCESS`] to halt enumeration, or all directory entries
780    /// were enumerated.
781    ///
782    /// ## Parameters
783    /// - `path`: the path of the directory to enumerate.
784    /// - `callback`: a function that is called for each entry in the directory.
785    /// - `userdata`: a pointer that is passed to `callback`.
786    ///
787    /// ## Return value
788    /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
789    ///   information.
790    ///
791    /// ## Thread safety
792    /// It is safe to call this function from any thread.
793    ///
794    /// ## Availability
795    /// This function is available since SDL 3.2.0.
796    pub fn SDL_EnumerateDirectory(
797        path: *const ::core::ffi::c_char,
798        callback: SDL_EnumerateDirectoryCallback,
799        userdata: *mut ::core::ffi::c_void,
800    ) -> ::core::primitive::bool;
801}
802
803unsafe extern "C" {
804    /// Remove a file or an empty directory.
805    ///
806    /// Directories that are not empty will fail; this function will not recursely
807    /// delete directory trees.
808    ///
809    /// ## Parameters
810    /// - `path`: the path to remove from the filesystem.
811    ///
812    /// ## Return value
813    /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
814    ///   information.
815    ///
816    /// ## Thread safety
817    /// It is safe to call this function from any thread.
818    ///
819    /// ## Availability
820    /// This function is available since SDL 3.2.0.
821    pub fn SDL_RemovePath(path: *const ::core::ffi::c_char) -> ::core::primitive::bool;
822}
823
824unsafe extern "C" {
825    /// Rename a file or directory.
826    ///
827    /// If the file at `newpath` already exists, it will be replaced.
828    ///
829    /// Note that this will not copy files across filesystems/drives/volumes, as
830    /// that is a much more complicated (and possibly time-consuming) operation.
831    ///
832    /// Which is to say, if this function fails, [`SDL_CopyFile()`] to a temporary file
833    /// in the same directory as `newpath`, then [`SDL_RenamePath()`] from the
834    /// temporary file to `newpath` and [`SDL_RemovePath()`] on `oldpath` might work
835    /// for files. Renaming a non-empty directory across filesystems is
836    /// dramatically more complex, however.
837    ///
838    /// ## Parameters
839    /// - `oldpath`: the old path.
840    /// - `newpath`: the new path.
841    ///
842    /// ## Return value
843    /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
844    ///   information.
845    ///
846    /// ## Thread safety
847    /// It is safe to call this function from any thread.
848    ///
849    /// ## Availability
850    /// This function is available since SDL 3.2.0.
851    pub fn SDL_RenamePath(
852        oldpath: *const ::core::ffi::c_char,
853        newpath: *const ::core::ffi::c_char,
854    ) -> ::core::primitive::bool;
855}
856
857unsafe extern "C" {
858    /// Copy a file.
859    ///
860    /// If the file at `newpath` already exists, it will be overwritten with the
861    /// contents of the file at `oldpath`.
862    ///
863    /// This function will block until the copy is complete, which might be a
864    /// significant time for large files on slow disks. On some platforms, the copy
865    /// can be handed off to the OS itself, but on others SDL might just open both
866    /// paths, and read from one and write to the other.
867    ///
868    /// Note that this is not an atomic operation! If something tries to read from
869    /// `newpath` while the copy is in progress, it will see an incomplete copy of
870    /// the data, and if the calling thread terminates (or the power goes out)
871    /// during the copy, `newpath`'s previous contents will be gone, replaced with
872    /// an incomplete copy of the data. To avoid this risk, it is recommended that
873    /// the app copy to a temporary file in the same directory as `newpath`, and if
874    /// the copy is successful, use [`SDL_RenamePath()`] to replace `newpath` with the
875    /// temporary file. This will ensure that reads of `newpath` will either see a
876    /// complete copy of the data, or it will see the pre-copy state of `newpath`.
877    ///
878    /// This function attempts to synchronize the newly-copied data to disk before
879    /// returning, if the platform allows it, so that the renaming trick will not
880    /// have a problem in a system crash or power failure, where the file could be
881    /// renamed but the contents never made it from the system file cache to the
882    /// physical disk.
883    ///
884    /// If the copy fails for any reason, the state of `newpath` is undefined. It
885    /// might be half a copy, it might be the untouched data of what was already
886    /// there, or it might be a zero-byte file, etc.
887    ///
888    /// ## Parameters
889    /// - `oldpath`: the old path.
890    /// - `newpath`: the new path.
891    ///
892    /// ## Return value
893    /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
894    ///   information.
895    ///
896    /// ## Thread safety
897    /// It is safe to call this function from any thread, but this
898    ///   operation is not atomic, so the app might need to protect
899    ///   access to specific paths from other threads if appropriate.
900    ///
901    /// ## Availability
902    /// This function is available since SDL 3.2.0.
903    pub fn SDL_CopyFile(
904        oldpath: *const ::core::ffi::c_char,
905        newpath: *const ::core::ffi::c_char,
906    ) -> ::core::primitive::bool;
907}
908
909unsafe extern "C" {
910    /// Get information about a filesystem path.
911    ///
912    /// Symlinks, on filesystems that support them, are always followed, so you
913    /// will always get information on what the symlink eventually points to, and
914    /// not the symlink itself.
915    ///
916    /// ## Parameters
917    /// - `path`: the path to query.
918    /// - `info`: a pointer filled in with information about the path, or NULL to
919    ///   check for the existence of a file.
920    ///
921    /// ## Return value
922    /// Returns true on success or false if the file doesn't exist, or another
923    ///   failure; call [`SDL_GetError()`] for more information.
924    ///
925    /// ## Thread safety
926    /// It is safe to call this function from any thread.
927    ///
928    /// ## Availability
929    /// This function is available since SDL 3.2.0.
930    pub fn SDL_GetPathInfo(
931        path: *const ::core::ffi::c_char,
932        info: *mut SDL_PathInfo,
933    ) -> ::core::primitive::bool;
934}
935
936unsafe extern "C" {
937    /// Enumerate a directory tree, filtered by pattern, and return a list.
938    ///
939    /// Files are filtered out if they don't match the string in `pattern`, which
940    /// may contain wildcard characters `*` (match everything) and `?` (match one
941    /// character). If pattern is NULL, no filtering is done and all results are
942    /// returned. Subdirectories are permitted, and are specified with a path
943    /// separator of `/`. Wildcard characters `*` and `?` never match a path
944    /// separator.
945    ///
946    /// `flags` may be set to [`SDL_GLOB_CASEINSENSITIVE`] to make the pattern matching
947    /// case-insensitive.
948    ///
949    /// The returned array is always NULL-terminated, for your iterating
950    /// convenience, but if `count` is non-NULL, on return it will contain the
951    /// number of items in the array, not counting the NULL terminator.
952    ///
953    /// ## Parameters
954    /// - `path`: the path of the directory to enumerate.
955    /// - `pattern`: the pattern that files in the directory must match. Can be
956    ///   NULL.
957    /// - `flags`: `SDL_GLOB_*` bitflags that affect this search.
958    /// - `count`: on return, will be set to the number of items in the returned
959    ///   array. Can be NULL.
960    ///
961    /// ## Return value
962    /// Returns an array of strings on success or NULL on failure; call
963    ///   [`SDL_GetError()`] for more information. This is a single allocation
964    ///   that should be freed with [`SDL_free()`] when it is no longer needed.
965    ///
966    /// ## Thread safety
967    /// It is safe to call this function from any thread.
968    ///
969    /// ## Availability
970    /// This function is available since SDL 3.2.0.
971    pub fn SDL_GlobDirectory(
972        path: *const ::core::ffi::c_char,
973        pattern: *const ::core::ffi::c_char,
974        flags: SDL_GlobFlags,
975        count: *mut ::core::ffi::c_int,
976    ) -> *mut *mut ::core::ffi::c_char;
977}
978
979unsafe extern "C" {
980    /// Get what the system believes is the "current working directory."
981    ///
982    /// For systems without a concept of a current working directory, this will
983    /// still attempt to provide something reasonable.
984    ///
985    /// SDL does not provide a means to _change_ the current working directory; for
986    /// platforms without this concept, this would cause surprises with file access
987    /// outside of SDL.
988    ///
989    /// The returned path is guaranteed to end with a path separator ('\\' on
990    /// Windows, '/' on most other platforms).
991    ///
992    /// ## Return value
993    /// Returns a UTF-8 string of the current working directory in
994    ///   platform-dependent notation. NULL if there's a problem. This
995    ///   should be freed with [`SDL_free()`] when it is no longer needed.
996    ///
997    /// ## Thread safety
998    /// It is safe to call this function from any thread.
999    ///
1000    /// ## Availability
1001    /// This function is available since SDL 3.2.0.
1002    pub fn SDL_GetCurrentDirectory() -> *mut ::core::ffi::c_char;
1003}
1004
1005#[cfg(doc)]
1006use crate::everything::*;