Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals  

miscutil.h File Reference

zalloc, hash_string, safe_strerror, strcmpic, strncmpic, and MinGW32 strdup functions. More...

Go to the source code of this file.

Defines

#define MISCUTIL_H_VERSION   "$Id: miscutil.h,v 2.0 2002/06/04 14:34:21 jongfoster Exp $"

Functions

void * zalloc (size_t size)
unsigned int hash_string (const char *s)
char * safe_strerror (int err)
int strcmpic (const char *s1, const char *s2)
int strncmpic (const char *s1, const char *s2, size_t n)
char * strsav (char *old, const char *text_to_append)
jb_err string_append (char **target_string, const char *text_to_append)
jb_err string_join (char **target_string, char *text_to_append)
char * string_toupper (const char *string)
char * chomp (char *string)
int simplematch (char *pattern, char *text)
char * bindup (const char *string, size_t len)
char * make_path (const char *dir, const char *file)

Variables

const char * basedir
const char miscutil_rcs []
const char miscutil_h_rcs []


Detailed Description

zalloc, hash_string, safe_strerror, strcmpic, strncmpic, and MinGW32 strdup functions.

These are each too small to deserve their own file but don't really fit in any other file.

Log:
miscutil.h,v
Revision 2.0 2002/06/04 14:34:21 jongfoster Moving source files to src/

Revision 1.21 2002/04/26 12:55:38 oes New function string_toupper

Revision 1.20 2002/03/26 22:29:55 swa we have a new homepage!

Revision 1.19 2002/03/24 13:25:43 swa name change related issues

Revision 1.18 2002/03/07 03:46:17 oes Fixed compiler warnings

Revision 1.17 2002/03/04 18:28:32 oes Deleted deletePidFile, played syleguide police

Revision 1.16 2002/01/21 00:53:36 jongfoster Adding string_join()

Revision 1.15 2001/12/30 14:07:32 steudten

Revision 1.14 2001/11/05 21:43:48 steudten Add global var 'basedir' for unix os.

Revision 1.13 2001/10/29 03:48:10 david__schmidt OS/2 native needed a snprintf() routine. Added one to miscutil, brackedted by and __OS2__ ifdef.

Revision 1.12 2001/10/23 21:27:50 jongfoster Standardising error codes in string_append make_path() no longer adds '\' if the dir already ends in '\' (this is just copying a UNIX-specific fix to the Windows-specific part)

Revision 1.11 2001/10/14 22:02:57 jongfoster New function string_append() which is like strsav(), but running out of memory isn't automatically FATAL.

Revision 1.10 2001/09/20 13:34:09 steudten

change long to int for prototype hash_string()

Revision 1.9 2001/07/29 18:43:08 jongfoster Changing ifdef _FILENAME_H to FILENAME_H_INCLUDED, to conform to ANSI C rules.

Revision 1.8 2001/06/29 13:32:14 oes Removed logentry from cancelled commit

Revision 1.7 2001/06/05 22:32:01 jongfoster New function make_path() to splice directory and file names together.

Revision 1.6 2001/06/03 19:12:30 oes introduced bindup()

Revision 1.5 2001/06/01 10:31:51 oes Added character class matching to trivimatch; renamed to simplematch

Revision 1.4 2001/05/31 17:32:31 oes

Revision 1.3 2001/05/29 23:10:09 oes

Revision 1.2 2001/05/29 09:50:24 jongfoster Unified blocklist/imagelist/permissionslist. File format is still under discussion, but the internal changes are (mostly) done.

Also modified interceptor behaviour:

Revision 1.1.1.1 2001/05/15 13:59:00 oes Initial import of version 2.9.3 source tree


Function Documentation

char* bindup const char *    string,
size_t    len
 

Duplicate the first n characters of a string that may contain '\0' characters.

Parameters:
string  string to be duplicated
len  number of bytes to duplicate
Returns:
pointer to copy, or NULL if failiure

char* chomp char *    string
 

In-situ-eliminate all leading and trailing whitespace from a string.

Parameters:
string  string to be chomped.
Returns:
chomped string

unsigned int hash_string const char *    s
 

Take a string and compute a (hopefuly) unique numeric integer value.

This has several uses, but being able to "switch" a string the one of my favorites.

Parameters:
s  string to be hashed.
Returns:
an unsigned long variable with the hashed value.

char* safe_strerror int    err
 

Variant of the library routine strerror() which will work on systems without the library routine, and which should never return NULL.

Parameters:
err  the `errno' of the last operation.
Returns:
An "English" string of the last `errno'. Allocated with strdup(), so caller frees. May be NULL if the system is out of memory.

int simplematch char *    pattern,
char *    text
 

String matching, with a (greedy) '*' wildcard that stands for zero or more arbitrary characters and character classes in [], which take both enumerations and ranges.

Parameters:
pattern  pattern for matching
text  text to be matched
Returns:
0 if match, else nonzero

int strcmpic const char *    s1,
const char *    s2
 

Case insensitive string comparison.

Parameters:
s1  string 1 to compare
s2  string 2 to compare
Returns:
0 if s1==s2, Negative if s1<s2, Positive if s1>s2

jb_err string_append char **    target_string,
const char *    text_to_append
 

Reallocate target_string and append text to it.

This makes it easier to append to malloc'd strings. This is similar to the (removed) strsav(), but running out of memory isn't catastrophic. Programming style: The following style provides sufficient error checking for this routine, with minimal clutter in the source code. It is recommended if you have many calls to this function: char * s = strdup(...); // don't check for error string_append(&s, ...); // don't check for error string_append(&s, ...); // don't check for error string_append(&s, ...); // don't check for error if (NULL == s) { ... handle error ... } OR, equivalently: char * s = strdup(...); // don't check for error string_append(&s, ...); // don't check for error string_append(&s, ...); // don't check for error if (string_append(&s, ...)) {... handle error ...}

Parameters:
target_string  Pointer to old text that is to be extended. *target_string will be free()d by this routine. target_string must be non-NULL. If *target_string is NULL, this routine will do nothing and return with an error - this allows you to make many calls to this routine and only check for errors after the last one.
text_to_append  Text to be appended to old. Must not be NULL.
Returns:
JB_ERR_OK on success, and sets *target_string to newly malloc'ed appended string. Caller must free(*target_string). JB_ERR_MEMORY on out-of-memory. (And free()s *target_string and sets it to NULL). JB_ERR_MEMORY if *target_string is NULL.

jb_err string_join char **    target_string,
char *    text_to_append
 

Join two strings together.

Frees BOTH the original strings. If either or both input strings are NULL, fails as if it had run out of memory. For comparison, string_append requires that the second string is non-NULL, and doesn't free it.

Rationale Too often, we want to do string_append(s, html_encode(s2)). That assert()s if s2 is NULL or if html_encode() runs out of memory. It also leaks memory. Proper checking is cumbersome. The solution: string_join(s, html_encode(s2)) is safe, and will free the memory allocated by html_encode().

Parameters:
target_string  Pointer to old text that is to be extended. *target_string will be free()d by this routine. target_string must be non-NULL.
text_to_append  Text to be appended to old.
Returns:
JB_ERR_OK on success, and sets *target_string to newly malloc'ed appended string. Caller must free(*target_string). JB_ERR_MEMORY on out-of-memory, or if *target_string or text_to_append is NULL. (In this case, frees *target_string and text_to_append, sets *target_string to NULL).

char* string_toupper const char *    string
 

Produce a copy of string with all convertible characters converted to uppercase.

Parameters:
string  string to convert
Returns:
Uppercase copy of string if possible, NULL on out-of-memory or if string was NULL.

int strncmpic const char *    s1,
const char *    s2,
size_t    n
 

Case insensitive string comparison (upto n characters).

Parameters:
s1  string 1 to compare
s2  string 2 to compare
n  maximum characters to compare
Returns:
0 if s1==s2, Negative if s1<s2, Positive if s1>s2

char* strsav char *    old,
const char *    text_to_append
 

Reallocate "old" and append text to it.

This makes it easier to append to malloc'd strings. Running out of memory is a FATAL error.

Parameters:
old  Old text that is to be extended. Will be free()d by this routine. May be NULL.
text_to_append  Text to be appended to old. May be NULL.
Returns:
Pointer to newly malloc'ed appended string. If there is no text to append, return old. Caller must free().

void* zalloc size_t    size
 

Malloc some memory and set it to '\0'.

The way calloc() ought to be -acjc

Parameters:
size  Size of memory chunk to return.
Returns:
Pointer to newly malloc'd memory chunk.


Variable Documentation

const char miscutil_h_rcs[]
 

Version information about miscutil.h.

const char miscutil_rcs[]
 

Version information about miscutil.c.


Generated on Tue Jun 4 18:54:49 2002 for Privoxy 3.1.1 by doxygen1.2.15