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

utils.c File Reference

utilities for the Classic Forum More...

#include "config.h"
#include "defines.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <ctype.h>
#include <errno.h>
#include <sys/time.h>
#include "charconvert.h"
#include "utils.h"

Go to the source code of this file.

Functions

void * memdup (void *inptr, size_t size)
void * fo_alloc (void *ptr, size_t nmemb, size_t size, int type)
size_t split (const u_char *big, const u_char *small, u_char ***ulist)
void mem_init (t_mem_pool *pool)
void str_init (t_string *str)
void mem_cleanup (t_mem_pool *pool)
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)
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)
void * mem_append (t_mem_pool *pool, const void *src, size_t length)
size_t str_str_append (t_string *str, t_string *content)
size_t mem_set (t_mem_pool *pool, const void *src, size_t length)
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 *set)
time_t transform_date (const u_char *datestr)
int gen_unid (u_char *buff, int maxlen)
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_rotate_left (t_cf_tree_node **n)
void cf_tree_rotate_right (t_cf_tree_node **n)
int cf_tree_leftgrown (t_cf_tree_node **n)
int cf_tree_rightgrown (t_cf_tree_node **n)
int cf_tree_insert (t_cf_tree *tree, t_cf_tree_node **n, t_cf_tree_dataset *d)
int cf_tree_leftshrunk (t_cf_tree_node **n)
int cf_tree_rightshrunk (t_cf_tree_node **n)
int cf_tree_findhighest (t_cf_tree_node *target, t_cf_tree_node **n, int *res)
int cf_tree_findlowest (t_cf_tree_node *target, t_cf_tree_node **n, int *res)
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)
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_nodes (t_cf_tree *tree, t_cf_tree_node *n)
void cf_tree_destroy (t_cf_tree *tree)
int cf_strcmp (const u_char *str1, const u_char *str2)
int cf_strcasecmp (const u_char *str1, const u_char *str2)
int cf_strncmp (const u_char *str1, const u_char *str2, size_t n)
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>
These utilities are written for the Classic Forum. Hope, they're useful.

Definition in file utils.c.


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 cf_tree_destroy_nodes t_cf_tree tree,
t_cf_tree_node n
 

Internal function used to destroy all tree nodes (works recursively)

Parameters:
tree The tree
n Actual node

Definition at line 1086 of file utils.c.

int cf_tree_findhighest t_cf_tree_node target,
t_cf_tree_node **  n,
int *  res
 

This function finds the highest subtree

Parameters:
target Target node
n The subtree root node
res Result of this operation (height of the tree)
Returns:
Returns 0 or 1

Definition at line 956 of file utils.c.

int cf_tree_findlowest t_cf_tree_node target,
t_cf_tree_node **  n,
int *  res
 

This function finds the lowest subtree

Parameters:
target The target node
n The subtree root node
res The result of this operation (height of the tree)
Returns:
Returns 0 or 1

Definition at line 990 of file utils.c.

int cf_tree_leftgrown t_cf_tree_node **  n  ) 
 

Handle case if tree has grown on the left side

Parameters:
n The subtree root node
Returns:
Returns 0 or 1

Definition at line 713 of file utils.c.

int cf_tree_leftshrunk t_cf_tree_node **  n  ) 
 

Handle the case that the tree has shrunk on the left side

Parameters:
n The subtree root node
Returns:
Returns 0 or 1

Definition at line 842 of file utils.c.

int cf_tree_rightgrown t_cf_tree_node **  n  ) 
 

private function to handle the case that the tree has been grown to the right side

Parameters:
n Subtree root node
Returns:
Returns 0 or 1

Definition at line 762 of file utils.c.

int cf_tree_rightshrunk t_cf_tree_node **  n  ) 
 

Handle the case that the tree has shrunk on the right side

Parameters:
n The subtree root node
Returns:
Returns 0 or 1

Definition at line 898 of file utils.c.

void cf_tree_rotate_left t_cf_tree_node **  n  ) 
 

private function to do left-rotation if tree is unbalanced

Parameters:
n The subtree root node

Definition at line 686 of file utils.c.

void cf_tree_rotate_right t_cf_tree_node **  n  ) 
 

private function to do right-rotation if tree is unbalanced

Parameters:
n The subtree root node

Definition at line 699 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