A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita
audio
rust
zig
deno
mpris
rockbox
mpd
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2010 Thomas Martitz
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 STRING_EXTRA_H
22#define STRING_EXTRA_H
23#include <string.h>
24#include "strlcpy.h"
25#include "strlcat.h"
26#include "strcasecmp.h"
27#include "strcasestr.h"
28#include "strmemccpy.h"
29#include "strtok_r.h"
30#include "memset16.h"
31
32#if defined(WIN32) || defined(APPLICATION) \
33 || defined(__PCTOOL__) || defined(SIMULATOR)
34#ifndef mempcpy
35#define mempcpy __builtin_mempcpy
36#endif
37#endif
38
39/* copies a buffer of len bytes and null terminates it */
40static inline char * strmemcpy(char *dst, const char *src, size_t len)
41{
42 /* NOTE: for now, assumes valid parameters! */
43 *(char *)mempcpy(dst, src, len) = '\0';
44 return dst;
45}
46
47/* duplicate and null-terminate a memory block on the stack with alloca() */
48#define strmemdupa(s, l) \
49 ({ const char *___s = (s); \
50 size_t ___l = (l); \
51 char *___buf = alloca(___l + 1); \
52 strmemcpy(___buf, ___s, ___l); })
53
54/* strdupa and strndupa may already be provided by a system's string.h */
55
56#ifndef strdupa
57/* duplicate an entire string on the stack with alloca() */
58#define strdupa(s) \
59 ({ const char *__s = (s); \
60 strmemdupa((__s), strlen(__s)); })
61#endif /* strdupa */
62
63#ifndef strndupa
64/* duplicate a string on the stack with alloca(), truncating it if it is too
65 long */
66#define strndupa(s, n) \
67 ({ const char *__s = (s); \
68 size_t __n = (n); \
69 size_t __len = strlen(_s); \
70 strmemdupa(__s, MIN(__n, __len)); })
71#endif /* strndupa */
72
73char *itoa_buf(char *buf, size_t bufsz, long int i);
74
75#endif /* STRING_EXTRA_H */