2 /* This is... er, the OS-independent part of osdep/ ;-). */
4 #ifndef EL__OSDEP_GENERIC_H
5 #define EL__OSDEP_GENERIC_H
8 #include <limits.h> /* may contain PIPE_BUF definition on some systems */
11 #ifdef HAVE_SYS_SIGNAL_H
12 #include <sys/signal.h> /* may contain SA_RESTART */
16 #include <stddef.h> /* may contain offsetof() */
24 #define PIPE_BUF 512 /* POSIX says that. -- Mikulas */
27 /* These are not available on some IRIX systems. */
28 #ifndef INET_ADDRSTRLEN
29 #define INET_ADDRSTRLEN 16
31 #ifndef INET6_ADDRSTRLEN
32 #define INET6_ADDRSTRLEN 46
36 #define IP_ADDRESS_BUFFER_SIZE INET6_ADDRSTRLEN
38 #define IP_ADDRESS_BUFFER_SIZE INET_ADDRSTRLEN
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 */
55 safe_read(int fd
, void *buf
, size_t count
) {
57 ssize_t r
= read(fd
, buf
, count
);
59 if (r
== -1 && errno
== EINTR
) continue;
65 safe_write(int fd
, const void *buf
, size_t count
) {
67 ssize_t w
= write(fd
, buf
, count
);
69 if (w
== -1 && errno
== EINTR
) continue;
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 */
83 #define ftello(stream) ftell(stream)
87 #define fseeko(stream, offset, whence) fseek(stream, offset, whence)
92 /* Some compilers, like SunOS4 cc, don't have offsetof in <stddef.h>. */
94 #define offsetof(type, ident) ((size_t) &(((type *) 0)->ident))
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
104 #define copy_struct(destination, source) \
105 do { (*(destination) = *(source)); } while (0)
107 #define sizeof_array(array) (sizeof(array)/sizeof(*(array)))