1 /* Copyright (C) 2010-2020 The RetroArch team
3 * ---------------------------------------------------------------------------------------
4 * The following license statement only applies to this file (m3u_file.h).
5 * ---------------------------------------------------------------------------------------
7 * Permission is hereby granted, free of charge,
8 * to any person obtaining a copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation the rights to
10 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
11 * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
16 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
19 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 #ifndef __LIBRETRO_SDK_FORMAT_M3U_FILE_H__
24 #define __LIBRETRO_SDK_FORMAT_M3U_FILE_H__
26 #include <retro_common_api.h>
34 /* Trivial handler for M3U playlist files */
36 /* M3U file extension */
37 #define M3U_FILE_EXT "m3u"
39 /* Prevent direct access to m3u_file_t members */
40 typedef struct content_m3u_file m3u_file_t;
42 /* Holds all metadata for a single M3U file entry */
50 /* Defines entry label formatting when
51 * writing M3U files to disk */
52 enum m3u_file_label_type
54 M3U_FILE_LABEL_NONE = 0,
55 M3U_FILE_LABEL_NONSTD,
56 M3U_FILE_LABEL_EXTSTD,
60 /* File Initialisation / De-Initialisation */
62 /* Creates and initialises an M3U file
63 * - If 'path' refers to an existing file,
65 * - If path does not exist, an empty M3U file
67 * - Returned m3u_file_t object must be free'd using
69 * - Returns NULL in the event of an error */
70 m3u_file_t *m3u_file_init(const char *path);
72 /* Frees specified M3U file */
73 void m3u_file_free(m3u_file_t *m3u_file);
77 /* Returns M3U file path */
78 char *m3u_file_get_path(m3u_file_t *m3u_file);
80 /* Returns number of entries in M3U file */
81 size_t m3u_file_get_size(m3u_file_t *m3u_file);
83 /* Fetches specified M3U file entry
84 * - Returns false if 'idx' is invalid, or internal
86 bool m3u_file_get_entry(
87 m3u_file_t *m3u_file, size_t idx, m3u_file_entry_t **entry);
91 /* Adds specified entry to the M3U file
92 * - Returns false if path is invalid, or
93 * memory could not be allocated for the
95 bool m3u_file_add_entry(
96 m3u_file_t *m3u_file, const char *path, const char *label);
98 /* Removes all entries in M3U file */
99 void m3u_file_clear(m3u_file_t *m3u_file);
103 /* Saves M3U file to disk
104 * - Setting 'label_type' to M3U_FILE_LABEL_NONE
105 * just outputs entry paths - this the most
106 * common format supported by most cores
107 * - Returns false in the event of an error */
109 m3u_file_t *m3u_file, enum m3u_file_label_type label_type);
113 /* Sorts M3U file entries in alphabetical order */
114 void m3u_file_qsort(m3u_file_t *m3u_file);
116 /* Returns true if specified path corresponds
117 * to an M3U file (simple convenience function) */
118 bool m3u_file_is_m3u(const char *path);