
/*----------------------------------------------------------------------+
 |                                                                      |
 |      base.h -- basic types                                           |
 |                                                                      |
 +----------------------------------------------------------------------*/

/*
 *  NOTE: This is A minimum base.h substitute for use by stand-alone wtime
 */
#define WTIME_BASE_H

/*----------------------------------------------------------------------+
 |      Copyright                                                       |
 +----------------------------------------------------------------------*/

/*
 *  Copyright (C) 2007, Marcel van Kervinck
 *  All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions
 *  are met:
 *  1. Redistributions of source code must retain the above copyright
 *     notice, this list of conditions and the following disclaimer.
 *  2. Redistributions in binary form must reproduce the above copyright
 *     notice, this list of conditions and the following disclaimer in
 *     the documentation and/or other materials provided with the
 *     distribution.
 *  3. Neither the name of the copyright holder nor the names of its
 *     contributors may be used to endorse or promote products derived
 *     from this software without specific prior written permission.
 *
 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS
 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
 *  COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
 *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 *  POSSIBILITY OF SUCH DAMAGE.
 */

/*----------------------------------------------------------------------+
 |      Booleans                                                        |
 +----------------------------------------------------------------------*/

typedef enum {
        false,
        true
} bool;

/*----------------------------------------------------------------------+
 |      Exceptions                                                      |
 +----------------------------------------------------------------------*/

typedef int err_t;

#define OK (0)

#define check(result) do{\
        err_t _tmp_err = (result);\
        if (_tmp_err != OK) {\
                err = _tmp_err;\
                goto cleanup;\
        }\
}while(0)

#define RETURN do{\
        goto cleanup;\
}while(0)

#define RAISE(xerror) do{\
        err = (xerror);\
        goto cleanup;\
}while(0)

#define RAISE_ERRNO(xfunction) RAISE(WTIME_ERR_SYSTEM)

/*----------------------------------------------------------------------+
 |      Arithmetic                                                      |
 +----------------------------------------------------------------------*/

/* for n>0 */
#define DIV(d,n) ( (d)>=0 ? (d)/(n) : ~(~(d)/(n)) )
#define MOD(d,n) ( (d)>=0 ? (d)%(n) : (n) - 1 - ~(d)%(n) )

/*----------------------------------------------------------------------+
 |                                                                      |
 +----------------------------------------------------------------------*/

