1 /* This is... er, the OS-independent part of osdep/ ;-). */
3 #ifndef EL__OSDEP_GENERIC_H
4 #define EL__OSDEP_GENERIC_H
7 #include <limits.h> /* may contain PIPE_BUF definition on some systems */
10 #ifdef HAVE_SYS_SIGNAL_H
11 #include <sys/signal.h> /* may contain SA_RESTART */
15 #include <stddef.h> /* may contain offsetof() */
23 #define PIPE_BUF 512 /* POSIX says that. -- Mikulas */
26 /* These are not available on some IRIX systems. */
27 #ifndef INET_ADDRSTRLEN
28 #define INET_ADDRSTRLEN 16
30 #ifndef INET6_ADDRSTRLEN
31 #define INET6_ADDRSTRLEN 46
35 #define IP_ADDRESS_BUFFER_SIZE INET6_ADDRSTRLEN
37 #define IP_ADDRESS_BUFFER_SIZE INET_ADDRSTRLEN
41 #define PF_INET AF_INET
45 #define PF_INET6 AF_INET6
48 /* Attempt to workaround the EINTR mess. */
49 #if defined(EINTR) && !defined(CONFIG_OS_WIN32)
51 #ifdef TEMP_FAILURE_RETRY /* GNU libc */
52 #define safe_read(fd, buf, count) TEMP_FAILURE_RETRY(read(fd, buf, count))
53 #define safe_write(fd, buf, count) TEMP_FAILURE_RETRY(write(fd, buf, count))
54 #else /* TEMP_FAILURE_RETRY */
61 safe_read(int fd
, void *buf
, size_t count
) {
63 ssize_t r
= read(fd
, buf
, count
);
65 if (r
== -1 && errno
== EINTR
) continue;
71 safe_write(int fd
, const void *buf
, size_t count
) {
73 ssize_t w
= write(fd
, buf
, count
);
75 if (w
== -1 && errno
== EINTR
) continue;
79 #endif /* TEMP_FAILURE_RETRY */
81 #else /* EINTR && !CONFIG_OS_WIN32 */
83 #define safe_read(fd, buf, count) read(fd, buf, count)
84 #define safe_write(fd, buf, count) write(fd, buf, count)
86 #endif /* EINTR && !CONFIG_OS_WIN32 */
89 #define ftello(stream) ftell(stream)
93 #define fseeko(stream, offset, whence) fseek(stream, offset, whence)
98 /* Some compilers, like SunOS4 cc, don't have offsetof in <stddef.h>. */
100 #define offsetof(type, ident) ((size_t) &(((type *) 0)->ident))
103 /* Alignment of types. */
104 #define alignof(TYPE) \
105 offsetof(struct { unsigned char dummy1; TYPE dummy2; }, dummy2)
107 /* Using this macro to copy structs is both faster and safer than
108 * memcpy(destination, source, sizeof(source)). Please, use this macro instead
110 #define copy_struct(destination, source) \
111 do { (*(destination) = *(source)); } while (0)
113 #define sizeof_array(array) (sizeof(array)/sizeof(*(array)))