common.h
author Tero Marttila <terom@fixme.fi>
Fri, 06 Jun 2008 18:35:46 +0300
changeset 11 082bfaf38cf0
parent 8 4d38ccbeb93e
child 12 43297144f196
permissions -rw-r--r--
* massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
* the beginnings of render_multi, really not done yet

committer: Tero Marttila <terom@fixme.fi>

/*
 * error handling
 */

// perror + exit
void die (const char *msg);

// fprintf + newline
void error (const char *fmt, ...);

// fprintf + strerror + newline
void perr (const char *fmt, ...);

// fprintf + strerror + newline + exit
void perr_exit (const char *fmt, ...);

// fprintf + newline + exit
void err_exit (const char *fmt, ...);

// fprintf (__func__ + msg, ...)
void err_func (const char *func, const char *fmt, ...);

// fprintf (__func__ + msg + strerror, ...)
void perr_func (const char *func, const char *fmt, ...);

// error(func + colon + msg, ...) + goto error
#define ERROR(msg) do { err_func(__func__, "%s", msg); goto error; } while (0)
#define ERROR_FMT(fmt, ...) do { err_func(__func__, fmt, __VA_ARGS__); goto error; } while (0)
#define PERROR(msg) do { perr_func(__func__, "%s", msg); goto error; } while (0)
#define PERROR_FMT(fmt, ...) do { perr_func(__func__, fmt, __VA_ARGS__); goto error; } while (0)

/*
 * Parse a host:port string.
 *
 * Valid formats:
 *  host
 *  host:port
 *  [host]
 *  [host]:port
 *
 * The contents of the given hostport string *will* be modified.
 *
 * The value of *port will be set to NULL if no port was given.
 *
 * Returns 0 and sets *host if succesfull, nonzero otherwise.
 *
 */
int parse_hostport (char *hostport, char **host, char **port);