-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathportable.h
71 lines (62 loc) · 1.64 KB
/
portable.h
1
2
3
4
5
6
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#ifndef PORTABLE_H
#define PORTABLE_H
#ifdef HAVE_CONFIG_H
# include "config.h"
#else
# define PACKAGE "dfu-util"
# define PACKAGE_VERSION "1.0"
# define PACKAGE_STRING "dfu-util 1.1 (ddmesh)"
# define PACKAGE_BUGREPORT "http://sourceforge.net/p/dfu-util/tickets/"
# include <io.h>
#endif /* HAVE_CONFIG_H */
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif /* HAVE_UNISTD_H */
#ifdef HAVE_NANOSLEEP
# include <time.h>
# define milli_sleep(msec) do {\
if (msec) {\
struct timespec nanosleepDelay = { (msec) / 1000, ((msec) % 1000) * 1000000 };\
nanosleep(&nanosleepDelay, NULL);\
} } while (0)
#elif defined HAVE_WINDOWS_H
# define milli_sleep(msec) do {\
if (msec) {\
Sleep(msec);\
} } while (0)
#else
# error "Can't get no sleep! Please report"
#endif /* HAVE_NANOSLEEP */
#ifdef HAVE_ERR
# include <err.h>
#else
# include <errno.h>
# include <string.h>
# define warnx(...) do {\
fprintf(stderr, __VA_ARGS__);\
fprintf(stderr, "\n"); } while (0)
# define errx(eval, ...) do {\
warnx(__VA_ARGS__);\
exit(eval); } while (0)
# define warn(...) do {\
fprintf(stderr, "%s: ", strerror(errno));\
warnx(__VA_ARGS__); } while (0)
# define err(eval, ...) do {\
warn(__VA_ARGS__);\
exit(eval); } while (0)
#endif /* HAVE_ERR */
#ifdef HAVE_SYSEXITS_H
# include <sysexits.h>
#else
# define EX_OK 0 /* successful termination */
# define EX_USAGE 64 /* command line usage error */
# define EX_SOFTWARE 70 /* internal software error */
# define EX_IOERR 74 /* input/output error */
#endif /* HAVE_SYSEXITS_H */
#ifndef O_BINARY
# define O_BINARY 0
#endif
#ifndef off_t
# define off_t long int
#endif
#endif /* PORTABLE_H */