A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita audio rust zig deno mpris rockbox mpd
at master 111 lines 4.1 kB view raw
1/*************************************************************************** 2 * __________ __ ___. 3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___ 4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / 5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < 6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ 7 * \/ \/ \/ \/ \/ 8 * $Id$ 9 * 10 * Copyright (C) 2014 by Michael Sevakis 11 * 12 * This program is free software; you can redistribute it and/or 13 * modify it under the terms of the GNU General Public License 14 * as published by the Free Software Foundation; either version 2 15 * of the License, or (at your option) any later version. 16 * 17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 18 * KIND, either express or implied. 19 * 20 ****************************************************************************/ 21#ifndef _PATHFUNCS_H_ 22#define _PATHFUNCS_H_ 23 24#include <sys/types.h> 25#define __need_size_t 26#include <stddef.h> 27#include <stdbool.h> 28#include "config.h" 29 30/* useful char constants that could be reconfigured if desired */ 31#define PATH_SEPCH '/' 32#define PATH_SEPSTR "/" 33#define PATH_ROOTCHR '/' 34#define PATH_ROOTSTR "/" 35#define PATH_BADSEPCH '\\' 36#define PATH_DRVSEPCH ':' 37 38#ifndef ROOT_VOLUME 39#define ROOT_VOLUME INT_MAX 40#endif 41 42/* a nicer way to check for "." and ".." than two strcmp() calls */ 43static inline bool is_dotdir_name(const char *name) 44{ 45 return name[0] == '.' && (!name[1] || (name[1] == '.' && !name[2])); 46} 47 48static inline bool name_is_dot(const char *name) 49{ 50 return name[0] == '.' && !name[1]; 51} 52 53static inline bool name_is_dot_dot(const char *name) 54{ 55 return name[0] == '.' && name[1] == '.' && !name[2]; 56} 57 58/* return a pointer to the character following path separators */ 59#define GOBBLE_PATH_SEPCH(p) \ 60 ({ int _c; \ 61 const char *_p = (p); \ 62 while ((_c = *_p) == PATH_SEPCH) \ 63 ++_p; \ 64 _p; }) 65 66/* return a pointer to the character following a path component which may 67 be a separator or the terminating nul */ 68#define GOBBLE_PATH_COMP(p) \ 69 ({ int _c; \ 70 const char *_p = (p); \ 71 while ((_c = *_p) && _c != PATH_SEPCH) \ 72 ++_p; \ 73 _p; }) 74 75/* does the character terminate a path component? */ 76#define IS_COMP_TERMINATOR(c) \ 77 ({ int _c = (c); \ 78 !_c || _c == PATH_SEPCH; }) 79 80#ifdef HAVE_MULTIVOLUME 81int path_strip_volume(const char *name, const char **nameptr, bool greedy); 82int path_strip_last_volume(const char *name, const char **nameptr, bool greedy); 83int get_volume_name(int volume, char *name); 84int make_volume_root(int volume, char *dst); 85void init_volume_names(void); 86int path_get_volume_id(const char *name); 87#endif 88 89int path_strip_drive(const char *name, const char **nameptr, bool greedy); 90size_t path_basename(const char *name, const char **nameptr); 91size_t path_dirname(const char *name, const char **nameptr); 92size_t path_strip_trailing_separators(const char *name, const char **nameptr); 93void path_correct_separators(char *dstpath, const char *path); 94void path_remove_dot_segments(char *dstpath, const char *path); 95 96/* constants useable in basepath and component */ 97#define PA_SEP_HARD NULL /* separate even if base is empty */ 98#define PA_SEP_SOFT "" /* separate only if base is nonempty */ 99size_t path_append_ex(char *buf, const char *basepath, size_t basepath_max, 100 const char *component, size_t bufsize); 101size_t path_append(char *buffer, const char *basepath, const char *component, 102 size_t bufsize); 103ssize_t parse_path_component(const char **pathp, const char **namep); 104 105/* return true if path begins with a root '/' component and is not NULL */ 106static inline bool path_is_absolute(const char *path) 107{ 108 return path && path[0] == PATH_SEPCH; 109} 110 111#endif /* _PATHFUNCS_H_ */