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
23extern "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    /// **Nintendo 3DS Specific Functionality**: This function returns "romfs"
47    /// directory of the application as it is uncommon to store resources outside
48    /// the executable. As such it is not a writable directory.
49    ///
50    /// The returned path is guaranteed to end with a path separator ('\\' on
51    /// Windows, '/' on most other platforms).
52    ///
53    /// ### Return value
54    /// Returns an absolute path in UTF-8 encoding to the application data
55    ///   directory. NULL will be returned on error or when the platform
56    ///   doesn't implement this functionality, call [`SDL_GetError()`] for more
57    ///   information.
58    ///
59    /// ### Availability
60    /// This function is available since SDL 3.2.0.
61    ///
62    /// ### See also
63    /// - [`SDL_GetPrefPath`]
64    pub fn SDL_GetBasePath() -> *const ::core::ffi::c_char;
65}
66
67extern "C" {
68    /// Get the user-and-app-specific path where files can be written.
69    ///
70    /// Get the "pref dir". This is meant to be where users can write personal
71    /// files (preferences and save games, etc) that are specific to your
72    /// application. This directory is unique per user, per application.
73    ///
74    /// This function will decide the appropriate location in the native
75    /// filesystem, create the directory if necessary, and return a string of the
76    /// absolute path to the directory in UTF-8 encoding.
77    ///
78    /// On Windows, the string might look like:
79    ///
80    /// `C:\\Users\\bob\\AppData\\Roaming\\My Company\\My Program Name\\`
81    ///
82    /// On Linux, the string might look like:
83    ///
84    /// `/home/bob/.local/share/My Program Name/`
85    ///
86    /// On macOS, the string might look like:
87    ///
88    /// `/Users/bob/Library/Application Support/My Program Name/`
89    ///
90    /// You should assume the path returned by this function is the only safe place
91    /// to write files (and that [`SDL_GetBasePath()`], while it might be writable, or
92    /// even the parent of the returned path, isn't where you should be writing
93    /// things).
94    ///
95    /// Both the org and app strings may become part of a directory name, so please
96    /// follow these rules:
97    ///
98    /// - Try to use the same org string (_including case-sensitivity_) for all
99    ///   your applications that use this function.
100    /// - Always use a unique app string for each one, and make sure it never
101    ///   changes for an app once you've decided on it.
102    /// - Unicode characters are legal, as long as they are UTF-8 encoded, but...
103    /// - ...only use letters, numbers, and spaces. Avoid punctuation like "Game
104    ///   Name 2: Bad Guy's Revenge!" ... "Game Name 2" is sufficient.
105    ///
106    /// The returned path is guaranteed to end with a path separator ('\\' on
107    /// Windows, '/' on most other platforms).
108    ///
109    /// ### Parameters
110    /// - `org`: the name of your organization.
111    /// - `app`: the name of your application.
112    ///
113    /// ### Return value
114    /// Returns a UTF-8 string of the user directory in platform-dependent
115    ///   notation. NULL if there's a problem (creating directory failed,
116    ///   etc.). This should be freed with [`SDL_free()`] when it is no longer
117    ///   needed.
118    ///
119    /// ### Availability
120    /// This function is available since SDL 3.2.0.
121    ///
122    /// ### See also
123    /// - [`SDL_GetBasePath`]
124    pub fn SDL_GetPrefPath(
125        org: *const ::core::ffi::c_char,
126        app: *const ::core::ffi::c_char,
127    ) -> *mut ::core::ffi::c_char;
128}
129
130/// The type of the OS-provided default folder for a specific purpose.
131///
132/// Note that the Trash folder isn't included here, because trashing files
133/// usually involves extra OS-specific functionality to remember the file's
134/// original location.
135///
136/// The folders supported per platform are:
137///
138/// |             | Windows | macOS/iOS | tvOS | Unix (XDG) | Haiku | Emscripten |
139/// | ----------- | ------- | --------- | ---- | ---------- | ----- | ---------- |
140/// | HOME        | X       | X         |      | X          | X     | X          |
141/// | DESKTOP     | X       | X         |      | X          | X     |            |
142/// | DOCUMENTS   | X       | X         |      | X          |       |            |
143/// | DOWNLOADS   | Vista+  | X         |      | X          |       |            |
144/// | MUSIC       | X       | X         |      | X          |       |            |
145/// | PICTURES    | X       | X         |      | X          |       |            |
146/// | PUBLICSHARE |         | X         |      | X          |       |            |
147/// | SAVEDGAMES  | Vista+  |           |      |            |       |            |
148/// | SCREENSHOTS | Vista+  |           |      |            |       |            |
149/// | TEMPLATES   | X       | X         |      | X          |       |            |
150/// | VIDEOS      | X       | X*        |      | X          |       |            |
151///
152/// Note that on macOS/iOS, the Videos folder is called "Movies".
153///
154/// ### Availability
155/// This enum is available since SDL 3.2.0.
156///
157/// ### See also
158/// - [`SDL_GetUserFolder`]
159///
160/// ### Known values (`sdl3-sys`)
161/// | Associated constant | Global constant | Description |
162/// | ------------------- | --------------- | ----------- |
163/// | [`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. |
164/// | [`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. |
165/// | [`DOCUMENTS`](SDL_Folder::DOCUMENTS) | [`SDL_FOLDER_DOCUMENTS`] | User document files, possibly application-specific. This is a good place to save a user's projects. |
166/// | [`DOWNLOADS`](SDL_Folder::DOWNLOADS) | [`SDL_FOLDER_DOWNLOADS`] | Standard folder for user files downloaded from the internet. |
167/// | [`MUSIC`](SDL_Folder::MUSIC) | [`SDL_FOLDER_MUSIC`] | Music files that can be played using a standard music player (mp3, ogg...). |
168/// | [`PICTURES`](SDL_Folder::PICTURES) | [`SDL_FOLDER_PICTURES`] | Image files that can be displayed using a standard viewer (png, jpg...). |
169/// | [`PUBLICSHARE`](SDL_Folder::PUBLICSHARE) | [`SDL_FOLDER_PUBLICSHARE`] | Files that are meant to be shared with other users on the same computer. |
170/// | [`SAVEDGAMES`](SDL_Folder::SAVEDGAMES) | [`SDL_FOLDER_SAVEDGAMES`] | Save files for games. |
171/// | [`SCREENSHOTS`](SDL_Folder::SCREENSHOTS) | [`SDL_FOLDER_SCREENSHOTS`] | Application screenshots. |
172/// | [`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. |
173/// | [`VIDEOS`](SDL_Folder::VIDEOS) | [`SDL_FOLDER_VIDEOS`] | Video files that can be played using a standard video player (mp4, webm...). |
174/// | [`COUNT`](SDL_Folder::COUNT) | [`SDL_FOLDER_COUNT`] | Total number of types in this enum, not a folder type by itself. |
175#[repr(transparent)]
176#[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
177pub struct SDL_Folder(pub ::core::ffi::c_int);
178
179impl From<SDL_Folder> for ::core::ffi::c_int {
180    #[inline(always)]
181    fn from(value: SDL_Folder) -> Self {
182        value.0
183    }
184}
185
186#[cfg(feature = "debug-impls")]
187impl ::core::fmt::Debug for SDL_Folder {
188    fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
189        #[allow(unreachable_patterns)]
190        f.write_str(match *self {
191            Self::HOME => "SDL_FOLDER_HOME",
192            Self::DESKTOP => "SDL_FOLDER_DESKTOP",
193            Self::DOCUMENTS => "SDL_FOLDER_DOCUMENTS",
194            Self::DOWNLOADS => "SDL_FOLDER_DOWNLOADS",
195            Self::MUSIC => "SDL_FOLDER_MUSIC",
196            Self::PICTURES => "SDL_FOLDER_PICTURES",
197            Self::PUBLICSHARE => "SDL_FOLDER_PUBLICSHARE",
198            Self::SAVEDGAMES => "SDL_FOLDER_SAVEDGAMES",
199            Self::SCREENSHOTS => "SDL_FOLDER_SCREENSHOTS",
200            Self::TEMPLATES => "SDL_FOLDER_TEMPLATES",
201            Self::VIDEOS => "SDL_FOLDER_VIDEOS",
202            Self::COUNT => "SDL_FOLDER_COUNT",
203
204            _ => return write!(f, "SDL_Folder({})", self.0),
205        })
206    }
207}
208
209impl SDL_Folder {
210    /// 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.
211    pub const HOME: Self = Self(0);
212    /// 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.
213    pub const DESKTOP: Self = Self(1);
214    /// User document files, possibly application-specific. This is a good place to save a user's projects.
215    pub const DOCUMENTS: Self = Self(2);
216    /// Standard folder for user files downloaded from the internet.
217    pub const DOWNLOADS: Self = Self(3);
218    /// Music files that can be played using a standard music player (mp3, ogg...).
219    pub const MUSIC: Self = Self(4);
220    /// Image files that can be displayed using a standard viewer (png, jpg...).
221    pub const PICTURES: Self = Self(5);
222    /// Files that are meant to be shared with other users on the same computer.
223    pub const PUBLICSHARE: Self = Self(6);
224    /// Save files for games.
225    pub const SAVEDGAMES: Self = Self(7);
226    /// Application screenshots.
227    pub const SCREENSHOTS: Self = Self(8);
228    /// 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.
229    pub const TEMPLATES: Self = Self(9);
230    /// Video files that can be played using a standard video player (mp4, webm...).
231    pub const VIDEOS: Self = Self(10);
232    /// Total number of types in this enum, not a folder type by itself.
233    pub const COUNT: Self = Self(11);
234}
235
236/// 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.
237pub const SDL_FOLDER_HOME: SDL_Folder = SDL_Folder::HOME;
238/// 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.
239pub const SDL_FOLDER_DESKTOP: SDL_Folder = SDL_Folder::DESKTOP;
240/// User document files, possibly application-specific. This is a good place to save a user's projects.
241pub const SDL_FOLDER_DOCUMENTS: SDL_Folder = SDL_Folder::DOCUMENTS;
242/// Standard folder for user files downloaded from the internet.
243pub const SDL_FOLDER_DOWNLOADS: SDL_Folder = SDL_Folder::DOWNLOADS;
244/// Music files that can be played using a standard music player (mp3, ogg...).
245pub const SDL_FOLDER_MUSIC: SDL_Folder = SDL_Folder::MUSIC;
246/// Image files that can be displayed using a standard viewer (png, jpg...).
247pub const SDL_FOLDER_PICTURES: SDL_Folder = SDL_Folder::PICTURES;
248/// Files that are meant to be shared with other users on the same computer.
249pub const SDL_FOLDER_PUBLICSHARE: SDL_Folder = SDL_Folder::PUBLICSHARE;
250/// Save files for games.
251pub const SDL_FOLDER_SAVEDGAMES: SDL_Folder = SDL_Folder::SAVEDGAMES;
252/// Application screenshots.
253pub const SDL_FOLDER_SCREENSHOTS: SDL_Folder = SDL_Folder::SCREENSHOTS;
254/// 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.
255pub const SDL_FOLDER_TEMPLATES: SDL_Folder = SDL_Folder::TEMPLATES;
256/// Video files that can be played using a standard video player (mp4, webm...).
257pub const SDL_FOLDER_VIDEOS: SDL_Folder = SDL_Folder::VIDEOS;
258/// Total number of types in this enum, not a folder type by itself.
259pub const SDL_FOLDER_COUNT: SDL_Folder = SDL_Folder::COUNT;
260
261extern "C" {
262    /// Finds the most suitable user folder for a specific purpose.
263    ///
264    /// Many OSes provide certain standard folders for certain purposes, such as
265    /// storing pictures, music or videos for a certain user. This function gives
266    /// the path for many of those special locations.
267    ///
268    /// This function is specifically for _user_ folders, which are meant for the
269    /// user to access and manage. For application-specific folders, meant to hold
270    /// data for the application to manage, see [`SDL_GetBasePath()`] and
271    /// [`SDL_GetPrefPath()`].
272    ///
273    /// The returned path is guaranteed to end with a path separator ('\\' on
274    /// Windows, '/' on most other platforms).
275    ///
276    /// If NULL is returned, the error may be obtained with [`SDL_GetError()`].
277    ///
278    /// ### Parameters
279    /// - `folder`: the type of folder to find.
280    ///
281    /// ### Return value
282    /// Returns either a null-terminated C string containing the full path to the
283    ///   folder, or NULL if an error happened.
284    ///
285    /// ### Availability
286    /// This function is available since SDL 3.2.0.
287    pub fn SDL_GetUserFolder(folder: SDL_Folder) -> *const ::core::ffi::c_char;
288}
289
290/// Types of filesystem entries.
291///
292/// Note that there may be other sorts of items on a filesystem: devices,
293/// symlinks, named pipes, etc. They are currently reported as
294/// [`SDL_PATHTYPE_OTHER`].
295///
296/// ### Availability
297/// This enum is available since SDL 3.2.0.
298///
299/// ### See also
300/// - [`SDL_PathInfo`]
301///
302/// ### Known values (`sdl3-sys`)
303/// | Associated constant | Global constant | Description |
304/// | ------------------- | --------------- | ----------- |
305/// | [`NONE`](SDL_PathType::NONE) | [`SDL_PATHTYPE_NONE`] | path does not exist |
306/// | [`FILE`](SDL_PathType::FILE) | [`SDL_PATHTYPE_FILE`] | a normal file |
307/// | [`DIRECTORY`](SDL_PathType::DIRECTORY) | [`SDL_PATHTYPE_DIRECTORY`] | a directory |
308/// | [`OTHER`](SDL_PathType::OTHER) | [`SDL_PATHTYPE_OTHER`] | something completely different like a device node (not a symlink, those are always followed) |
309#[repr(transparent)]
310#[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
311pub struct SDL_PathType(pub ::core::ffi::c_int);
312
313impl From<SDL_PathType> for ::core::ffi::c_int {
314    #[inline(always)]
315    fn from(value: SDL_PathType) -> Self {
316        value.0
317    }
318}
319
320#[cfg(feature = "debug-impls")]
321impl ::core::fmt::Debug for SDL_PathType {
322    fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
323        #[allow(unreachable_patterns)]
324        f.write_str(match *self {
325            Self::NONE => "SDL_PATHTYPE_NONE",
326            Self::FILE => "SDL_PATHTYPE_FILE",
327            Self::DIRECTORY => "SDL_PATHTYPE_DIRECTORY",
328            Self::OTHER => "SDL_PATHTYPE_OTHER",
329
330            _ => return write!(f, "SDL_PathType({})", self.0),
331        })
332    }
333}
334
335impl SDL_PathType {
336    /// path does not exist
337    pub const NONE: Self = Self(0);
338    /// a normal file
339    pub const FILE: Self = Self(1);
340    /// a directory
341    pub const DIRECTORY: Self = Self(2);
342    /// something completely different like a device node (not a symlink, those are always followed)
343    pub const OTHER: Self = Self(3);
344}
345
346/// path does not exist
347pub const SDL_PATHTYPE_NONE: SDL_PathType = SDL_PathType::NONE;
348/// a normal file
349pub const SDL_PATHTYPE_FILE: SDL_PathType = SDL_PathType::FILE;
350/// a directory
351pub const SDL_PATHTYPE_DIRECTORY: SDL_PathType = SDL_PathType::DIRECTORY;
352/// something completely different like a device node (not a symlink, those are always followed)
353pub const SDL_PATHTYPE_OTHER: SDL_PathType = SDL_PathType::OTHER;
354
355/// Information about a path on the filesystem.
356///
357/// ### Availability
358/// This datatype is available since SDL 3.2.0.
359///
360/// ### See also
361/// - [`SDL_GetPathInfo`]
362/// - [`SDL_GetStoragePathInfo`]
363#[repr(C)]
364#[derive(Clone, Copy, Default, PartialEq, Eq, Hash)]
365#[cfg_attr(feature = "debug-impls", derive(Debug))]
366pub struct SDL_PathInfo {
367    /// the path type
368    pub r#type: SDL_PathType,
369    /// the file size in bytes
370    pub size: Uint64,
371    /// the time when the path was created
372    pub create_time: SDL_Time,
373    /// the last time the path was modified
374    pub modify_time: SDL_Time,
375    /// the last time the path was read
376    pub access_time: SDL_Time,
377}
378
379/// Flags for path matching.
380///
381/// ### Availability
382/// This datatype is available since SDL 3.2.0.
383///
384/// ### See also
385/// - [`SDL_GlobDirectory`]
386/// - [`SDL_GlobStorageDirectory`]
387///
388/// ### Known values (`sdl3-sys`)
389/// | Constant | Description |
390/// | -------- | ----------- |
391/// | [`SDL_GLOB_CASEINSENSITIVE`] | |
392pub type SDL_GlobFlags = Uint32;
393
394pub const SDL_GLOB_CASEINSENSITIVE: SDL_GlobFlags = ((1_u32) as SDL_GlobFlags);
395
396extern "C" {
397    /// Create a directory, and any missing parent directories.
398    ///
399    /// This reports success if `path` already exists as a directory.
400    ///
401    /// If parent directories are missing, it will also create them. Note that if
402    /// this fails, it will not remove any parent directories it already made.
403    ///
404    /// ### Parameters
405    /// - `path`: the path of the directory to create.
406    ///
407    /// ### Return value
408    /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
409    ///   information.
410    ///
411    /// ### Availability
412    /// This function is available since SDL 3.2.0.
413    pub fn SDL_CreateDirectory(path: *const ::core::ffi::c_char) -> ::core::primitive::bool;
414}
415
416/// Possible results from an enumeration callback.
417///
418/// ### Availability
419/// This enum is available since SDL 3.2.0.
420///
421/// ### See also
422/// - [`SDL_EnumerateDirectoryCallback`]
423///
424/// ### Known values (`sdl3-sys`)
425/// | Associated constant | Global constant | Description |
426/// | ------------------- | --------------- | ----------- |
427/// | [`CONTINUE`](SDL_EnumerationResult::CONTINUE) | [`SDL_ENUM_CONTINUE`] | Value that requests that enumeration continue. |
428/// | [`SUCCESS`](SDL_EnumerationResult::SUCCESS) | [`SDL_ENUM_SUCCESS`] | Value that requests that enumeration stop, successfully. |
429/// | [`FAILURE`](SDL_EnumerationResult::FAILURE) | [`SDL_ENUM_FAILURE`] | Value that requests that enumeration stop, as a failure. |
430#[repr(transparent)]
431#[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
432pub struct SDL_EnumerationResult(pub ::core::ffi::c_int);
433
434impl From<SDL_EnumerationResult> for ::core::ffi::c_int {
435    #[inline(always)]
436    fn from(value: SDL_EnumerationResult) -> Self {
437        value.0
438    }
439}
440
441#[cfg(feature = "debug-impls")]
442impl ::core::fmt::Debug for SDL_EnumerationResult {
443    fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
444        #[allow(unreachable_patterns)]
445        f.write_str(match *self {
446            Self::CONTINUE => "SDL_ENUM_CONTINUE",
447            Self::SUCCESS => "SDL_ENUM_SUCCESS",
448            Self::FAILURE => "SDL_ENUM_FAILURE",
449
450            _ => return write!(f, "SDL_EnumerationResult({})", self.0),
451        })
452    }
453}
454
455impl SDL_EnumerationResult {
456    /// Value that requests that enumeration continue.
457    pub const CONTINUE: Self = Self(0);
458    /// Value that requests that enumeration stop, successfully.
459    pub const SUCCESS: Self = Self(1);
460    /// Value that requests that enumeration stop, as a failure.
461    pub const FAILURE: Self = Self(2);
462}
463
464/// Value that requests that enumeration continue.
465pub const SDL_ENUM_CONTINUE: SDL_EnumerationResult = SDL_EnumerationResult::CONTINUE;
466/// Value that requests that enumeration stop, successfully.
467pub const SDL_ENUM_SUCCESS: SDL_EnumerationResult = SDL_EnumerationResult::SUCCESS;
468/// Value that requests that enumeration stop, as a failure.
469pub const SDL_ENUM_FAILURE: SDL_EnumerationResult = SDL_EnumerationResult::FAILURE;
470
471/// Callback for directory enumeration.
472///
473/// Enumeration of directory entries will continue until either all entries
474/// have been provided to the callback, or the callback has requested a stop
475/// through its return value.
476///
477/// Returning [`SDL_ENUM_CONTINUE`] will let enumeration proceed, calling the
478/// callback with further entries. [`SDL_ENUM_SUCCESS`] and [`SDL_ENUM_FAILURE`] will
479/// terminate the enumeration early, and dictate the return value of the
480/// enumeration function itself.
481///
482/// `dirname` is guaranteed to end with a path separator ('\\' on Windows, '/'
483/// on most other platforms).
484///
485/// ### Parameters
486/// - `userdata`: an app-controlled pointer that is passed to the callback.
487/// - `dirname`: the directory that is being enumerated.
488/// - `fname`: the next entry in the enumeration.
489///
490/// ### Return value
491/// Returns how the enumeration should proceed.
492///
493/// ### Availability
494/// This datatype is available since SDL 3.2.0.
495///
496/// ### See also
497/// - [`SDL_EnumerateDirectory`]
498pub type SDL_EnumerateDirectoryCallback = ::core::option::Option<
499    unsafe extern "C" fn(
500        userdata: *mut ::core::ffi::c_void,
501        dirname: *const ::core::ffi::c_char,
502        fname: *const ::core::ffi::c_char,
503    ) -> SDL_EnumerationResult,
504>;
505
506extern "C" {
507    /// Enumerate a directory through a callback function.
508    ///
509    /// This function provides every directory entry through an app-provided
510    /// callback, called once for each directory entry, until all results have been
511    /// provided or the callback returns either [`SDL_ENUM_SUCCESS`] or
512    /// [`SDL_ENUM_FAILURE`].
513    ///
514    /// This will return false if there was a system problem in general, or if a
515    /// callback returns [`SDL_ENUM_FAILURE`]. A successful return means a callback
516    /// returned [`SDL_ENUM_SUCCESS`] to halt enumeration, or all directory entries
517    /// were enumerated.
518    ///
519    /// ### Parameters
520    /// - `path`: the path of the directory to enumerate.
521    /// - `callback`: a function that is called for each entry in the directory.
522    /// - `userdata`: a pointer that is passed to `callback`.
523    ///
524    /// ### Return value
525    /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
526    ///   information.
527    ///
528    /// ### Availability
529    /// This function is available since SDL 3.2.0.
530    pub fn SDL_EnumerateDirectory(
531        path: *const ::core::ffi::c_char,
532        callback: SDL_EnumerateDirectoryCallback,
533        userdata: *mut ::core::ffi::c_void,
534    ) -> ::core::primitive::bool;
535}
536
537extern "C" {
538    /// Remove a file or an empty directory.
539    ///
540    /// Directories that are not empty will fail; this function will not recursely
541    /// delete directory trees.
542    ///
543    /// ### Parameters
544    /// - `path`: the path to remove from the filesystem.
545    ///
546    /// ### Return value
547    /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
548    ///   information.
549    ///
550    /// ### Availability
551    /// This function is available since SDL 3.2.0.
552    pub fn SDL_RemovePath(path: *const ::core::ffi::c_char) -> ::core::primitive::bool;
553}
554
555extern "C" {
556    /// Rename a file or directory.
557    ///
558    /// If the file at `newpath` already exists, it will replaced.
559    ///
560    /// Note that this will not copy files across filesystems/drives/volumes, as
561    /// that is a much more complicated (and possibly time-consuming) operation.
562    ///
563    /// Which is to say, if this function fails, [`SDL_CopyFile()`] to a temporary file
564    /// in the same directory as `newpath`, then [`SDL_RenamePath()`] from the
565    /// temporary file to `newpath` and [`SDL_RemovePath()`] on `oldpath` might work
566    /// for files. Renaming a non-empty directory across filesystems is
567    /// dramatically more complex, however.
568    ///
569    /// ### Parameters
570    /// - `oldpath`: the old path.
571    /// - `newpath`: the new path.
572    ///
573    /// ### Return value
574    /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
575    ///   information.
576    ///
577    /// ### Availability
578    /// This function is available since SDL 3.2.0.
579    pub fn SDL_RenamePath(
580        oldpath: *const ::core::ffi::c_char,
581        newpath: *const ::core::ffi::c_char,
582    ) -> ::core::primitive::bool;
583}
584
585extern "C" {
586    /// Copy a file.
587    ///
588    /// If the file at `newpath` already exists, it will be overwritten with the
589    /// contents of the file at `oldpath`.
590    ///
591    /// This function will block until the copy is complete, which might be a
592    /// significant time for large files on slow disks. On some platforms, the copy
593    /// can be handed off to the OS itself, but on others SDL might just open both
594    /// paths, and read from one and write to the other.
595    ///
596    /// Note that this is not an atomic operation! If something tries to read from
597    /// `newpath` while the copy is in progress, it will see an incomplete copy of
598    /// the data, and if the calling thread terminates (or the power goes out)
599    /// during the copy, `newpath`'s previous contents will be gone, replaced with
600    /// an incomplete copy of the data. To avoid this risk, it is recommended that
601    /// the app copy to a temporary file in the same directory as `newpath`, and if
602    /// the copy is successful, use [`SDL_RenamePath()`] to replace `newpath` with the
603    /// temporary file. This will ensure that reads of `newpath` will either see a
604    /// complete copy of the data, or it will see the pre-copy state of `newpath`.
605    ///
606    /// This function attempts to synchronize the newly-copied data to disk before
607    /// returning, if the platform allows it, so that the renaming trick will not
608    /// have a problem in a system crash or power failure, where the file could be
609    /// renamed but the contents never made it from the system file cache to the
610    /// physical disk.
611    ///
612    /// If the copy fails for any reason, the state of `newpath` is undefined. It
613    /// might be half a copy, it might be the untouched data of what was already
614    /// there, or it might be a zero-byte file, etc.
615    ///
616    /// ### Parameters
617    /// - `oldpath`: the old path.
618    /// - `newpath`: the new path.
619    ///
620    /// ### Return value
621    /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
622    ///   information.
623    ///
624    /// ### Availability
625    /// This function is available since SDL 3.2.0.
626    pub fn SDL_CopyFile(
627        oldpath: *const ::core::ffi::c_char,
628        newpath: *const ::core::ffi::c_char,
629    ) -> ::core::primitive::bool;
630}
631
632extern "C" {
633    /// Get information about a filesystem path.
634    ///
635    /// ### Parameters
636    /// - `path`: the path to query.
637    /// - `info`: a pointer filled in with information about the path, or NULL to
638    ///   check for the existence of a file.
639    ///
640    /// ### Return value
641    /// Returns true on success or false if the file doesn't exist, or another
642    ///   failure; call [`SDL_GetError()`] for more information.
643    ///
644    /// ### Availability
645    /// This function is available since SDL 3.2.0.
646    pub fn SDL_GetPathInfo(
647        path: *const ::core::ffi::c_char,
648        info: *mut SDL_PathInfo,
649    ) -> ::core::primitive::bool;
650}
651
652extern "C" {
653    /// Enumerate a directory tree, filtered by pattern, and return a list.
654    ///
655    /// Files are filtered out if they don't match the string in `pattern`, which
656    /// may contain wildcard characters '\*' (match everything) and '?' (match one
657    /// character). If pattern is NULL, no filtering is done and all results are
658    /// returned. Subdirectories are permitted, and are specified with a path
659    /// separator of '/'. Wildcard characters '\*' and '?' never match a path
660    /// separator.
661    ///
662    /// `flags` may be set to [`SDL_GLOB_CASEINSENSITIVE`] to make the pattern matching
663    /// case-insensitive.
664    ///
665    /// The returned array is always NULL-terminated, for your iterating
666    /// convenience, but if `count` is non-NULL, on return it will contain the
667    /// number of items in the array, not counting the NULL terminator.
668    ///
669    /// ### Parameters
670    /// - `path`: the path of the directory to enumerate.
671    /// - `pattern`: the pattern that files in the directory must match. Can be
672    ///   NULL.
673    /// - `flags`: `SDL_GLOB_*` bitflags that affect this search.
674    /// - `count`: on return, will be set to the number of items in the returned
675    ///   array. Can be NULL.
676    ///
677    /// ### Return value
678    /// Returns an array of strings on success or NULL on failure; call
679    ///   [`SDL_GetError()`] for more information. This is a single allocation
680    ///   that should be freed with [`SDL_free()`] when it is no longer needed.
681    ///
682    /// ### Thread safety
683    /// It is safe to call this function from any thread.
684    ///
685    /// ### Availability
686    /// This function is available since SDL 3.2.0.
687    pub fn SDL_GlobDirectory(
688        path: *const ::core::ffi::c_char,
689        pattern: *const ::core::ffi::c_char,
690        flags: SDL_GlobFlags,
691        count: *mut ::core::ffi::c_int,
692    ) -> *mut *mut ::core::ffi::c_char;
693}
694
695extern "C" {
696    /// Get what the system believes is the "current working directory."
697    ///
698    /// For systems without a concept of a current working directory, this will
699    /// still attempt to provide something reasonable.
700    ///
701    /// SDL does not provide a means to _change_ the current working directory; for
702    /// platforms without this concept, this would cause surprises with file access
703    /// outside of SDL.
704    ///
705    /// The returned path is guaranteed to end with a path separator ('\\' on
706    /// Windows, '/' on most other platforms).
707    ///
708    /// ### Return value
709    /// Returns a UTF-8 string of the current working directory in
710    ///   platform-dependent notation. NULL if there's a problem. This
711    ///   should be freed with [`SDL_free()`] when it is no longer needed.
712    ///
713    /// ### Availability
714    /// This function is available since SDL 3.2.0.
715    pub fn SDL_GetCurrentDirectory() -> *mut ::core::ffi::c_char;
716}
717
718#[cfg(doc)]
719use crate::everything::*;