1 /* 2 * Get path to config dir/file. 3 * 4 * This file is part of mpv. 5 * 6 * mpv is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU Lesser General Public 8 * License as published by the Free Software Foundation; either 9 * version 2.1 of the License, or (at your option) any later version. 10 * 11 * mpv is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU Lesser General Public License for more details. 15 * 16 * You should have received a copy of the GNU Lesser General Public 17 * License along with mpv. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 20 #ifndef MPLAYER_PATH_H 21 #define MPLAYER_PATH_H 22 23 #include <stdbool.h> 24 #include "misc/bstr.h" 25 26 struct mpv_global; 27 struct MPOpts; 28 29 void mp_init_paths(struct mpv_global *global, struct MPOpts *opts); 30 31 // Search for the input filename in several paths. These include user and global 32 // config locations by default. Some platforms may implement additional platform 33 // related lookups (i.e.: OSX inside an application bundle). 34 char *mp_find_config_file(void *talloc_ctx, struct mpv_global *global, 35 const char *filename); 36 37 // Like mp_find_config_file(), but search only the local writable user config 38 // dir. Also, this returns a result even if the file does not exist. Calling 39 // it with filename="" is equivalent to retrieving the user config dir. 40 char *mp_find_user_config_file(void *talloc_ctx, struct mpv_global *global, 41 const char *filename); 42 43 // Find all instances of the given config file. Paths are returned in order 44 // from lowest to highest priority. filename can contain multiple names 45 // separated with '|', with the first having highest priority. 46 char **mp_find_all_config_files(void *talloc_ctx, struct mpv_global *global, 47 const char *filename); 48 49 // Normally returns a talloc_strdup'ed copy of the path, except for special 50 // paths starting with '~'. Used to allow the user explicitly reference a 51 // file from the user's home or mpv config directory. 52 char *mp_get_user_path(void *talloc_ctx, struct mpv_global *global, 53 const char *path); 54 55 // Return pointer to filename part of path 56 57 char *mp_basename(const char *path); 58 59 /* Return file extension, excluding the '.'. If root is not NULL, set it to the 60 * part of the path without extension. So: path == root + "." + extension 61 * Don't consider it a file extension if the only '.' is the first character. 62 * Return NULL if no extension and don't set *root in this case. 63 */ 64 char *mp_splitext(const char *path, bstr *root); 65 66 /* Return struct bstr referencing directory part of path, or if that 67 * would be empty, ".". 68 */ 69 struct bstr mp_dirname(const char *path); 70 71 void mp_path_strip_trailing_separator(char *path); 72 73 /* Join two path components and return a newly allocated string 74 * for the result. '/' is inserted between the components if needed. 75 * If p2 is an absolute path then the value of p1 is ignored. 76 */ 77 char *mp_path_join(void *talloc_ctx, const char *p1, const char *p2); 78 char *mp_path_join_bstr(void *talloc_ctx, struct bstr p1, struct bstr p2); 79 80 // Return whether the path is absolute. 81 bool mp_path_is_absolute(struct bstr path); 82 83 char *mp_getcwd(void *talloc_ctx); 84 85 bool mp_path_exists(const char *path); 86 bool mp_path_isdir(const char *path); 87 88 bool mp_is_url(bstr path); 89 90 bstr mp_split_proto(bstr path, bstr *out_url); 91 92 void mp_mkdirp(const char *dir); 93 void mp_mk_config_dir(struct mpv_global *global, char *subdir); 94 95 #endif /* MPLAYER_PATH_H */ 96