| 1 |
|
| 2 |
#ifndef PORTABLE_H |
| 3 |
#define PORTABLE_H |
| 4 |
|
| 5 |
#ifndef HAVE_CONFIG_H |
| 6 |
# define PACKAGE "dfu-util" |
| 7 |
# define PACKAGE_VERSION "0.11-msvc" |
| 8 |
# define PACKAGE_STRING "dfu-util 0.11-msvc" |
| 9 |
# define PACKAGE_BUGREPORT "http://sourceforge.net/p/dfu-util/tickets/" |
| 10 |
# include <io.h> |
| 11 |
/* FIXME if off_t is a typedef it is not a define */ |
| 12 |
# ifndef off_t |
| 13 |
# define off_t long int |
| 14 |
# endif |
| 15 |
#endif /* HAVE_CONFIG_H */ |
| 16 |
|
| 17 |
#ifdef HAVE_UNISTD_H |
| 18 |
# include <unistd.h> |
| 19 |
#endif /* HAVE_UNISTD_H */ |
| 20 |
|
| 21 |
#ifdef HAVE_NANOSLEEP |
| 22 |
# include <time.h> |
| 23 |
# define milli_sleep(msec) do {\ |
| 24 |
if (msec != 0) {\ |
| 25 |
struct timespec nanosleepDelay = { (msec) / 1000, ((msec) % 1000) * 1000000 };\ |
| 26 |
nanosleep(&nanosleepDelay, NULL);\ |
| 27 |
} } while (0) |
| 28 |
#elif defined HAVE_WINDOWS_H |
| 29 |
# define milli_sleep(msec) do {\ |
| 30 |
if (msec != 0) {\ |
| 31 |
Sleep(msec);\ |
| 32 |
} } while (0) |
| 33 |
#else |
| 34 |
# error "Can't get no sleep! Please report" |
| 35 |
#endif /* HAVE_NANOSLEEP */ |
| 36 |
|
| 37 |
#ifdef HAVE_ERR |
| 38 |
# include <err.h> |
| 39 |
#else |
| 40 |
# include <errno.h> |
| 41 |
# include <string.h> |
| 42 |
# define warnx(...) do {\ |
| 43 |
fprintf(stderr, __VA_ARGS__);\ |
| 44 |
fprintf(stderr, "\n"); } while (0) |
| 45 |
# define errx(eval, ...) do {\ |
| 46 |
warnx(__VA_ARGS__);\ |
| 47 |
exit(eval); } while (0) |
| 48 |
# define warn(...) do {\ |
| 49 |
fprintf(stderr, "%s: ", strerror(errno));\ |
| 50 |
warnx(__VA_ARGS__); } while (0) |
| 51 |
# define err(eval, ...) do {\ |
| 52 |
warn(__VA_ARGS__);\ |
| 53 |
exit(eval); } while (0) |
| 54 |
#endif /* HAVE_ERR */ |
| 55 |
|
| 56 |
#ifdef HAVE_SYSEXITS_H |
| 57 |
# include <sysexits.h> |
| 58 |
#else |
| 59 |
# define EX_OK 0 /* successful termination */ |
| 60 |
# define EX_USAGE 64 /* command line usage error */ |
| 61 |
# define EX_DATAERR 65 |
| 62 |
# define EX_NOINPUT 66 |
| 63 |
# define EX_SOFTWARE 70 /* internal software error */ |
| 64 |
# define EX_CANTCREAT 73 /* input/output error */ |
| 65 |
# define EX_IOERR 74 /* input/output error */ |
| 66 |
# define EX_PROTOCOL 76 /* input/output error */ |
| 67 |
#endif /* HAVE_SYSEXITS_H */ |
| 68 |
|
| 69 |
#ifndef O_BINARY |
| 70 |
# define O_BINARY 0 |
| 71 |
#endif |
| 72 |
|
| 73 |
#endif /* PORTABLE_H */ |