apple2ix/src/common.h

122 lines
2.8 KiB
C
Raw Normal View History

2013-07-07 21:01:21 +00:00
/*
2013-10-06 06:13:24 +00:00
* Apple // emulator for *nix
2013-07-07 21:01:21 +00:00
*
* This software package is subject to the GNU General Public License
* version 2 or later (your choice) as published by the Free Software
* Foundation.
*
* THERE ARE NO WARRANTIES WHATSOEVER.
*
*/
#ifndef _COMMON_H_
#define _COMMON_H_
2013-10-23 04:18:03 +00:00
#if defined(__GNUC__) && !defined(_GNU_SOURCE)
# define _GNU_SOURCE
#endif
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
2013-07-07 21:01:21 +00:00
#include <stdlib.h>
#include <stdio.h>
2013-07-07 21:01:21 +00:00
#include <errno.h>
#include <string.h>
2013-10-06 06:13:24 +00:00
#include <stdint.h>
#include <stdbool.h>
#include <time.h>
#include <unistd.h>
#include <assert.h>
#include <pthread.h>
#include <ctype.h>
#include <dirent.h>
#include <fcntl.h>
#include <limits.h>
#include <zlib.h>
2013-07-07 21:01:21 +00:00
#include <sys/time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "misc.h"
#include "timing.h"
#include "cpu.h"
#include "video/video.h"
#include "disk.h"
#include "interface.h"
#include "keys.h"
#include "joystick.h"
#include "glue.h"
#include "prefs.h"
#include "uthash.h"
#include "zlib-helpers.h"
#ifdef DEBUGGER
#include "meta/debug.h"
#endif
#ifdef AUDIO_ENABLED
#include "audio/soundcore.h"
#include "audio/speaker.h"
#include "audio/mockingboard.h"
#endif
2013-07-07 21:01:21 +00:00
#ifndef NDEBUG
2013-10-06 06:13:24 +00:00
# if defined(__GNUC__)
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wunused-variable"
# elif defined(__clang__)
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wunused-variable"
# endif
2013-07-07 21:01:21 +00:00
static FILE *error_log=0;
#define ERRLOG(/* err message format string, args */...) \
2013-10-06 06:13:24 +00:00
do { \
2013-07-07 21:01:21 +00:00
int saverr = errno; errno = 0; \
fprintf(error_log ? error_log : stderr, "%s:%d - ", __FILE__, __LINE__); \
fprintf(error_log ? error_log : stderr, __VA_ARGS__); \
if (saverr) { \
fprintf(error_log ? error_log : stderr, " (syserr: %s)", strerror(saverr)); \
} \
fprintf(error_log ? error_log : stderr, "\n"); \
2013-10-06 06:13:24 +00:00
} while(0);
2013-07-07 21:01:21 +00:00
2013-09-13 03:47:00 +00:00
#define ERRQUIT(...) \
2013-10-06 06:13:24 +00:00
do { \
2013-09-13 03:47:00 +00:00
ERRLOG(__VA_ARGS__); \
exit(1); \
2013-10-06 06:13:24 +00:00
} while(0);
2013-09-13 03:47:00 +00:00
2013-07-07 21:01:21 +00:00
#else // NDEBUG
#if defined(__GNUC__)
2013-09-13 03:47:00 +00:00
# pragma GCC diagnostic pop
2013-07-07 21:01:21 +00:00
#elif defined(__clang__)
2013-09-13 03:47:00 +00:00
# pragma clang diagnostic pop
2013-07-07 21:01:21 +00:00
#endif
2013-10-06 06:13:24 +00:00
#define ERRLOG(...) \
do \
{ \
2013-07-07 21:01:21 +00:00
} while(0);
#endif
2013-10-06 06:13:24 +00:00
#define LOG(...) \
do { \
errno = 0; \
ERRLOG(__VA_ARGS__); \
} while(0);
2013-07-07 21:01:21 +00:00
2013-10-06 06:13:24 +00:00
#define Free(X) \
do { \
free(X); \
X=NULL; \
} while (0);
2013-07-07 21:01:21 +00:00
#endif // whole file