pam_pkcs11 0.6.12
strings.h File Reference
#include <stdlib.h>
#include <string.h>

Go to the source code of this file.

Macros

#define M_EXTERN   extern
 String management library.
 

Functions

M_EXTERN int is_empty_str (const char *str)
 Check for a null or spaced string.
 
M_EXTERN char * clone_str (const char *str)
 Duplicate a string.
 
M_EXTERN char * toupper_str (const char *str)
 Duplicate a string converting all chars to upper-case.
 
M_EXTERN char * tolower_str (const char *str)
 Duplicate a string converting all chars to lower-case.
 
M_EXTERN char * bin2hex (const unsigned char *binstr, const int len)
 Convert a byte array into a colon-separated hexadecimal sequence.
 
M_EXTERN unsigned char * hex2bin (const char *hexstr)
 Convert a colon-separated hexadecimal data into a byte array.
 
M_EXTERN unsigned char * hex2bin_static (const char *hexstr, unsigned char **res, int *size)
 Convert a colon-separated hexadecimal data into a byte array, store result into a previously allocated space.
 
M_EXTERN char ** split (const char *str, char sep, int nelems)
 Splits a string to an array of nelems by using sep as character separator.
 
M_EXTERN char ** split_static (const char *str, char sep, int nelems, char *dst)
 Splits a string to an array of nelems by using sep as character separator, using dest as pre-allocated destination memory for the resulting array.
 
M_EXTERN char * trim (const char *str)
 Remove all extra spaces from a string.
 

Macro Definition Documentation

◆ M_EXTERN

#define M_EXTERN   extern

String management library.

Definition at line 37 of file strings.h.

Referenced by bin2hex(), clone_str(), hex2bin(), hex2bin_static(), is_empty_str(), split(), split_static(), tolower_str(), toupper_str(), and trim().

Function Documentation

◆ bin2hex()

M_EXTERN char * bin2hex ( const unsigned char * binstr,
const int len )

Convert a byte array into a colon-separated hexadecimal sequence.

Parameters
binstrByteArray to be parsed
lenNumber of bytes to be converted
Returns
Pointer to result string or null if error in allocating memory

References M_EXTERN.

◆ clone_str()

M_EXTERN char * clone_str ( const char * str)

Duplicate a string.

Parameters
strString to be cloned
Returns
Pointer to cloned string or null if error in allocating memory

References M_EXTERN.

◆ hex2bin()

M_EXTERN unsigned char * hex2bin ( const char * hexstr)

Convert a colon-separated hexadecimal data into a byte array.

Parameters
hexstrString to be parsed
Returns
Pointer to resulting byte array, or null if no memory available

References M_EXTERN.

◆ hex2bin_static()

M_EXTERN unsigned char * hex2bin_static ( const char * hexstr,
unsigned char ** res,
int * size )

Convert a colon-separated hexadecimal data into a byte array, store result into a previously allocated space.

Parameters
hexstrString to be parsed
resPointer to pre-allocated user space
sizePointer to store lenght of data parsed
Returns
Pointer to resulting byte array, or null on parse error

References M_EXTERN.

◆ is_empty_str()

M_EXTERN int is_empty_str ( const char * str)

Check for a null or spaced string.

Parameters
strTested string
Returns
nonzero on null, empty or spaced string, else zero

References M_EXTERN.

◆ split()

M_EXTERN char ** split ( const char * str,
char sep,
int nelems )

Splits a string to an array of nelems by using sep as character separator.

To free() memory used by this call, call free(res[0]); free(res);

Parameters
strString to be parsed
sepCharacter to be used as separator
nelemsNumber of elements of resulting array
Returns
res: Pointer to resulting string array, or null if malloc() error

References M_EXTERN.

◆ split_static()

M_EXTERN char ** split_static ( const char * str,
char sep,
int nelems,
char * dst )

Splits a string to an array of nelems by using sep as character separator, using dest as pre-allocated destination memory for the resulting array.

To free() memory used by this call, just call free result pointer

Parameters
strString to be parsed
sepCharacter to be used as separator
nelemsNumber of elements of resulting array
dstChar array to store temporary data
Returns
Pointer to resulting string array, or null if malloc() error

References M_EXTERN.

◆ tolower_str()

M_EXTERN char * tolower_str ( const char * str)

Duplicate a string converting all chars to lower-case.

Parameters
strString to be cloned & lowercased
Returns
Pointer to result string or null if error in allocating memory

References M_EXTERN.

◆ toupper_str()

M_EXTERN char * toupper_str ( const char * str)

Duplicate a string converting all chars to upper-case.

Parameters
strString to be cloned & uppercassed
Returns
Pointer to result string or null if error in allocating memory

References M_EXTERN.

◆ trim()

M_EXTERN char * trim ( const char * str)

Remove all extra spaces from a string.

a char is considered space if trues isspace()

Parameters
strString to be trimmed
Returns
Pointer to cloned string with all spaces trimmed or null if error in allocating memory

References M_EXTERN.