GitLab maintenance scheduled for Tomorrow, 2020-08-11, from 17:00 to 18:00 CT - Services will be unavailable during this time.

tools.h 1.54 KB
Newer Older
Philip Carns's avatar
Philip Carns committed
1 2 3 4 5 6
/*
 * Copyright (C) 2013 University of Chicago.
 * See COPYRIGHT notice in top-level directory.
 *
 */

7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
#ifndef SRC_COMMON_UTIL_TOOLS_H
#define SRC_COMMON_UTIL_TOOLS_H

#ifdef UNUSED
#elif defined(__GNUC__)
# define UNUSED(x) UNUSED_ ## x __attribute__((unused))
#elif defined(__LCLINT__)
# define UNUSED(x) /*@unused@*/ x
#else
# define UNUSED(x) x
#endif /* UNUSED */

#define codesmin(a,b) ((a)<(b) ? (a):(b))
#define codesmax(a,b) ((a)>(b) ? (a):(b))

void always_assert_error(const char * expr, const char * file, int lineno);

#define ALWAYS_ASSERT(a) if (!(a)) always_assert_error(#a,__FILE__, __LINE__);

#define ARRAY_SIZEOF(a) (sizeof(a)/sizeof(a[0]))

char * safe_strncpy(char * buf, const char * source, unsigned int bufsize);

#define CODES_FLAG_ISSET(mode_, flag_) ((mode_ & flag_) != 0)
#define CODES_FLAG_SET(mode_, flag_, branch_)   \
do                                              \
{                                               \
    mode_ = mode_ | flag_;                      \
    branch_ = 1;                                \
}while(0)

#define CODES_FLAG_SET_RC(mode_, flag_, branch_)   \
do                                                  \
{                                                   \
    if(branch_)                                     \
    {                                               \
        mode_ = mode_ & (~flag_);                   \
    }                                               \
}while(0)

#endif
Philip Carns's avatar
Philip Carns committed
48 49 50 51 52 53 54 55 56

/*
 * Local variables:
 *  c-indent-level: 4
 *  c-basic-offset: 4
 * End:
 *
 * vim: ts=8 sts=4 sw=4 expandtab
 */