OpenVPN
Functions
utils.c File Reference
#include <string.h>
#include <ctype.h>
#include <stdbool.h>
#include <stdlib.h>
#include <sys/types.h>
#include <stdint.h>
#include "utils.h"
Include dependency graph for utils.c:

Go to the source code of this file.

Functions

char * searchandreplace (const char *tosearch, const char *searchfor, const char *replacewith)
 Read 'tosearch', replace all occurrences of 'searchfor' with 'replacewith' and return a pointer to the NEW string. More...
 
const char * get_env (const char *name, const char *envp[])
 Given an environmental variable name, search the envp array for its value. More...
 
int string_array_len (const char *array[])
 Return the length of a string array. More...
 

Function Documentation

◆ get_env()

const char* get_env ( const char *  name,
const char *  envp[] 
)

Given an environmental variable name, search the envp array for its value.

Parameters
nameEnvironment variable to look up
envpEnvironment variable table with all key/value pairs
Returns
Returns a pointer to the value of the environment variable if found, otherwise NULL is returned.

Definition at line 92 of file utils.c.

◆ searchandreplace()

char* searchandreplace ( const char *  tosearch,
const char *  searchfor,
const char *  replacewith 
)

Read 'tosearch', replace all occurrences of 'searchfor' with 'replacewith' and return a pointer to the NEW string.

Does not modify the input strings. Will not enter an infinite loop with clever 'searchfor' and 'replacewith' strings.

Author
Daniel Johnson - Progm.nosp@m.an20.nosp@m.00@us.nosp@m.a.ne.nosp@m.t / djohn.nosp@m.son@.nosp@m.progm.nosp@m.an.u.nosp@m.s
Parameters
tosearchhaystack to search in
searchforneedle to search for in the haystack
replacewithwhen a match is found, replace needle with this string
Returns
Returns NULL when any parameter is NULL or the worst-case result is to large ( >= SIZE_MAX). Otherwise it returns a pointer to a new buffer containing the modified input

Definition at line 43 of file utils.c.

Referenced by my_conv(), pass_any_empty_string__returns_null(), pass_any_null_param__returns_null(), pattern_not_found__returns_original(), replace_longer_text__multiple_times__match_all_matches_are_replaced(), replace_single_char__multiple_times__match_all_matches_are_replaced(), and replace_single_char__one_time__match_is_replaced().

◆ string_array_len()

int string_array_len ( const char *  array[])

Return the length of a string array.

Parameters
arrayPointer to the array to calculate size of

Definition at line 114 of file utils.c.