html_special(): move va_end() call outside the switch and make variables
[elinks.git] / src / osdep / generic.h
blobc6608aac1cebb533edafda71954d2ba47d3a9a22
2 /* This is... er, the OS-independent part of osdep/ ;-). */
4 #ifndef EL__OSDEP_GENERIC_H
5 #define EL__OSDEP_GENERIC_H
7 #ifdef HAVE_LIMITS_H
8 #include <limits.h> /* may contain PIPE_BUF definition on some systems */
9 #endif
11 #ifdef HAVE_SYS_SIGNAL_H
12 #include <sys/signal.h> /* may contain SA_RESTART */
13 #endif
15 #ifdef HAVE_STDDEF_H
16 #include <stddef.h> /* may contain offsetof() */
17 #endif
19 #ifndef SA_RESTART
20 #define SA_RESTART 0
21 #endif
23 #ifndef PIPE_BUF
24 #define PIPE_BUF 512 /* POSIX says that. -- Mikulas */
25 #endif
27 /* These are not available on some IRIX systems. */
28 #ifndef INET_ADDRSTRLEN
29 #define INET_ADDRSTRLEN 16
30 #endif
31 #ifndef INET6_ADDRSTRLEN
32 #define INET6_ADDRSTRLEN 46
33 #endif
35 #ifdef CONFIG_IPV6
36 #define IP_ADDRESS_BUFFER_SIZE INET6_ADDRSTRLEN
37 #else
38 #define IP_ADDRESS_BUFFER_SIZE INET_ADDRSTRLEN
39 #endif
42 /* Attempt to workaround the EINTR mess. */
43 #if defined(EINTR) && !defined(CONFIG_WIN32)
45 #ifdef TEMP_FAILURE_RETRY /* GNU libc */
46 #define safe_read(fd, buf, count) TEMP_FAILURE_RETRY(read(fd, buf, count))
47 #define safe_write(fd, buf, count) TEMP_FAILURE_RETRY(write(fd, buf, count))
48 #else /* TEMP_FAILURE_RETRY */
50 #ifdef HAVE_UNISTD_H
51 #include <unistd.h>
52 #endif
54 static inline ssize_t
55 safe_read(int fd, void *buf, size_t count) {
56 do {
57 ssize_t r = read(fd, buf, count);
59 if (r == -1 && errno == EINTR) continue;
60 return r;
61 } while (1);
64 static inline ssize_t
65 safe_write(int fd, const void *buf, size_t count) {
66 do {
67 ssize_t w = write(fd, buf, count);
69 if (w == -1 && errno == EINTR) continue;
70 return w;
71 } while (1);
73 #endif /* TEMP_FAILURE_RETRY */
75 #else /* EINTR && !CONFIG_WIN32 */
77 #define safe_read(fd, buf, count) read(fd, buf, count)
78 #define safe_write(fd, buf, count) write(fd, buf, count)
80 #endif /* EINTR && !CONFIG_WIN32 */
82 #ifndef HAVE_FTELLO
83 #define ftello(stream) ftell(stream)
84 #endif
86 #ifndef HAVE_FSEEKO
87 #define fseeko(stream, offset, whence) fseek(stream, offset, whence)
88 #endif
90 /* Compiler area: */
92 /* Some compilers, like SunOS4 cc, don't have offsetof in <stddef.h>. */
93 #ifndef offsetof
94 #define offsetof(type, ident) ((size_t) &(((type *) 0)->ident))
95 #endif
97 /* Alignment of types. */
98 #define alignof(TYPE) \
99 ((int) &((struct { unsigned char dummy1; TYPE dummy2; } *) 0)->dummy2)
101 /* Using this macro to copy structs is both faster and safer than
102 * memcpy(destination, source, sizeof(source)). Please, use this macro instead
103 * of memcpy(). */
104 #define copy_struct(destination, source) \
105 do { (*(destination) = *(source)); } while (0)
107 #define sizeof_array(array) (sizeof(array)/sizeof(*(array)))
109 #endif