Main Page | Modules | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

utils.h File Reference

Utilities for the Classic Forum. More...

#include <time.h>
#include <sys/types.h>

Go to the source code of this file.

Data Structures

struct  s_array
struct  s_cf_dataset
struct  s_cf_tree
struct  s_cf_tree_node
struct  s_mem_pool
struct  s_string

Defines

#define FO_ALLOC_MALLOC   0
#define FO_ALLOC_CALLOC   1
#define FO_ALLOC_REALLOC   2

Typedefs

typedef s_mem_pool t_mem_pool
typedef s_string t_string
typedef s_array t_array
typedef s_cf_dataset t_cf_tree_dataset
typedef s_cf_tree_node t_cf_tree_node
typedef s_cf_tree t_cf_tree

Enumerations

enum  e_cf_tree_balance { CF_TREE_NONE, CF_TREE_LEFT, CF_TREE_RIGHT }

Functions

void mem_init (t_mem_pool *pool)
void mem_cleanup (t_mem_pool *pool)
size_t mem_set (t_mem_pool *pool, const void *src, size_t length)
void * mem_append (t_mem_pool *pool, const void *src, size_t len)
void str_init (t_string *str)
void str_cleanup (t_string *str)
size_t str_char_append (t_string *str, const u_char content)
size_t str_chars_append (t_string *str, const u_char *content, size_t length)
size_t str_str_append (t_string *str, t_string *content)
size_t str_char_set (t_string *str, const u_char *content, size_t length)
size_t str_str_set (t_string *str, t_string *content)
int str_equal_string (const t_string *str1, const t_string *str2)
int str_equal_chars (const t_string *str1, const u_char *str2, size_t len)
size_t split (const u_char *big, const u_char *small, u_char ***ulist)
time_t transform_date (const u_char *datestr)
int gen_unid (u_char *buff, int maxlen)
void * fo_alloc (void *ptr, size_t nmemb, size_t size, int type)
void * memdup (void *inptr, size_t size)
void array_init (t_array *ary, size_t element_size, void(*array_destroy)(void *))
void array_push (t_array *ary, const void *element)
void * array_pop (t_array *ary)
void * array_shift (t_array *ary)
void array_unshift (t_array *ary, const void *element)
void array_sort (t_array *ary, int(*compar)(const void *, const void *))
void * array_bsearch (t_array *ary, const void *key, int(*compar)(const void *, const void *))
void * array_element_at (t_array *ary, size_t index)
void array_destroy (t_array *ary)
void cf_tree_init (t_cf_tree *tree, int(*compare)(t_cf_tree_dataset *, t_cf_tree_dataset *), void(*destroy)(t_cf_tree_dataset *))
void cf_tree_destroy (t_cf_tree *tree)
int cf_tree_insert (t_cf_tree *tree, t_cf_tree_node **n, t_cf_tree_dataset *d)
int cf_tree_remove (t_cf_tree *tree, t_cf_tree_node **n, t_cf_tree_dataset *key)
const t_cf_tree_datasetcf_tree_find (t_cf_tree *tree, t_cf_tree_node *n, t_cf_tree_dataset *key)
int cf_strcmp (const u_char *str1, const u_char *str2)
int cf_strncmp (const u_char *str1, const u_char *str2, size_t n)
int cf_strcasecmp (const u_char *str1, const u_char *str2)
int cf_strncasecmp (const u_char *str1, const u_char *str2, size_t n)
size_t cf_strlen_utf8 (const u_char *str, size_t rlen)


Detailed Description

Utilities for the Classic Forum.

Author:
Christian Kruse, <cjk@wwwtech.de>
This file contains some utility functions for the Classic Forum, e.g. a string abstraction and a split() function.

Definition in file utils.h.


Define Documentation

#define FO_ALLOC_CALLOC   1
 

Allocate memory and initialize it with 0 bytes

Definition at line 222 of file utils.h.

#define FO_ALLOC_MALLOC   0
 

Just allocate Memory

Definition at line 221 of file utils.h.

#define FO_ALLOC_REALLOC   2
 

Re-allocate a memory block with a different size

Definition at line 223 of file utils.h.


Function Documentation

int cf_strcasecmp const u_char *  str1,
const u_char *  str2
 

Fast implementation of strcasecmp()

Parameters:
str1 First string
str2 Second string
Returns:
0 if strings are equal (case insensitive), 1 if not equal

Definition at line 1123 of file utils.c.

int cf_strcmp const u_char *  str1,
const u_char *  str2
 

Fast implementation of strcmp()

Parameters:
str1 First string
str2 Second string
Returns:
0 if strings are equal, 1 if strings are not equal

Definition at line 1112 of file utils.c.

size_t cf_strlen_utf8 const u_char *  str,
size_t  rlen
 

Counts characters (not bytes!!) in an utf8 string

Parameters:
str The string to count
rlen The real length of the memory area
Returns:
-1 on failure (e.g. EILSEQ), length on success

Definition at line 1158 of file utils.c.

int cf_strncasecmp const u_char *  str1,
const u_char *  str2,
size_t  n
 

Fast implementation of strncasecmp()

Parameters:
str1 First string
str2 Second string
n Number of chars to compare
Returns:
0 if substrings are equal, 1 if not equal

Definition at line 1146 of file utils.c.

int cf_strncmp const u_char *  str1,
const u_char *  str2,
size_t  n
 

Fast implementation of strncmp()

Parameters:
str1 First string
str2 Second string
n Number of chars to compare
Returns:
0 if substrings are equal, 1 if not equal

Definition at line 1134 of file utils.c.

void* fo_alloc void *  ptr,
size_t  nmemb,
size_t  size,
int  type
 

This function safely allocates new memory. If the memory could not be allocated, exit() will be called.

Parameters:
ptr The old pointer (for FO_ALLOC_REALLOC)
nmemb The number of objects to allocate
size The size of one object
type The type of the allocation
Returns:
The pointer to the new memory segment or NULL, if you gave a wrong type.

Definition at line 62 of file utils.c.

int gen_unid u_char *  buff,
int  maxlen
 

This function generates a (hopefully) unique id from the REMOTE_ADDR environment variable and a little bit random.

Parameters:
buff The buffer to store the id in
maxlen The maximal length of the id
Returns:
The length of the id on success or 0 on failure

Definition at line 492 of file utils.c.

void* memdup void *  inptr,
size_t  size
 

This function duplicates a memory segment area

Parameters:
inptr Pointer to the memory area segment to duplicate
size The size of the segment
Returns:
A pointer to the newly created segment
Attention:
You have to free() the newly created segment yourself!

Definition at line 44 of file utils.c.

size_t split const u_char *  big,
const u_char *  small,
u_char ***  ulist
 

Splits a string into a list of strings and returns the length of the list. The string big will be cut at every match of the string small.

Parameters:
big The string to split
small The string to search
ulist A reference to a u_char ** pointer. In this u_char ** pointer will the list be stored.
Returns:
The length of the list.
Attention:
You HAVE to free every element of the list and the list itself!

Definition at line 96 of file utils.c.

time_t transform_date const u_char *  datestr  ) 
 

This function tries to convert a date string in the form of "1.1.1982 12:30:40" into a unix timestamp. The time in the date is optional.

Parameters:
datestr The date string
Returns:
The timestamp on success or -1 on failure.

Definition at line 393 of file utils.c.


Generated on Sun Apr 25 16:37:39 2004 for Classic Forum by doxygen 1.3.5