1998-06-17 14:31:36 +00:00
|
|
|
/*
|
|
|
|
* BIRD Library -- String Functions
|
|
|
|
*
|
|
|
|
* (c) 1998 Martin Mares <mj@ucw.cz>
|
|
|
|
*
|
|
|
|
* Can be freely distributed and used under the terms of the GNU GPL.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _BIRD_STRING_H_
|
|
|
|
#define _BIRD_STRING_H_
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
2000-03-31 23:30:21 +00:00
|
|
|
#include <string.h>
|
2012-08-14 14:25:22 +00:00
|
|
|
#include <strings.h>
|
1998-06-17 14:31:36 +00:00
|
|
|
|
2016-11-16 11:10:34 +00:00
|
|
|
#include "lib/resource.h"
|
|
|
|
|
1998-06-17 14:31:36 +00:00
|
|
|
int bsprintf(char *str, const char *fmt, ...);
|
|
|
|
int bvsprintf(char *str, const char *fmt, va_list args);
|
1998-11-16 21:40:35 +00:00
|
|
|
int bsnprintf(char *str, int size, const char *fmt, ...);
|
|
|
|
int bvsnprintf(char *str, int size, const char *fmt, va_list args);
|
1998-06-17 14:31:36 +00:00
|
|
|
|
2022-03-15 10:21:46 +00:00
|
|
|
char *mb_sprintf(pool *p, const char *fmt, ...);
|
|
|
|
char *mb_vsprintf(pool *p, const char *fmt, va_list args);
|
|
|
|
char *lp_sprintf(linpool *p, const char *fmt, ...);
|
|
|
|
char *lp_vsprintf(linpool *p, const char *fmt, va_list args);
|
|
|
|
|
2024-10-02 20:32:07 +00:00
|
|
|
#define tmp_sprintf(...) lp_sprintf(tmp_linpool, __VA_ARGS__)
|
|
|
|
#define tmp_vsprintf(...) lp_vsprintf(tmp_linpool, __VA_ARGS__)
|
|
|
|
|
2013-10-05 18:12:28 +00:00
|
|
|
int buffer_vprint(buffer *buf, const char *fmt, va_list args);
|
|
|
|
int buffer_print(buffer *buf, const char *fmt, ...);
|
|
|
|
void buffer_puts(buffer *buf, const char *str);
|
|
|
|
|
2019-02-25 22:28:36 +00:00
|
|
|
u64 bstrtoul10(const char *str, char **end);
|
|
|
|
u64 bstrtoul16(const char *str, char **end);
|
2021-04-14 19:39:43 +00:00
|
|
|
byte bstrtobyte16(const char *str);
|
2019-02-25 22:28:36 +00:00
|
|
|
|
2023-08-24 01:04:58 +00:00
|
|
|
int bstrhextobin(const char *s, byte *b);
|
|
|
|
int bstrbintohex(const byte *b, size_t len, char *buf, size_t size, char delim);
|
|
|
|
|
2015-11-24 12:52:26 +00:00
|
|
|
int patmatch(const byte *pat, const byte *str);
|
1998-11-29 14:47:24 +00:00
|
|
|
|
2016-04-07 10:20:45 +00:00
|
|
|
static inline char *xbasename(const char *str)
|
|
|
|
{
|
|
|
|
char *s = strrchr(str, '/');
|
|
|
|
return s ? s+1 : (char *) str;
|
|
|
|
}
|
|
|
|
|
2016-11-01 10:37:49 +00:00
|
|
|
static inline char *
|
|
|
|
xstrdup(const char *c)
|
|
|
|
{
|
|
|
|
size_t l = strlen(c) + 1;
|
|
|
|
char *z = xmalloc(l);
|
|
|
|
memcpy(z, c, l);
|
|
|
|
return z;
|
|
|
|
}
|
|
|
|
|
2016-11-16 11:10:34 +00:00
|
|
|
static inline char *
|
|
|
|
lp_strdup(linpool *lp, const char *c)
|
|
|
|
{
|
|
|
|
size_t l = strlen(c) + 1;
|
|
|
|
char *z = lp_allocu(lp, l);
|
|
|
|
memcpy(z, c, l);
|
|
|
|
return z;
|
|
|
|
}
|
|
|
|
|
2024-10-02 20:32:07 +00:00
|
|
|
#define tmp_strdup(x) lp_strdup(tmp_linpool, (x))
|
|
|
|
|
2024-09-04 18:34:54 +00:00
|
|
|
static inline char *
|
|
|
|
mb_strdup(pool *p, const char *c)
|
|
|
|
{
|
|
|
|
size_t l = strlen(c) + 1;
|
|
|
|
char *z = mb_alloc(p, l);
|
|
|
|
memcpy(z, c, l);
|
|
|
|
return z;
|
|
|
|
}
|
|
|
|
|
2016-10-26 14:07:45 +00:00
|
|
|
static inline void
|
|
|
|
memset32(void *D, u32 val, uint n)
|
|
|
|
{
|
|
|
|
u32 *dst = D;
|
|
|
|
uint i;
|
|
|
|
|
|
|
|
for (i = 0; i < n; i++)
|
|
|
|
dst[i] = val;
|
|
|
|
}
|
|
|
|
|
2019-07-22 23:52:18 +00:00
|
|
|
static inline int
|
|
|
|
bstrcmp(const char *s1, const char *s2)
|
|
|
|
{
|
|
|
|
if (s1 && s2)
|
|
|
|
return strcmp(s1, s2);
|
|
|
|
else
|
|
|
|
return !s2 - !s1;
|
|
|
|
}
|
|
|
|
|
2019-08-14 08:28:23 +00:00
|
|
|
static inline void *
|
|
|
|
bmemcpy(void *dest, const void *src, size_t n)
|
|
|
|
{
|
|
|
|
if (n)
|
|
|
|
return memcpy(dest, src, n);
|
|
|
|
else
|
|
|
|
return dest;
|
|
|
|
}
|
|
|
|
|
2016-04-28 16:01:40 +00:00
|
|
|
#define ROUTER_ID_64_LENGTH 23
|
|
|
|
|
1998-06-17 14:31:36 +00:00
|
|
|
#endif
|