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

util.c File Reference

#include "sys.h"
#include "sysnet.h"
#include "util.h"
#include <ctype.h>
#include <dirent.h>

Defines

#define AW_MALLOC_SLEEP   10000
#define AW_N_MALLOC_TRIES   5

Functions

int32_t aw_cache_alloc_clear (aw_cache_allocator_t *allocator)
 Clear, clean up allocator. Assumes been init'd.

int32_t aw_cache_alloc_free (aw_cache_allocator_t *allocator, void *object)
 free() wrapper for use with cache allocator

int32_t aw_cache_alloc_init (aw_cache_allocator_t *allocator, size_t object_size, u_int32_t max_cache_size)
 malloc() wrapper, that caches frees in a list for quick reuse

void * aw_cache_alloc_malloc (aw_cache_allocator_t *allocator)
 Retuns object , from cache if possible.

void aw_close_all_fds (void)
 Close all fds except 0,1,2. Used between a fork() and exec() to avoid child exits() from flushing buffered io to parent fds.

int32_t aw_close_tcpsocket (int32_t s)
 standard tcp shutdown procedure

byte_t * aw_find_in_path (const byte_t *filename, const byte_t *pathvar)
 Return malloc'd full path of filename found in pathvar (e.g., PATH, LD_LIBRARY_PATH), else NULL
Returns:
Found file path or NULL.


void aw_free (void *p)
 free() wrapper

int32_t aw_get_major_version (void)
int32_t aw_get_minor_version (void)
int32_t aw_get_patchlevel (void)
const byte_t * aw_get_version_string (void)
in_addr_t aw_getifip (const byte_t *ifname)
 Get first ip address associated with interface.

off_t aw_lseek_resume (int fildes, off_t offset, int whence)
 Signal insensitve lseek().

void * aw_malloc (size_t size)
 malloc() wrapper, does some sleep/retry on failure

int32_t aw_nanosleep (const struct timespec *sleep)
 Signal insensitve nanosleep().

ssize_t aw_read_resume (int fd, void *buf, size_t count)
 Signal insensitve read().

byte_t * aw_strcatdup (const byte_t *s1, const byte_t *s2)
 Return copy of 2 concatentated strings, NULL on failure.

byte_t * aw_strstrcase (const byte_t *haystack, const byte_t *needle)
 Case insensitive strstr.

byte_t * aw_strtrim (byte_t *s)
 Remove (in place) whitespace in front/behind text.

ssize_t aw_write_resume (int fd, const void *buf, size_t count)
 Signal insensitve write().

void * aw_zalloc (size_t size)
 aw_malloc() wrapper, zeros the memory


Define Documentation

#define AW_MALLOC_SLEEP   10000
 

#define AW_N_MALLOC_TRIES   5
 


Function Documentation

int32_t aw_cache_alloc_clear (  aw_cache_allocator_t *  allocator  ) 
 

Clear, clean up allocator. Assumes been init'd.

aw_cache_alloc_clear

Parameters:
allocator Cache object
Returns:
Returns 0 on success

int32_t aw_cache_alloc_free (  aw_cache_allocator_t *  allocator,
void *  object
) 
 

free() wrapper for use with cache allocator

aw_cache_alloc_free

Parameters:
allocator Cache object
object Pointer to memory to free
Returns:
Returns 0 on success

int32_t aw_cache_alloc_init (  aw_cache_allocator_t *  allocator,
size_t  object_size,
u_int32_t  max_cache_size
) 
 

malloc() wrapper, that caches frees in a list for quick reuse

aw_cache_alloc_init

Parameters:
allocator Cache object
object_size The size in bytes of an object
max_cache_size How many objects to allow on free list before _really_ freeing. If 0, then unlimited.
Returns:
Returns 0 on success

void* aw_cache_alloc_malloc (  aw_cache_allocator_t *  allocator  ) 
 

Retuns object , from cache if possible.

aw_cache_alloc_malloc

Parameters:
allocator Cache object
Returns:
Returns ptr to object, NULL on failure

void aw_close_all_fds (  void   ) 
 

Close all fds except 0,1,2. Used between a fork() and exec() to avoid child exits() from flushing buffered io to parent fds.

aw_close_all_fds

int32_t aw_close_tcpsocket (  int32_t  s  ) 
 

standard tcp shutdown procedure

aw_close_tcpsocket

Parameters:
s socket
Returns:
same as close()

byte_t* aw_find_in_path (  const byte_t *  filename,
const byte_t *  pathvar
) 
 

Return malloc'd full path of filename found in pathvar (e.g., PATH, LD_LIBRARY_PATH), else NULL

Returns:
Found file path or NULL.

aw_find_in_path

void aw_free (  void *  p  ) 
 

free() wrapper

aw_free

Parameters:
p Pointer to memory to free

int32_t aw_get_major_version (  void   ) 
 

aw_get_major_version

Returns:
Major version of sw as compiled, see version.h

int32_t aw_get_minor_version (  void   ) 
 

aw_get_minor_version

Returns:
Minor version of sw as compiled, see version.h

int32_t aw_get_patchlevel (  void   ) 
 

aw_get_patchlevel

Returns:
Patchlevel version of sw as compiled, see version.h

const byte_t* aw_get_version_string (  void   ) 
 

aw_get_version_string

Returns:
Version string of sw as compiled, see version.h

in_addr_t aw_getifip (  const byte_t *  ifname  ) 
 

Get first ip address associated with interface.

aw_getifip

Parameters:
ifname Name of interface
Returns:
Ip address of interface, return -1 on failure

off_t aw_lseek_resume (  int  fildes,
off_t  offset,
int  whence
) 
 

Signal insensitve lseek().

aw_lseek_resume

Parameters:
fildes File descriptor
offset Offset
whence How to seek
Returns:
same as lseek()

void* aw_malloc (  size_t  size  ) 
 

malloc() wrapper, does some sleep/retry on failure

aw_malloc

Parameters:
size The size in bytes
Returns:
Returns ptr to object, NULL on failure

int32_t aw_nanosleep (  const struct timespec *  sleep  ) 
 

Signal insensitve nanosleep().

aw_nanosleep

Parameters:
sleep Time to sleep
Returns:
0 for success, -1 if error

ssize_t aw_read_resume (  int  fd,
void *  buf,
size_t  count
) 
 

Signal insensitve read().

aw_read_resume

Parameters:
fd File descriptor
buf Ptr to data
count Number of bytes
Returns:
same as read()

byte_t* aw_strcatdup (  const byte_t *  s1,
const byte_t *  s2
) 
 

Return copy of 2 concatentated strings, NULL on failure.

aw_strcatdup

Parameters:
s1 First string
s2 Second string
Returns:
Concatenated string, NULL on failure

byte_t* aw_strstrcase (  const byte_t *  haystack,
const byte_t *  needle
) 
 

Case insensitive strstr.

aw_strstrcase

Parameters:
haystack String to search
needle String to find in haystack
Returns:
Pointer to found needle in haystack, else NULL

byte_t* aw_strtrim (  byte_t *  s  ) 
 

Remove (in place) whitespace in front/behind text.

aw_strtrim

Parameters:
s String to trim in place
Returns:
s

ssize_t aw_write_resume (  int  fd,
const void *  buf,
size_t  count
) 
 

Signal insensitve write().

aw_write_resume

Parameters:
fd File descriptor
buf Ptr to data
count Number of bytes
Returns:
same as write()

void* aw_zalloc (  size_t  size  ) 
 

aw_malloc() wrapper, zeros the memory

aw_zalloc

Parameters:
size The size in bytes
Returns:
Returns ptr to object, NULL on failure

Aware 0.11.1 Copyright (C) 1998-2005 Russell Leighton (russ@elegant-software.com)