common.h

/** @file common.h
 *  @date April 24, 2009
 */

#ifndef COMMON_H_
#define COMMON_H_

#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <sys/types.h>

#ifdef DEBUG

/** Returns a failure after displayinga message.  This is executed only in
 *  the DEBUG configuration.
 *
 *  @param module The module that detected the failure.
 *  @param line The line number that detected the failure.
 *  @param error The value of errno when things failed.
 *
 *  @return EXIT_FAILURE.
 */
extern int return_failure(
    const char * module,
    size_t       line,
    int          error);

/** Calls the return_failure function. */
#define RETURN_FAILURE() return return_failure(__FILE__, __LINE__, errno)

#else /* DEBUG */

/** This function simply returns EXIT_FAILURE in the RELEASE configuration. */
#define RETURN_FAILURE() return EXIT_FAILURE

#endif /* DEBUG */

/** Calls the RETURN_FAILURE macro when an expression is zero. */
#define RETURN_IF_FALSE(E) if (!(E)) RETURN_FAILURE()

/** Calls the RETURN_FAILURE macro when an expreesion is not EXIT_SUCCESS. */
#define RETURN_IF_FAILURE(E) RETURN_IF_FALSE(EXIT_SUCCESS == (E))

/** A colleciton of information about a peer. */
typedef struct peer_t {

    /** The address of the peer. */
    u_long address;

    /** The port number of the peer. */
    u_short port;

} peer_t;

/** Starts the stopwatch. */
extern void stopwatch_start(void);

/** Stops the stopwatch and prints statistics.
 *
 *  @param filesize The size of the file in size.
 */
extern void stopwatch_stop(u_long filesize, size_t retries, u_long packets);

#endif /* COMMON_H_ */
Valid HTML 4.01 Valid CSS