Main Page | Modules | Data Structures | Directories | File List | Data Fields

Miscellaneous


Functions

int u_isblank (int c)
 Returns 0 if c is neither a space or a tab, not-zero otherwise.
void u_trim (char *s)
 Removes leading and trailing blanks (spaces and tabs) from s.
int u_isblank_str (const char *ln)
 Returns 1 if ln is a blank string i.e. a string formed by ONLY spaces and/or tabs characters.
int u_isnl (int c)
 Returns 0 if c is neither a CR (\r) or a LF (\n), not-zero otherwise.
char * u_strndup (const char *s, size_t len)
 Dups the first len chars of s. Returns the dupped zero terminated string or NULL on error.
char * u_strdup (const char *s)
 Dups the supplied string s.
int u_savepid (const char *pf)
 Save the PID of the calling process to a file named pf (that should be a fully qualified path). Returns 0 on success, not-zero on error.
char * u_sstrncpy (char *dst, const char *src, size_t size)
 Safe string copy, see also the U_SSTRNCPY define Safe string copy which null-terminates the destination string dst before copying the source string src for no more than size bytes. Returns a pointer to the destination string dst.
void * u_memdup (const void *src, size_t size)
 Dups the memory block src of size size. Returns the pointer of the dup'd block on success, NULL on error.
int u_tokenize (char *wlist, const char *delim, char **tokv, size_t tokv_sz)
 tokenize the supplied wlist string
int u_snprintf (char *str, size_t size, const char *fmt,...)
 snprintf-like function that returns 0 on success and ~0 on error
int u_path_snprintf (char *buf, size_t sz, char sep, const char *fmt,...)
 snprintf-like function that handle path separator issues
void u_use_unused_args (char *dummy,...)
int u_data_is_bin (char *data, size_t sz)
 Return 1 if the supplied buffer data has non-ascii bytes.
int u_data_dump (char *data, size_t sz, const char *file)
int u_load_file (const char *path, size_t sz_max, char **pbuf, size_t *psz)
 Load file into memory from the supplied FS entry.
int u_io (iof_t f, int sd, void *buf, size_t l, ssize_t *n, int *eof)
 Top level I/O routine.
int u_sleep (unsigned int secs)
 sleep(3) wrapper that handles EINTR
int u_accept (int ld, struct sockaddr *addr, int *addrlen)
 accept(2) wrapper that handles EINTR
ssize_t u_read (int fd, void *buf, size_t size)
 read(2) wrapper that handles EINTR
ssize_t u_write (int fd, void *buf, size_t size)
 write(2) wrapper that handle EINTR

Function Documentation

int u_accept int  ld,
struct sockaddr *  addr,
int *  addrlen
 

Parameters:
ld file descriptor
addr see accept(2)
addrlen size of addr struct
Returns:
on success returns the socket descriptor; on failure returns -1

Definition at line 421 of file srcs/toolbox/misc.c.

int u_io iof_t  f,
int  sd,
void *  buf,
size_t  l,
ssize_t *  n,
int *  eof
 

Try to read/write - atomically - a chunk of l bytes from/to the object referenced by the descriptor sd. The data chunk is written to/read from the buffer starting at buf. The I/O driver function f is used to carry out the job, its interface and behaviour must conform to those of POSIX.1 read() or write(). If n is not NULL, it will store the number of bytes actually read/written: this information is significant only when u_io has failed. If eof is not NULL, it will be set to 1 on an end-of-file condition.

Parameters:
f the I/O function, i.e. read(2) or write(2)
sd the file descriptor on which the I/O operation is performed
buf the data chunk to be read or written
l the length in bytes of buf
n the number of bytes read/written as a value-result arg
eof true if end-of-file condition
Returns:
A ~0 is returned if an error other than EINTR has occurred, or if the requested amount of data could not be entirely read/written. A 0 is returned on success.

Definition at line 346 of file srcs/toolbox/misc.c.

Referenced by u_read(), and u_write().

int u_load_file const char *  path,
size_t  sz_max,
char **  pbuf,
size_t *  psz
 

Parameters:
path the path name of the file
sz_max if >0 impose this size limit (otherwise unlimited)
pbuf the pointer to the memory location holding the file's contents as a value-result argument
psz size of the loaded file as a v-r argument
Returns:
0 on success, ~0 on error

Definition at line 293 of file srcs/toolbox/misc.c.

References u_zalloc().

int u_path_snprintf char *  buf,
size_t  sz,
char  sep,
const char *  fmt,
  ...
 

Calls snprintf with the provided arguments and remove consecutive path separators from the resulting string.

Parameters:
buf destination buffer
sz size of str
sep path separator to use ('/' or '\')
fmt snprintf format string
Returns 0 on success, not-zero on error.

Definition at line 225 of file srcs/toolbox/misc.c.

ssize_t u_read int  fd,
void *  buf,
size_t  size
 

Parameters:
fd file descriptor
buf buffer to read into
size size of the buffer
Returns:
on success returns the number of bytes read (that will be always 'size' except on eof); on failure returns -1

Definition at line 442 of file srcs/toolbox/misc.c.

References u_io().

int u_sleep unsigned int  secs  ) 
 

Parameters:
secs sleep for 'secs' seconds
Returns:
on success returns the socket descriptor; on failure returns -1

Definition at line 393 of file srcs/toolbox/misc.c.

int u_snprintf char *  str,
size_t  size,
const char *  fmt,
  ...
 

snprintf-like function that returns 0 on success and ~0 on error

Parameters:
str destination buffer
size size of str
fmt snprintf format string
Returns 0 on success, not-zero on error.

Definition at line 194 of file srcs/toolbox/misc.c.

Referenced by u_hmap_put().

int u_tokenize char *  wlist,
const char *  delim,
char **  tokv,
size_t  tokv_sz
 

Tokenize the delim separated string wlist and place its pieces (at most tokv_sz - 1) into tokv.

Parameters:
wlist list of strings possibily separated by chars in delim
delim set of token separators
tokv pre-allocated string array
tokv_sz number of cells in tokv array

Definition at line 155 of file srcs/toolbox/misc.c.

ssize_t u_write int  fd,
void *  buf,
size_t  size
 

Parameters:
fd file descriptor
buf buffer to write
size size of the buffer
Returns:
size on success, -1 on error

Definition at line 467 of file srcs/toolbox/misc.c.

References u_io().


←Products
© 2005-2007 - KoanLogic S.r.l. - All rights reserved