]> git.ipfire.org Git - thirdparty/bird.git/blob - lib/string.h
75cb88ddc82e0c1dddbc579c8adc06dc2b25bf37
[thirdparty/bird.git] / lib / string.h
1 /*
2 * BIRD Library -- String Functions
3 *
4 * (c) 1998 Martin Mares <mj@ucw.cz>
5 *
6 * Can be freely distributed and used under the terms of the GNU GPL.
7 */
8
9 #ifndef _BIRD_STRING_H_
10 #define _BIRD_STRING_H_
11
12 #include <stdarg.h>
13 #include <string.h>
14 #include <strings.h>
15
16 int bsprintf(char *str, const char *fmt, ...);
17 int bvsprintf(char *str, const char *fmt, va_list args);
18 int bsnprintf(char *str, int size, const char *fmt, ...);
19 int bvsnprintf(char *str, int size, const char *fmt, va_list args);
20
21 int buffer_vprint(buffer *buf, const char *fmt, va_list args);
22 int buffer_print(buffer *buf, const char *fmt, ...);
23 void buffer_puts(buffer *buf, const char *str);
24
25 int patmatch(const byte *pat, const byte *str);
26
27 static inline char *xbasename(const char *str)
28 {
29 char *s = strrchr(str, '/');
30 return s ? s+1 : (char *) str;
31 }
32
33 static inline char *
34 xstrdup(const char *c)
35 {
36 size_t l = strlen(c) + 1;
37 char *z = xmalloc(l);
38 memcpy(z, c, l);
39 return z;
40 }
41
42 static inline void
43 memset32(void *D, u32 val, uint n)
44 {
45 u32 *dst = D;
46 uint i;
47
48 for (i = 0; i < n; i++)
49 dst[i] = val;
50 }
51
52 #define ROUTER_ID_64_LENGTH 23
53
54 #endif