1008: Moved the definition of the big_files_offset to the form.c.
[elinks.git] / src / osdep / generic.h
blob357b602d3a3b9cb8e1a3dedf87a02cfb87ed15fe
1 /* This is... er, the OS-independent part of osdep/ ;-). */
3 #ifndef EL__OSDEP_GENERIC_H
4 #define EL__OSDEP_GENERIC_H
6 #ifdef HAVE_LIMITS_H
7 #include <limits.h> /* may contain PIPE_BUF definition on some systems */
8 #endif
10 #ifdef HAVE_SYS_SIGNAL_H
11 #include <sys/signal.h> /* may contain SA_RESTART */
12 #endif
14 #ifdef HAVE_STDDEF_H
15 #include <stddef.h> /* may contain offsetof() */
16 #endif
18 #ifndef SA_RESTART
19 #define SA_RESTART 0
20 #endif
22 #ifndef PIPE_BUF
23 #define PIPE_BUF 512 /* POSIX says that. -- Mikulas */
24 #endif
26 /* These are not available on some IRIX systems. */
27 #ifndef INET_ADDRSTRLEN
28 #define INET_ADDRSTRLEN 16
29 #endif
30 #ifndef INET6_ADDRSTRLEN
31 #define INET6_ADDRSTRLEN 46
32 #endif
34 #ifdef CONFIG_IPV6
35 #define IP_ADDRESS_BUFFER_SIZE INET6_ADDRSTRLEN
36 #else
37 #define IP_ADDRESS_BUFFER_SIZE INET_ADDRSTRLEN
38 #endif
40 #ifndef PF_INET
41 #define PF_INET AF_INET
42 #endif
44 #ifndef PF_INET6
45 #define PF_INET6 AF_INET6
46 #endif
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 */
56 #ifdef HAVE_UNISTD_H
57 #include <unistd.h>
58 #endif
60 static inline ssize_t
61 safe_read(int fd, void *buf, size_t count) {
62 do {
63 ssize_t r = read(fd, buf, count);
65 if (r == -1 && errno == EINTR) continue;
66 return r;
67 } while (1);
70 static inline ssize_t
71 safe_write(int fd, const void *buf, size_t count) {
72 do {
73 ssize_t w = write(fd, buf, count);
75 if (w == -1 && errno == EINTR) continue;
76 return w;
77 } while (1);
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 */
88 #ifndef HAVE_FTELLO
89 #define ftello(stream) ftell(stream)
90 #endif
92 #ifndef HAVE_FSEEKO
93 #define fseeko(stream, offset, whence) fseek(stream, offset, whence)
94 #endif
96 /* Compiler area: */
98 /* Some compilers, like SunOS4 cc, don't have offsetof in <stddef.h>. */
99 #ifndef offsetof
100 #define offsetof(type, ident) ((size_t) &(((type *) 0)->ident))
101 #endif
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
109 * of memcpy(). */
110 #define copy_struct(destination, source) \
111 do { (*(destination) = *(source)); } while (0)
113 #define sizeof_array(array) (sizeof(array)/sizeof(*(array)))
115 #endif