File: string.h

package info (click to toggle)
bird3 3.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,600 kB
  • sloc: ansic: 85,199; sh: 3,807; perl: 3,484; lex: 976; python: 726; makefile: 527; xml: 520; sed: 13
file content (126 lines) | stat: -rw-r--r-- 2,948 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/*
 *	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>
#include <string.h>
#include <strings.h>

#include "lib/resource.h"

int bsprintf(char *str, const char *fmt, ...);
int bvsprintf(char *str, const char *fmt, va_list args);
int bsnprintf(char *str, int size, const char *fmt, ...) ACCESS_WRITE(1, 2);
int bvsnprintf(char *str, int size, const char *fmt, va_list args) ACCESS_WRITE(1, 2);

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);
#define tmp_sprintf(...)    lp_sprintf(tmp_linpool, __VA_ARGS__)
#define tmp_vsprintf(...)   lp_vsprintf(tmp_linpool, __VA_ARGS__)

#define tmp_sprintf(...)  lp_sprintf(tmp_linpool, __VA_ARGS__)
#define tmp_vsprintf(...)  lp_vsprintf(tmp_linpool, __VA_ARGS__)

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);

u64 bstrtoul10(const char *str, char **end);
u64 bstrtoul16(const char *str, char **end);
byte bstrtobyte16(const char *str);

char *fmt_order(u64 value, uint decimals, u64 kb_threshold);

int bstrhextobin(const char *s, byte *b);
int bstrbintohex(const byte *b, size_t len, char *buf, size_t size, char delim) ACCESS_READ(1, 2) ACCESS_WRITE(3, 4);

int patmatch(const byte *pat, const byte *str);

static inline char *xbasename(const char *str)
{
  char *s = strrchr(str, '/');
  return s ? s+1 : (char *) str;
}

static inline char *
xstrdup(const char *c)
{
  size_t l = strlen(c) + 1;
  char *z = xmalloc(l);
  memcpy(z, c, l);
  return z;
}

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;
}

#define tmp_strdup(x) lp_strdup(tmp_linpool, (x))

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;
}

static inline char *
lp_strcat(linpool *lp, const char *s1, const char *s2)
{
  size_t l1 = strlen(s1);
  size_t l2 = strlen(s2);
  char *z = lp_allocu(lp, l1 + l2 + 1);
  memcpy(z, s1, l1);
  memcpy(z + l1, s2, l2 + 1);
  return z;
}

#define tmp_strcat(x, y) lp_strcat(tmp_linpool, (x), (y))

static inline void
memset32(void *D, u32 val, uint n)
{
  u32 *dst = D;
  uint i;

  for (i = 0; i < n; i++)
    dst[i] = val;
}

static inline int
bstrcmp(const char *s1, const char *s2)
{
  if (s1 && s2)
    return strcmp(s1, s2);
  else
    return !s2 - !s1;
}

static inline void *
bmemcpy(void *dest, const void *src, size_t n)
{
  if (n)
    return memcpy(dest, src, n);
  else
    return dest;
}

#define ROUTER_ID_64_LENGTH 23

#endif