Greenbone Vulnerability Management Libraries 22.32.0
strings.c File Reference

String utilities. More...

#include "strings.h"
#include <assert.h>
#include <glib.h>
Include dependency graph for strings.c:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define G_LOG_DOMAIN   "libgvm base"
 GLib log domain.

Functions

void gvm_append_string (gchar **var, const gchar *string)
 Append a string to a string variable.
void gvm_append_text (gchar **var, const gchar *string, gsize length)
 Append a string of a known length to a string variable.
void gvm_free_string_var (gchar **var)
 Free a string variable.
char * gvm_strip_space (char *string, char *end)
 "Strip" space and newline characters from either end of some memory.

Detailed Description

String utilities.

Definition in file strings.c.

Macro Definition Documentation

◆ G_LOG_DOMAIN

#define G_LOG_DOMAIN   "libgvm base"

GLib log domain.

Definition at line 20 of file strings.c.

Function Documentation

◆ gvm_append_string()

void gvm_append_string ( gchar ** var,
const gchar * string )

Append a string to a string variable.

When the variable is NULL store a copy of the given string in the variable.

When the variable already contains a string replace the string with a new string that is the concatenation of the two, freeing the old string. It is up to the caller to free the given string if it was dynamically allocated.

Parameters
[in]varThe address of a string variable, that is, a pointer to a string.
[in]stringThe string to append to the string in the variable.

Definition at line 36 of file strings.c.

37{
38 if (*var)
39 {
40 char *old = *var;
41 *var = g_strconcat (old, string, NULL);
42 g_free (old);
43 }
44 else
45 *var = g_strdup (string);
46}

Referenced by Ensure(), Ensure(), and Ensure().

Here is the caller graph for this function:

◆ gvm_append_text()

void gvm_append_text ( gchar ** var,
const gchar * string,
gsize length )

Append a string of a known length to a string variable.

When the variable is NULL store a copy of the given string in the variable.

When the variable already contains a string replace the string with a new string that is the concatenation of the two, freeing the old string. It is up to the caller to free the given string if it was dynamically allocated.

The string must be NULL terminated, and the given length must be the actual length of the string.

Parameters
[in]varThe address of a string variable, that is, a pointer to a string.
[in]stringThe string to append to the string in the variable.
[in]lengthThe length of string.

Definition at line 66 of file strings.c.

67{
68 if (*var)
69 {
70 char *old = *var;
71 *var = g_strconcat (old, string, NULL);
72 g_free (old);
73 }
74 else
75 *var = g_strndup (string, length);
76}

Referenced by append_to_credentials_password(), append_to_credentials_username(), Ensure(), Ensure(), Ensure(), and Ensure().

Here is the caller graph for this function:

◆ gvm_free_string_var()

void gvm_free_string_var ( gchar ** var)

Free a string variable.

Free the string in the variable and set the variable to NULL.

Parameters
[in]varThe address of a string variable, that is, a pointer to a string.

Definition at line 87 of file strings.c.

88{
89 g_free (*var);
90 *var = NULL;
91}

Referenced by Ensure(), and Ensure().

Here is the caller graph for this function:

◆ gvm_strip_space()

char * gvm_strip_space ( char * string,
char * end )

"Strip" space and newline characters from either end of some memory.

Return the given pointer moved forward past any spaces, replacing the first of any contiguous spaces at or before the end of the memory with a terminating NULL.

This is for use when string points into a static buffers.

Parameters
[in,out]stringThe start of the memory.
[in]endPointer to the byte after the end of the memory.
Returns
A new pointer into the string.

Definition at line 108 of file strings.c.

109{
110 assert (string <= end);
111 if (string >= end)
112 return string;
113 end--;
114 while (string[0] == ' ' || string[0] == '\n')
115 {
116 string++;
117 if (string >= end)
118 {
119 end[0] = '\0';
120 return end;
121 }
122 }
123
124 /* Here string is < end. */
125 if (end[0] == ' ' || end[0] == '\n')
126 {
127 end--;
128 while (end >= string && (end[0] == ' ' || end[0] == '\n'))
129 {
130 end--;
131 }
132 end[1] = '\0';
133 }
134 return string;
135}

Referenced by Ensure(), Ensure(), Ensure(), Ensure(), Ensure(), Ensure(), and Ensure().

Here is the caller graph for this function: