Flowgrind
Advanced TCP traffic generator
fg_string.h File Reference

Functions to manipulate strings used by Flowgrind. More...

#include "config.h"

Go to the source code of this file.

Functions

int asprintf_append (char **resultp, const char *fmt,...) __attribute__((format(printf
 Realloc resultp to append the formatted result of fmt and return a pointer to it via the first argument. More...
 
size_t fmtlen (char const *fmt, va_list ap)
 Determine the number of characters that would be generated by a printf with format string fmt and arguments ap. More...
 
char * strdup_append (char *s, const char *a)
 Append the duplication of string a to the given string s. More...
 
char * strndup_append (char *s, const char *a, size_t n)
 Append at most n characters of the duplication of string a to the given string s. More...
 
int int vasprintf_append (char **resultp, const char *fmt, va_list ap) __attribute__((format(printf
 Realloc resultp to append the formatted result of fmt and ap and return a pointer to it via the first argument. More...
 

Detailed Description

Functions to manipulate strings used by Flowgrind.

Definition in file fg_string.h.

Function Documentation

int asprintf_append ( char **  resultp,
const char *  fmt,
  ... 
)

Realloc resultp to append the formatted result of fmt and return a pointer to it via the first argument.

Good for gradually accumulating output into a string buffer. Appends at the end of the string

Parameters
[in,out]resultpdestination string to append to
[in]fmtformat string
[in]...parameters used to fill fmt
Returns
return the number of bytes printed for success, or -1 for failure
size_t fmtlen ( char const *  fmt,
va_list  ap 
)

Determine the number of characters that would be generated by a printf with format string fmt and arguments ap.

Parameters
[in]fmtformat string
[in]apparameters used to fill fmt
Returns
number of number of characters

Definition at line 61 of file fg_string.c.

62 {
63  va_list ap2;
64  char c;
65 
66  /* If the output of vsnprintf is truncated, its return value is the
67  * number of characters which would have been written to the string
68  * if enough space had been available */
69  va_copy(ap2, ap);
70  size_t length = vsnprintf(&c, 1, fmt, ap2);
71  va_end(ap2);
72 
73  return length;
74 }
char* strdup_append ( char *  s,
const char *  a 
)

Append the duplication of string a to the given string s.

Parameters
[in]sdestination string to append to
[in]asource string to be append
Returns
concatenated strings, NULL on error

Definition at line 76 of file fg_string.c.

77 {
78  if (unlikely(!s))
79  return strdup(a);
80 
81  if (unlikely(!a))
82  return s;
83 
84  return strlendup_append(s, strlen(s), a, strlen(a));
85 }
#define unlikely(x)
These macros gain us a few percent of speed.
static char * strlendup_append(char *s, size_t slen, const char *a, size_t alen)
Append the duplication of string a of length alen to the given string s at point slen.
Definition: fg_string.c:47
char* strndup_append ( char *  s,
const char *  a,
size_t  n 
)

Append at most n characters of the duplication of string a to the given string s.

Parameters
[in]sdestination string to append to
[in]asource string to be append
[in]nnumber of characters to be append from the string
Returns
concatenated strings, NULL on error

Definition at line 87 of file fg_string.c.

88 {
89  if (unlikely(!s))
90  return strdup(a);
91 
92  if (unlikely(!a))
93  return s;
94 
95  return strlendup_append(s, strlen(s), a, strnlen(a, n));
96 }
#define unlikely(x)
These macros gain us a few percent of speed.
static char * strlendup_append(char *s, size_t slen, const char *a, size_t alen)
Append the duplication of string a of length alen to the given string s at point slen.
Definition: fg_string.c:47
int int vasprintf_append ( char **  resultp,
const char *  fmt,
va_list  ap 
)

Realloc resultp to append the formatted result of fmt and ap and return a pointer to it via the first argument.

Good for gradually accumulating output into a string buffer. Appends at the end of the string.

Parameters
[in,out]resultpdestination string to append to
[in]fmtformat string
[in]apparameters used to fill fmt
Returns
return the number of bytes printed for success, or -1 for failure