18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci#ifndef _TOOLS_LINUX_STRING_H_ 38c2ecf20Sopenharmony_ci#define _TOOLS_LINUX_STRING_H_ 48c2ecf20Sopenharmony_ci 58c2ecf20Sopenharmony_ci#include <linux/types.h> /* for size_t */ 68c2ecf20Sopenharmony_ci#include <string.h> 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_civoid *memdup(const void *src, size_t len); 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_cichar **argv_split(const char *str, int *argcp); 118c2ecf20Sopenharmony_civoid argv_free(char **argv); 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ciint strtobool(const char *s, bool *res); 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_ci/* 168c2ecf20Sopenharmony_ci * glibc based builds needs the extern while uClibc doesn't. 178c2ecf20Sopenharmony_ci * However uClibc headers also define __GLIBC__ hence the hack below 188c2ecf20Sopenharmony_ci */ 198c2ecf20Sopenharmony_ci#if defined(__GLIBC__) && !defined(__UCLIBC__) 208c2ecf20Sopenharmony_ci// pragma diagnostic was introduced in gcc 4.6 218c2ecf20Sopenharmony_ci#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) 228c2ecf20Sopenharmony_ci#pragma GCC diagnostic push 238c2ecf20Sopenharmony_ci#pragma GCC diagnostic ignored "-Wredundant-decls" 248c2ecf20Sopenharmony_ci#endif 258c2ecf20Sopenharmony_ciextern size_t strlcpy(char *dest, const char *src, size_t size); 268c2ecf20Sopenharmony_ci#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) 278c2ecf20Sopenharmony_ci#pragma GCC diagnostic pop 288c2ecf20Sopenharmony_ci#endif 298c2ecf20Sopenharmony_ci#endif 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_cichar *str_error_r(int errnum, char *buf, size_t buflen); 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_cichar *strreplace(char *s, char old, char new); 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_ci/** 368c2ecf20Sopenharmony_ci * strstarts - does @str start with @prefix? 378c2ecf20Sopenharmony_ci * @str: string to examine 388c2ecf20Sopenharmony_ci * @prefix: prefix to look for. 398c2ecf20Sopenharmony_ci */ 408c2ecf20Sopenharmony_cistatic inline bool strstarts(const char *str, const char *prefix) 418c2ecf20Sopenharmony_ci{ 428c2ecf20Sopenharmony_ci return strncmp(str, prefix, strlen(prefix)) == 0; 438c2ecf20Sopenharmony_ci} 448c2ecf20Sopenharmony_ci 458c2ecf20Sopenharmony_ciextern char * __must_check skip_spaces(const char *); 468c2ecf20Sopenharmony_ci 478c2ecf20Sopenharmony_ciextern char *strim(char *); 488c2ecf20Sopenharmony_ci 498c2ecf20Sopenharmony_ciextern void *memchr_inv(const void *start, int c, size_t bytes); 508c2ecf20Sopenharmony_ci#endif /* _TOOLS_LINUX_STRING_H_ */ 51