A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita audio rust zig deno mpris rockbox mpd
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

at master 77 lines 2.8 kB view raw
1/*************************************************************************** 2 * __________ __ ___. 3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___ 4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / 5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < 6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ 7 * \/ \/ \/ \/ \/ 8 * $Id$ 9 * 10 * Copyright (C) 2022 by William WIlgus 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#include "config.h" 22 23#include <stddef.h> 24#include <string.h> 25#include "strtok_r.h" 26/* strptokspn_r is a custom implementation of strtok_r that does NOT modify 27 * the source string. 28 * 29 * strptokspn_r reads ptr as a series of zero or more tokens, 30 * and sep as delimiters of the tokens 31 * The tokens can be separated by one or more of the delimiters 32 * first call searches for the first token skipping over any leading delimiters. 33 * Returns pointer to first token 34 * Pointer *len contains the span to the first delimeter 35 * (this would be the resulting strlen had token actually been NULL terminated) 36 * Pointer **end contains pointer to first character after the last delimeter 37 * 38 * When strptokspn_r is called with a ptr == NULL, the next token is read from 39 * Pointer **end 40 * 41 * Note the returned token is NOT NULL terminated by the function as in strtok_r 42 * However the caller can use ret[len] = '\0'; to emulate a call to strtok_r 43*/ 44const char *strptokspn_r(const char *ptr, const char *sep, size_t *len, const char **end) 45{ 46 if (ptr == NULL) /* we got NULL input so then we get last position instead */ 47 { 48 ptr = *end; 49 } 50 51 /* pass all letters that are including in the separator string */ 52 while (*ptr && strchr(sep, *ptr)) 53 ++ptr; 54 55 if (*ptr != '\0') 56 { 57 /* so this is where the next piece of string starts */ 58 const char *start = ptr; 59 *len = strcspn(ptr, sep); /* Get span until any sep character in string */ 60 *end = ptr + *len; 61 if (**end) /* the end is not a null byte */ 62 ++*end; 63 return start; 64 } 65 return NULL; 66} 67 68#if !defined(HAVE_STRTOK_R) 69char * strtok_r(char *ptr, const char *sep, char **end) 70{ 71 size_t len; 72 char * ret = (char*) strptokspn_r((const char*)ptr, sep, &len, (const char**) end); 73 if (ret) 74 ret[len] = '\0'; 75 return ret; 76} 77#endif