pam_pkcs11  0.6.8
Defines | Functions
strings.h File Reference
#include <stdlib.h>
#include <string.h>

Go to the source code of this file.

Defines

#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.

Define Documentation

#define M_EXTERN   extern

String management library.

Definition at line 37 of file strings.h.


Function Documentation

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