Mercurial > dovecot > original-hg > dovecot-1.2
annotate src/lib/compat.h @ 8076:bbfbc84f795c HEAD
Added clock_gettime() compatibility function for systems without it.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Thu, 07 Aug 2008 15:05:40 -0400 |
parents | 7f9f7fc02359 |
children | 845e6da5194a |
rev | line source |
---|---|
6410
e4eb71ae8e96
Changed .h ifdef/defines to use <NAME>_H format.
Timo Sirainen <tss@iki.fi>
parents:
5782
diff
changeset
|
1 #ifndef COMPAT_H |
e4eb71ae8e96
Changed .h ifdef/defines to use <NAME>_H format.
Timo Sirainen <tss@iki.fi>
parents:
5782
diff
changeset
|
2 #define COMPAT_H |
0 | 3 |
3672 | 4 #if defined (HAVE_INTTYPES_H) && defined(__osf__) |
3671
77135b9e26b5
Include inttypes.h with Tru64 to get uint32_t etc. types defined.
Timo Sirainen <tss@iki.fi>
parents:
3623
diff
changeset
|
5 # include <inttypes.h> |
77135b9e26b5
Include inttypes.h with Tru64 to get uint32_t etc. types defined.
Timo Sirainen <tss@iki.fi>
parents:
3623
diff
changeset
|
6 #endif |
77135b9e26b5
Include inttypes.h with Tru64 to get uint32_t etc. types defined.
Timo Sirainen <tss@iki.fi>
parents:
3623
diff
changeset
|
7 |
56 | 8 /* well, this is obviously wrong since it assumes it's 64bit, but older |
9 GCCs don't define it and we really want it. */ | |
10 #ifndef LLONG_MAX | |
11 # define LLONG_MAX 9223372036854775807LL | |
12 #endif | |
13 | |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3672
diff
changeset
|
14 #ifndef __cplusplus |
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3672
diff
changeset
|
15 #ifdef HAVE__BOOL |
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3672
diff
changeset
|
16 typedef _Bool bool; |
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3672
diff
changeset
|
17 #else |
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3672
diff
changeset
|
18 typedef int bool; |
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3672
diff
changeset
|
19 #endif |
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3672
diff
changeset
|
20 #endif |
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3672
diff
changeset
|
21 |
3929
49a1a979959e
If uoff_t type already exists, use it (UnixWare has it).
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
22 #if defined (HAVE_UOFF_T) |
49a1a979959e
If uoff_t type already exists, use it (UnixWare has it).
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
23 /* native support */ |
49a1a979959e
If uoff_t type already exists, use it (UnixWare has it).
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
24 #elif defined (UOFF_T_INT) |
179
0ffecd4e7e1a
added dec2str() function and largest_t type, removed itoa() and ltoa()
Timo Sirainen <tss@iki.fi>
parents:
56
diff
changeset
|
25 typedef unsigned int uoff_t; |
0ffecd4e7e1a
added dec2str() function and largest_t type, removed itoa() and ltoa()
Timo Sirainen <tss@iki.fi>
parents:
56
diff
changeset
|
26 #elif defined (UOFF_T_LONG) |
0ffecd4e7e1a
added dec2str() function and largest_t type, removed itoa() and ltoa()
Timo Sirainen <tss@iki.fi>
parents:
56
diff
changeset
|
27 typedef unsigned long uoff_t; |
0ffecd4e7e1a
added dec2str() function and largest_t type, removed itoa() and ltoa()
Timo Sirainen <tss@iki.fi>
parents:
56
diff
changeset
|
28 #elif defined (UOFF_T_LONG_LONG) |
0ffecd4e7e1a
added dec2str() function and largest_t type, removed itoa() and ltoa()
Timo Sirainen <tss@iki.fi>
parents:
56
diff
changeset
|
29 typedef unsigned long long uoff_t; |
0ffecd4e7e1a
added dec2str() function and largest_t type, removed itoa() and ltoa()
Timo Sirainen <tss@iki.fi>
parents:
56
diff
changeset
|
30 #else |
0ffecd4e7e1a
added dec2str() function and largest_t type, removed itoa() and ltoa()
Timo Sirainen <tss@iki.fi>
parents:
56
diff
changeset
|
31 # error uoff_t size not set |
0ffecd4e7e1a
added dec2str() function and largest_t type, removed itoa() and ltoa()
Timo Sirainen <tss@iki.fi>
parents:
56
diff
changeset
|
32 #endif |
0ffecd4e7e1a
added dec2str() function and largest_t type, removed itoa() and ltoa()
Timo Sirainen <tss@iki.fi>
parents:
56
diff
changeset
|
33 |
678
1e5c655bad25
Renamed largest_t to uintmax_t which already exists in C99.
Timo Sirainen <tss@iki.fi>
parents:
572
diff
changeset
|
34 #ifndef HAVE_UINTMAX_T |
1e5c655bad25
Renamed largest_t to uintmax_t which already exists in C99.
Timo Sirainen <tss@iki.fi>
parents:
572
diff
changeset
|
35 # if SIZEOF_LONG_LONG > 0 |
1e5c655bad25
Renamed largest_t to uintmax_t which already exists in C99.
Timo Sirainen <tss@iki.fi>
parents:
572
diff
changeset
|
36 typedef unsigned long long uintmax_t; |
1e5c655bad25
Renamed largest_t to uintmax_t which already exists in C99.
Timo Sirainen <tss@iki.fi>
parents:
572
diff
changeset
|
37 # else |
1e5c655bad25
Renamed largest_t to uintmax_t which already exists in C99.
Timo Sirainen <tss@iki.fi>
parents:
572
diff
changeset
|
38 typedef unsigned long uintmax_t; |
1e5c655bad25
Renamed largest_t to uintmax_t which already exists in C99.
Timo Sirainen <tss@iki.fi>
parents:
572
diff
changeset
|
39 # endif |
908
bc55266563cd
Use separate check for uint_fast32_t.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
40 #endif |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
805
diff
changeset
|
41 |
908
bc55266563cd
Use separate check for uint_fast32_t.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
42 #ifndef HAVE_UINT_FAST32_T |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
805
diff
changeset
|
43 # if SIZEOF_INT >= 4 |
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
805
diff
changeset
|
44 typedef unsigned int uint_fast32_t; |
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
805
diff
changeset
|
45 # else |
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
805
diff
changeset
|
46 typedef unsigned long uint_fast32_t; |
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
805
diff
changeset
|
47 # endif |
678
1e5c655bad25
Renamed largest_t to uintmax_t which already exists in C99.
Timo Sirainen <tss@iki.fi>
parents:
572
diff
changeset
|
48 #endif |
1e5c655bad25
Renamed largest_t to uintmax_t which already exists in C99.
Timo Sirainen <tss@iki.fi>
parents:
572
diff
changeset
|
49 |
1e5c655bad25
Renamed largest_t to uintmax_t which already exists in C99.
Timo Sirainen <tss@iki.fi>
parents:
572
diff
changeset
|
50 #ifndef HAVE_SOCKLEN_T |
1e5c655bad25
Renamed largest_t to uintmax_t which already exists in C99.
Timo Sirainen <tss@iki.fi>
parents:
572
diff
changeset
|
51 typedef int socklen_t; |
179
0ffecd4e7e1a
added dec2str() function and largest_t type, removed itoa() and ltoa()
Timo Sirainen <tss@iki.fi>
parents:
56
diff
changeset
|
52 #endif |
0ffecd4e7e1a
added dec2str() function and largest_t type, removed itoa() and ltoa()
Timo Sirainen <tss@iki.fi>
parents:
56
diff
changeset
|
53 |
692
359f73bf84b5
Added CMP_DEV_T macro which uses major()/minor() if possible but fallbacks
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
54 #ifdef HAVE_SYS_SYSMACROS_H |
693
21233287e9c1
And the missing sys/sysmacros.h include..
Timo Sirainen <tss@iki.fi>
parents:
692
diff
changeset
|
55 # include <sys/sysmacros.h> |
3932
b079a386a2f7
Include sys/mkdev.h with UnixWare for major() and minor()
Timo Sirainen <tss@iki.fi>
parents:
3929
diff
changeset
|
56 # ifdef HAVE_SYS_MKDEV_H |
b079a386a2f7
Include sys/mkdev.h with UnixWare for major() and minor()
Timo Sirainen <tss@iki.fi>
parents:
3929
diff
changeset
|
57 # include <sys/mkdev.h> /* UnixWare */ |
b079a386a2f7
Include sys/mkdev.h with UnixWare for major() and minor()
Timo Sirainen <tss@iki.fi>
parents:
3929
diff
changeset
|
58 # endif |
692
359f73bf84b5
Added CMP_DEV_T macro which uses major()/minor() if possible but fallbacks
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
59 # define CMP_DEV_T(a, b) (major(a) == major(b) && minor(a) == minor(b)) |
359f73bf84b5
Added CMP_DEV_T macro which uses major()/minor() if possible but fallbacks
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
60 #elif !defined (DEV_T_STRUCT) |
359f73bf84b5
Added CMP_DEV_T macro which uses major()/minor() if possible but fallbacks
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
61 # define CMP_DEV_T(a, b) ((a) == (b)) |
359f73bf84b5
Added CMP_DEV_T macro which uses major()/minor() if possible but fallbacks
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
62 #else |
359f73bf84b5
Added CMP_DEV_T macro which uses major()/minor() if possible but fallbacks
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
63 # error I do not know how to compare dev_t |
359f73bf84b5
Added CMP_DEV_T macro which uses major()/minor() if possible but fallbacks
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
64 #endif |
359f73bf84b5
Added CMP_DEV_T macro which uses major()/minor() if possible but fallbacks
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
65 |
7526
a957567706ec
Replaced HAVE_ST_NSEC macro checks with more generic ST_?TIME_NSEC() macros
Timo Sirainen <tss@iki.fi>
parents:
6410
diff
changeset
|
66 #ifdef HAVE_STAT_XTIM |
a957567706ec
Replaced HAVE_ST_NSEC macro checks with more generic ST_?TIME_NSEC() macros
Timo Sirainen <tss@iki.fi>
parents:
6410
diff
changeset
|
67 # define HAVE_ST_NSECS |
a957567706ec
Replaced HAVE_ST_NSEC macro checks with more generic ST_?TIME_NSEC() macros
Timo Sirainen <tss@iki.fi>
parents:
6410
diff
changeset
|
68 # define ST_ATIME_NSEC(st) ((unsigned long)(st).st_atim.tv_nsec) |
a957567706ec
Replaced HAVE_ST_NSEC macro checks with more generic ST_?TIME_NSEC() macros
Timo Sirainen <tss@iki.fi>
parents:
6410
diff
changeset
|
69 # define ST_MTIME_NSEC(st) ((unsigned long)(st).st_mtim.tv_nsec) |
a957567706ec
Replaced HAVE_ST_NSEC macro checks with more generic ST_?TIME_NSEC() macros
Timo Sirainen <tss@iki.fi>
parents:
6410
diff
changeset
|
70 # define ST_CTIME_NSEC(st) ((unsigned long)(st).st_ctim.tv_nsec) |
a957567706ec
Replaced HAVE_ST_NSEC macro checks with more generic ST_?TIME_NSEC() macros
Timo Sirainen <tss@iki.fi>
parents:
6410
diff
changeset
|
71 #elif defined (HAVE_STAT_XTIMESPEC) |
a957567706ec
Replaced HAVE_ST_NSEC macro checks with more generic ST_?TIME_NSEC() macros
Timo Sirainen <tss@iki.fi>
parents:
6410
diff
changeset
|
72 # define HAVE_ST_NSECS |
a957567706ec
Replaced HAVE_ST_NSEC macro checks with more generic ST_?TIME_NSEC() macros
Timo Sirainen <tss@iki.fi>
parents:
6410
diff
changeset
|
73 # define ST_ATIME_NSEC(st) ((unsigned long)(st).st_atimespec.tv_nsec) |
a957567706ec
Replaced HAVE_ST_NSEC macro checks with more generic ST_?TIME_NSEC() macros
Timo Sirainen <tss@iki.fi>
parents:
6410
diff
changeset
|
74 # define ST_MTIME_NSEC(st) ((unsigned long)(st).st_mtimespec.tv_nsec) |
a957567706ec
Replaced HAVE_ST_NSEC macro checks with more generic ST_?TIME_NSEC() macros
Timo Sirainen <tss@iki.fi>
parents:
6410
diff
changeset
|
75 # define ST_CTIME_NSEC(st) ((unsigned long)(st).st_ctimespec.tv_nsec) |
a957567706ec
Replaced HAVE_ST_NSEC macro checks with more generic ST_?TIME_NSEC() macros
Timo Sirainen <tss@iki.fi>
parents:
6410
diff
changeset
|
76 #else |
a957567706ec
Replaced HAVE_ST_NSEC macro checks with more generic ST_?TIME_NSEC() macros
Timo Sirainen <tss@iki.fi>
parents:
6410
diff
changeset
|
77 # define ST_ATIME_NSEC(st) 0UL |
a957567706ec
Replaced HAVE_ST_NSEC macro checks with more generic ST_?TIME_NSEC() macros
Timo Sirainen <tss@iki.fi>
parents:
6410
diff
changeset
|
78 # define ST_MTIME_NSEC(st) 0UL |
a957567706ec
Replaced HAVE_ST_NSEC macro checks with more generic ST_?TIME_NSEC() macros
Timo Sirainen <tss@iki.fi>
parents:
6410
diff
changeset
|
79 # define ST_CTIME_NSEC(st) 0UL |
a957567706ec
Replaced HAVE_ST_NSEC macro checks with more generic ST_?TIME_NSEC() macros
Timo Sirainen <tss@iki.fi>
parents:
6410
diff
changeset
|
80 #endif |
a957567706ec
Replaced HAVE_ST_NSEC macro checks with more generic ST_?TIME_NSEC() macros
Timo Sirainen <tss@iki.fi>
parents:
6410
diff
changeset
|
81 |
a957567706ec
Replaced HAVE_ST_NSEC macro checks with more generic ST_?TIME_NSEC() macros
Timo Sirainen <tss@iki.fi>
parents:
6410
diff
changeset
|
82 #ifdef HAVE_ST_NSECS |
a957567706ec
Replaced HAVE_ST_NSEC macro checks with more generic ST_?TIME_NSEC() macros
Timo Sirainen <tss@iki.fi>
parents:
6410
diff
changeset
|
83 /* TRUE if a nanosecond timestamp from struct stat matches another nanosecond. |
a957567706ec
Replaced HAVE_ST_NSEC macro checks with more generic ST_?TIME_NSEC() macros
Timo Sirainen <tss@iki.fi>
parents:
6410
diff
changeset
|
84 If nanoseconds aren't supported in struct stat, returns always TRUE (useful |
a957567706ec
Replaced HAVE_ST_NSEC macro checks with more generic ST_?TIME_NSEC() macros
Timo Sirainen <tss@iki.fi>
parents:
6410
diff
changeset
|
85 with NFS if some hosts support nanoseconds and others don't). */ |
a957567706ec
Replaced HAVE_ST_NSEC macro checks with more generic ST_?TIME_NSEC() macros
Timo Sirainen <tss@iki.fi>
parents:
6410
diff
changeset
|
86 # define ST_NTIMES_EQUAL(ns1, ns2) ((ns1) == (ns2)) |
a957567706ec
Replaced HAVE_ST_NSEC macro checks with more generic ST_?TIME_NSEC() macros
Timo Sirainen <tss@iki.fi>
parents:
6410
diff
changeset
|
87 #else |
a957567706ec
Replaced HAVE_ST_NSEC macro checks with more generic ST_?TIME_NSEC() macros
Timo Sirainen <tss@iki.fi>
parents:
6410
diff
changeset
|
88 # define ST_NTIMES_EQUAL(ns1, ns2) TRUE |
a957567706ec
Replaced HAVE_ST_NSEC macro checks with more generic ST_?TIME_NSEC() macros
Timo Sirainen <tss@iki.fi>
parents:
6410
diff
changeset
|
89 #endif |
a957567706ec
Replaced HAVE_ST_NSEC macro checks with more generic ST_?TIME_NSEC() macros
Timo Sirainen <tss@iki.fi>
parents:
6410
diff
changeset
|
90 |
a957567706ec
Replaced HAVE_ST_NSEC macro checks with more generic ST_?TIME_NSEC() macros
Timo Sirainen <tss@iki.fi>
parents:
6410
diff
changeset
|
91 #define CMP_ST_MTIME(st1, st2) \ |
5782
2e6a977b1d6a
Added CMP_ST_MTIME() and CMP_ST_CTIME() macros that compare also nanoseconds
Timo Sirainen <tss@iki.fi>
parents:
4909
diff
changeset
|
92 ((st1)->st_mtime == (st2)->st_mtime && \ |
7577
0d842b055838
Fixed compiling in BSD systems.
Timo Sirainen <tss@iki.fi>
parents:
7526
diff
changeset
|
93 ST_NTIMES_EQUAL(ST_MTIME_NSEC(*(st1)), ST_MTIME_NSEC(*(st2)))) |
7526
a957567706ec
Replaced HAVE_ST_NSEC macro checks with more generic ST_?TIME_NSEC() macros
Timo Sirainen <tss@iki.fi>
parents:
6410
diff
changeset
|
94 #define CMP_ST_CTIME(st1, st2) \ |
5782
2e6a977b1d6a
Added CMP_ST_MTIME() and CMP_ST_CTIME() macros that compare also nanoseconds
Timo Sirainen <tss@iki.fi>
parents:
4909
diff
changeset
|
95 ((st1)->st_ctime == (st2)->st_ctime && \ |
7578
5766890f1275
Previous fix broke CMP_ST_CTIME() nsec checks.
Timo Sirainen <tss@iki.fi>
parents:
7577
diff
changeset
|
96 ST_NTIMES_EQUAL(ST_CTIME_NSEC(*(st1)), ST_CTIME_NSEC(*(st2)))) |
5782
2e6a977b1d6a
Added CMP_ST_MTIME() and CMP_ST_CTIME() macros that compare also nanoseconds
Timo Sirainen <tss@iki.fi>
parents:
4909
diff
changeset
|
97 |
0 | 98 /* strcasecmp(), strncasecmp() */ |
99 #ifndef HAVE_STRCASECMP | |
100 # ifdef HAVE_STRICMP | |
101 # define strcasecmp stricmp | |
102 # define strncasecmp strnicmp | |
103 # else | |
104 # define strcasecmp my_strcasecmp | |
105 # define strncasecmp my_strncasecmp | |
106 int my_strcasecmp(const char *s1, const char *s2); | |
107 int my_strncasecmp(const char *s1, const char *s2, size_t max_chars); | |
108 # endif | |
109 #endif | |
110 | |
111 #ifndef HAVE_INET_ATON | |
112 # include <sys/socket.h> | |
113 # include <netinet/in.h> | |
114 # include <arpa/inet.h> | |
115 # define inet_aton my_inet_aton | |
116 int my_inet_aton(const char *cp, struct in_addr *inp); | |
117 #endif | |
118 | |
119 #ifndef HAVE_VSYSLOG | |
120 # define vsyslog my_vsyslog | |
121 void my_vsyslog(int priority, const char *format, va_list args); | |
122 #endif | |
123 | |
5
1b34ec11fff8
Message data is parsed in blocks (no longer entirely mmap()ed). Several
Timo Sirainen <tss@iki.fi>
parents:
0
diff
changeset
|
124 #ifndef HAVE_GETPAGESIZE |
1b34ec11fff8
Message data is parsed in blocks (no longer entirely mmap()ed). Several
Timo Sirainen <tss@iki.fi>
parents:
0
diff
changeset
|
125 # define getpagesize my_getpagesize |
1b34ec11fff8
Message data is parsed in blocks (no longer entirely mmap()ed). Several
Timo Sirainen <tss@iki.fi>
parents:
0
diff
changeset
|
126 int my_getpagesize(void); |
1b34ec11fff8
Message data is parsed in blocks (no longer entirely mmap()ed). Several
Timo Sirainen <tss@iki.fi>
parents:
0
diff
changeset
|
127 #endif |
1b34ec11fff8
Message data is parsed in blocks (no longer entirely mmap()ed). Several
Timo Sirainen <tss@iki.fi>
parents:
0
diff
changeset
|
128 |
494
83d4617e1dca
Check fdatasync() from -lrt if it's not in libc (solaris). Also fallback to
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
129 #ifndef HAVE_FDATASYNC |
83d4617e1dca
Check fdatasync() from -lrt if it's not in libc (solaris). Also fallback to
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
130 # define fdatasync fsync |
83d4617e1dca
Check fdatasync() from -lrt if it's not in libc (solaris). Also fallback to
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
131 #endif |
83d4617e1dca
Check fdatasync() from -lrt if it's not in libc (solaris). Also fallback to
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
132 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1852
diff
changeset
|
133 struct const_iovec { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1852
diff
changeset
|
134 const void *iov_base; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1852
diff
changeset
|
135 size_t iov_len; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1852
diff
changeset
|
136 }; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1852
diff
changeset
|
137 |
410
1f0e7229ee58
Split IOBuffer into mmaped IBuffer, file IBuffer, memory data IBuffer and
Timo Sirainen <tss@iki.fi>
parents:
204
diff
changeset
|
138 #ifndef HAVE_STRUCT_IOVEC |
1f0e7229ee58
Split IOBuffer into mmaped IBuffer, file IBuffer, memory data IBuffer and
Timo Sirainen <tss@iki.fi>
parents:
204
diff
changeset
|
139 struct iovec { |
1f0e7229ee58
Split IOBuffer into mmaped IBuffer, file IBuffer, memory data IBuffer and
Timo Sirainen <tss@iki.fi>
parents:
204
diff
changeset
|
140 void *iov_base; |
1f0e7229ee58
Split IOBuffer into mmaped IBuffer, file IBuffer, memory data IBuffer and
Timo Sirainen <tss@iki.fi>
parents:
204
diff
changeset
|
141 size_t iov_len; |
1f0e7229ee58
Split IOBuffer into mmaped IBuffer, file IBuffer, memory data IBuffer and
Timo Sirainen <tss@iki.fi>
parents:
204
diff
changeset
|
142 }; |
1f0e7229ee58
Split IOBuffer into mmaped IBuffer, file IBuffer, memory data IBuffer and
Timo Sirainen <tss@iki.fi>
parents:
204
diff
changeset
|
143 #endif |
1f0e7229ee58
Split IOBuffer into mmaped IBuffer, file IBuffer, memory data IBuffer and
Timo Sirainen <tss@iki.fi>
parents:
204
diff
changeset
|
144 |
3623
085ebc6e341c
Use IOV_MAX instead of UIO_MAXIOV when available.
Timo Sirainen <tss@iki.fi>
parents:
3237
diff
changeset
|
145 /* IOV_MAX should be in limits.h nowadays. Linux still (2005) requires |
085ebc6e341c
Use IOV_MAX instead of UIO_MAXIOV when available.
Timo Sirainen <tss@iki.fi>
parents:
3237
diff
changeset
|
146 defining _XOPEN_SOURCE to get that value. UIO_MAXIOV works with it though, |
085ebc6e341c
Use IOV_MAX instead of UIO_MAXIOV when available.
Timo Sirainen <tss@iki.fi>
parents:
3237
diff
changeset
|
147 so use it instead. 16 is the lowest acceptable value for all OSes. */ |
085ebc6e341c
Use IOV_MAX instead of UIO_MAXIOV when available.
Timo Sirainen <tss@iki.fi>
parents:
3237
diff
changeset
|
148 #ifndef IOV_MAX |
085ebc6e341c
Use IOV_MAX instead of UIO_MAXIOV when available.
Timo Sirainen <tss@iki.fi>
parents:
3237
diff
changeset
|
149 # include <sys/uio.h> |
085ebc6e341c
Use IOV_MAX instead of UIO_MAXIOV when available.
Timo Sirainen <tss@iki.fi>
parents:
3237
diff
changeset
|
150 # ifdef UIO_MAXIOV |
085ebc6e341c
Use IOV_MAX instead of UIO_MAXIOV when available.
Timo Sirainen <tss@iki.fi>
parents:
3237
diff
changeset
|
151 # define IOV_MAX UIO_MAXIOV |
085ebc6e341c
Use IOV_MAX instead of UIO_MAXIOV when available.
Timo Sirainen <tss@iki.fi>
parents:
3237
diff
changeset
|
152 # else |
085ebc6e341c
Use IOV_MAX instead of UIO_MAXIOV when available.
Timo Sirainen <tss@iki.fi>
parents:
3237
diff
changeset
|
153 # define IOV_MAX 16 |
085ebc6e341c
Use IOV_MAX instead of UIO_MAXIOV when available.
Timo Sirainen <tss@iki.fi>
parents:
3237
diff
changeset
|
154 # endif |
085ebc6e341c
Use IOV_MAX instead of UIO_MAXIOV when available.
Timo Sirainen <tss@iki.fi>
parents:
3237
diff
changeset
|
155 #endif |
085ebc6e341c
Use IOV_MAX instead of UIO_MAXIOV when available.
Timo Sirainen <tss@iki.fi>
parents:
3237
diff
changeset
|
156 |
410
1f0e7229ee58
Split IOBuffer into mmaped IBuffer, file IBuffer, memory data IBuffer and
Timo Sirainen <tss@iki.fi>
parents:
204
diff
changeset
|
157 #ifndef HAVE_WRITEV |
1f0e7229ee58
Split IOBuffer into mmaped IBuffer, file IBuffer, memory data IBuffer and
Timo Sirainen <tss@iki.fi>
parents:
204
diff
changeset
|
158 # define writev my_writev |
1f0e7229ee58
Split IOBuffer into mmaped IBuffer, file IBuffer, memory data IBuffer and
Timo Sirainen <tss@iki.fi>
parents:
204
diff
changeset
|
159 struct iovec; |
704
fdc1fafb533d
writev()'s 3rd parameter is declared as "int" pretty much everywhere, so we
Timo Sirainen <tss@iki.fi>
parents:
696
diff
changeset
|
160 ssize_t my_writev(int fd, const struct iovec *iov, int iov_len); |
410
1f0e7229ee58
Split IOBuffer into mmaped IBuffer, file IBuffer, memory data IBuffer and
Timo Sirainen <tss@iki.fi>
parents:
204
diff
changeset
|
161 #endif |
1f0e7229ee58
Split IOBuffer into mmaped IBuffer, file IBuffer, memory data IBuffer and
Timo Sirainen <tss@iki.fi>
parents:
204
diff
changeset
|
162 |
7822
5abe05d7d093
HP-UX: pread() and pwrite() are broken, use our own implementation.
Timo Sirainen <tss@iki.fi>
parents:
7578
diff
changeset
|
163 #if !defined(HAVE_PREAD) || defined(PREAD_WRAPPERS) || defined(PREAD_BROKEN) |
1852
29729fa90bb2
more kludgeing to get pread/pwrite working
Timo Sirainen <tss@iki.fi>
parents:
1849
diff
changeset
|
164 # ifndef IN_COMPAT_C |
29729fa90bb2
more kludgeing to get pread/pwrite working
Timo Sirainen <tss@iki.fi>
parents:
1849
diff
changeset
|
165 # define pread my_pread |
29729fa90bb2
more kludgeing to get pread/pwrite working
Timo Sirainen <tss@iki.fi>
parents:
1849
diff
changeset
|
166 # define pwrite my_pwrite |
29729fa90bb2
more kludgeing to get pread/pwrite working
Timo Sirainen <tss@iki.fi>
parents:
1849
diff
changeset
|
167 # endif |
1793
82e19ad18784
If we don't have function foo, do it always as #define foo my_foo and create
Timo Sirainen <tss@iki.fi>
parents:
1669
diff
changeset
|
168 ssize_t my_pread(int fd, void *buf, size_t count, off_t offset); |
82e19ad18784
If we don't have function foo, do it always as #define foo my_foo and create
Timo Sirainen <tss@iki.fi>
parents:
1669
diff
changeset
|
169 ssize_t my_pwrite(int fd, const void *buf, size_t count, off_t offset); |
1669 | 170 #endif |
171 | |
2705
20dcf58cc05c
Add seteuid() wrapper for HP-UX
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
172 #ifndef HAVE_SETEUID |
2872
c0e2a38b7647
Check for libgen.h and if it's not found, use my_basename(). Also
Timo Sirainen <tss@iki.fi>
parents:
2705
diff
changeset
|
173 # define seteuid my_seteuid |
2705
20dcf58cc05c
Add seteuid() wrapper for HP-UX
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
174 int my_seteuid(uid_t euid); |
20dcf58cc05c
Add seteuid() wrapper for HP-UX
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
175 #endif |
20dcf58cc05c
Add seteuid() wrapper for HP-UX
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
176 |
3237
2f57438d9542
Added setegid() emulation for HP-UX.
Timo Sirainen <tss@iki.fi>
parents:
3002
diff
changeset
|
177 #ifndef HAVE_SETEGID |
2f57438d9542
Added setegid() emulation for HP-UX.
Timo Sirainen <tss@iki.fi>
parents:
3002
diff
changeset
|
178 # define setegid my_setegid |
2f57438d9542
Added setegid() emulation for HP-UX.
Timo Sirainen <tss@iki.fi>
parents:
3002
diff
changeset
|
179 int my_setegid(gid_t egid); |
2f57438d9542
Added setegid() emulation for HP-UX.
Timo Sirainen <tss@iki.fi>
parents:
3002
diff
changeset
|
180 #endif |
2f57438d9542
Added setegid() emulation for HP-UX.
Timo Sirainen <tss@iki.fi>
parents:
3002
diff
changeset
|
181 |
2872
c0e2a38b7647
Check for libgen.h and if it's not found, use my_basename(). Also
Timo Sirainen <tss@iki.fi>
parents:
2705
diff
changeset
|
182 #ifndef HAVE_LIBGEN_H |
c0e2a38b7647
Check for libgen.h and if it's not found, use my_basename(). Also
Timo Sirainen <tss@iki.fi>
parents:
2705
diff
changeset
|
183 # define basename my_basename |
c0e2a38b7647
Check for libgen.h and if it's not found, use my_basename(). Also
Timo Sirainen <tss@iki.fi>
parents:
2705
diff
changeset
|
184 char *my_basename(char *path); |
c0e2a38b7647
Check for libgen.h and if it's not found, use my_basename(). Also
Timo Sirainen <tss@iki.fi>
parents:
2705
diff
changeset
|
185 #endif |
c0e2a38b7647
Check for libgen.h and if it's not found, use my_basename(). Also
Timo Sirainen <tss@iki.fi>
parents:
2705
diff
changeset
|
186 |
3002
9f765960fca6
If strtoull() isn't supported, fallback to strtouq(). If that's not found
Timo Sirainen <tss@iki.fi>
parents:
2872
diff
changeset
|
187 #ifndef HAVE_STRTOULL |
9f765960fca6
If strtoull() isn't supported, fallback to strtouq(). If that's not found
Timo Sirainen <tss@iki.fi>
parents:
2872
diff
changeset
|
188 # define strtoull my_strtoull |
9f765960fca6
If strtoull() isn't supported, fallback to strtouq(). If that's not found
Timo Sirainen <tss@iki.fi>
parents:
2872
diff
changeset
|
189 unsigned long long int my_strtoull(const char *nptr, char **endptr, int base); |
9f765960fca6
If strtoull() isn't supported, fallback to strtouq(). If that's not found
Timo Sirainen <tss@iki.fi>
parents:
2872
diff
changeset
|
190 #endif |
7847
35877d1131db
Added more fallbacks if strtoll() or strtoull() isn't implemented
Timo Sirainen <tss@iki.fi>
parents:
7822
diff
changeset
|
191 #ifndef HAVE_STRTOLL |
35877d1131db
Added more fallbacks if strtoll() or strtoull() isn't implemented
Timo Sirainen <tss@iki.fi>
parents:
7822
diff
changeset
|
192 # define strtoll my_strtoll |
35877d1131db
Added more fallbacks if strtoll() or strtoull() isn't implemented
Timo Sirainen <tss@iki.fi>
parents:
7822
diff
changeset
|
193 unsigned long long int my_strtoll(const char *nptr, char **endptr, int base); |
35877d1131db
Added more fallbacks if strtoll() or strtoull() isn't implemented
Timo Sirainen <tss@iki.fi>
parents:
7822
diff
changeset
|
194 #endif |
3002
9f765960fca6
If strtoull() isn't supported, fallback to strtouq(). If that's not found
Timo Sirainen <tss@iki.fi>
parents:
2872
diff
changeset
|
195 |
7850
7f9f7fc02359
Support systems with non-C99 vsnprintf().
Timo Sirainen <tss@iki.fi>
parents:
7847
diff
changeset
|
196 #ifdef HAVE_OLD_VSNPRINTF |
7f9f7fc02359
Support systems with non-C99 vsnprintf().
Timo Sirainen <tss@iki.fi>
parents:
7847
diff
changeset
|
197 # include <stdio.h> |
7f9f7fc02359
Support systems with non-C99 vsnprintf().
Timo Sirainen <tss@iki.fi>
parents:
7847
diff
changeset
|
198 # define vsnprintf my_vsnprintf |
7f9f7fc02359
Support systems with non-C99 vsnprintf().
Timo Sirainen <tss@iki.fi>
parents:
7847
diff
changeset
|
199 int my_vsnprintf(char *str, size_t size, const char *format, va_list ap); |
7f9f7fc02359
Support systems with non-C99 vsnprintf().
Timo Sirainen <tss@iki.fi>
parents:
7847
diff
changeset
|
200 #endif |
7f9f7fc02359
Support systems with non-C99 vsnprintf().
Timo Sirainen <tss@iki.fi>
parents:
7847
diff
changeset
|
201 |
8076
bbfbc84f795c
Added clock_gettime() compatibility function for systems without it.
Timo Sirainen <tss@iki.fi>
parents:
7850
diff
changeset
|
202 #ifndef HAVE_CLOCK_GETTIME |
bbfbc84f795c
Added clock_gettime() compatibility function for systems without it.
Timo Sirainen <tss@iki.fi>
parents:
7850
diff
changeset
|
203 # include <time.h> |
bbfbc84f795c
Added clock_gettime() compatibility function for systems without it.
Timo Sirainen <tss@iki.fi>
parents:
7850
diff
changeset
|
204 # undef CLOCK_REALTIME |
bbfbc84f795c
Added clock_gettime() compatibility function for systems without it.
Timo Sirainen <tss@iki.fi>
parents:
7850
diff
changeset
|
205 # define CLOCK_REALTIME 1 |
bbfbc84f795c
Added clock_gettime() compatibility function for systems without it.
Timo Sirainen <tss@iki.fi>
parents:
7850
diff
changeset
|
206 # define clock_gettime my_clock_gettime |
bbfbc84f795c
Added clock_gettime() compatibility function for systems without it.
Timo Sirainen <tss@iki.fi>
parents:
7850
diff
changeset
|
207 int my_clock_gettime(int clk_id, struct timespec *tp); |
bbfbc84f795c
Added clock_gettime() compatibility function for systems without it.
Timo Sirainen <tss@iki.fi>
parents:
7850
diff
changeset
|
208 #endif |
bbfbc84f795c
Added clock_gettime() compatibility function for systems without it.
Timo Sirainen <tss@iki.fi>
parents:
7850
diff
changeset
|
209 |
0 | 210 /* ctype.h isn't safe with signed chars, |
211 use our own instead if really needed */ | |
696
c7f42a8e7176
Reverted back the isdigit()/etc. They're defined to get int argument, so we
Timo Sirainen <tss@iki.fi>
parents:
694
diff
changeset
|
212 #define i_toupper(x) ((char) toupper((int) (unsigned char) (x))) |
c7f42a8e7176
Reverted back the isdigit()/etc. They're defined to get int argument, so we
Timo Sirainen <tss@iki.fi>
parents:
694
diff
changeset
|
213 #define i_tolower(x) ((char) tolower((int) (unsigned char) (x))) |
c7f42a8e7176
Reverted back the isdigit()/etc. They're defined to get int argument, so we
Timo Sirainen <tss@iki.fi>
parents:
694
diff
changeset
|
214 #define i_isalnum(x) isalnum((int) (unsigned char) (x)) |
c7f42a8e7176
Reverted back the isdigit()/etc. They're defined to get int argument, so we
Timo Sirainen <tss@iki.fi>
parents:
694
diff
changeset
|
215 #define i_isalpha(x) isalpha((int) (unsigned char) (x)) |
c7f42a8e7176
Reverted back the isdigit()/etc. They're defined to get int argument, so we
Timo Sirainen <tss@iki.fi>
parents:
694
diff
changeset
|
216 #define i_isascii(x) isascii((int) (unsigned char) (x)) |
c7f42a8e7176
Reverted back the isdigit()/etc. They're defined to get int argument, so we
Timo Sirainen <tss@iki.fi>
parents:
694
diff
changeset
|
217 #define i_isblank(x) isblank((int) (unsigned char) (x)) |
c7f42a8e7176
Reverted back the isdigit()/etc. They're defined to get int argument, so we
Timo Sirainen <tss@iki.fi>
parents:
694
diff
changeset
|
218 #define i_iscntrl(x) iscntrl((int) (unsigned char) (x)) |
c7f42a8e7176
Reverted back the isdigit()/etc. They're defined to get int argument, so we
Timo Sirainen <tss@iki.fi>
parents:
694
diff
changeset
|
219 #define i_isdigit(x) isdigit((int) (unsigned char) (x)) |
c7f42a8e7176
Reverted back the isdigit()/etc. They're defined to get int argument, so we
Timo Sirainen <tss@iki.fi>
parents:
694
diff
changeset
|
220 #define i_isgraph(x) isgraph((int) (unsigned char) (x)) |
c7f42a8e7176
Reverted back the isdigit()/etc. They're defined to get int argument, so we
Timo Sirainen <tss@iki.fi>
parents:
694
diff
changeset
|
221 #define i_islower(x) islower((int) (unsigned char) (x)) |
c7f42a8e7176
Reverted back the isdigit()/etc. They're defined to get int argument, so we
Timo Sirainen <tss@iki.fi>
parents:
694
diff
changeset
|
222 #define i_isprint(x) isprint((int) (unsigned char) (x)) |
c7f42a8e7176
Reverted back the isdigit()/etc. They're defined to get int argument, so we
Timo Sirainen <tss@iki.fi>
parents:
694
diff
changeset
|
223 #define i_ispunct(x) ispunct((int) (unsigned char) (x)) |
c7f42a8e7176
Reverted back the isdigit()/etc. They're defined to get int argument, so we
Timo Sirainen <tss@iki.fi>
parents:
694
diff
changeset
|
224 #define i_isspace(x) isspace((int) (unsigned char) (x)) |
c7f42a8e7176
Reverted back the isdigit()/etc. They're defined to get int argument, so we
Timo Sirainen <tss@iki.fi>
parents:
694
diff
changeset
|
225 #define i_isupper(x) isupper((int) (unsigned char) (x)) |
c7f42a8e7176
Reverted back the isdigit()/etc. They're defined to get int argument, so we
Timo Sirainen <tss@iki.fi>
parents:
694
diff
changeset
|
226 #define i_isxdigit(x) isxdigit((int) (unsigned char) (x)) |
0 | 227 |
572
3c6a0cb061c6
EOVERFLOW doesn't exist everywhere, fallback it to EINVAL.
Timo Sirainen <tss@iki.fi>
parents:
494
diff
changeset
|
228 #ifndef EOVERFLOW |
3c6a0cb061c6
EOVERFLOW doesn't exist everywhere, fallback it to EINVAL.
Timo Sirainen <tss@iki.fi>
parents:
494
diff
changeset
|
229 # define EOVERFLOW EINVAL |
0 | 230 #endif |
572
3c6a0cb061c6
EOVERFLOW doesn't exist everywhere, fallback it to EINVAL.
Timo Sirainen <tss@iki.fi>
parents:
494
diff
changeset
|
231 |
1325
e026f8e4d241
Handle EDQUOT errno as "not enough disk space" like ENOSPC.
Timo Sirainen <tss@iki.fi>
parents:
908
diff
changeset
|
232 #ifdef EDQUOT |
e026f8e4d241
Handle EDQUOT errno as "not enough disk space" like ENOSPC.
Timo Sirainen <tss@iki.fi>
parents:
908
diff
changeset
|
233 # define ENOSPACE(errno) ((errno) == ENOSPC || (errno) == EDQUOT) |
e026f8e4d241
Handle EDQUOT errno as "not enough disk space" like ENOSPC.
Timo Sirainen <tss@iki.fi>
parents:
908
diff
changeset
|
234 #else |
e026f8e4d241
Handle EDQUOT errno as "not enough disk space" like ENOSPC.
Timo Sirainen <tss@iki.fi>
parents:
908
diff
changeset
|
235 # define ENOSPACE(errno) ((errno) == ENOSPC) |
572
3c6a0cb061c6
EOVERFLOW doesn't exist everywhere, fallback it to EINVAL.
Timo Sirainen <tss@iki.fi>
parents:
494
diff
changeset
|
236 #endif |
1325
e026f8e4d241
Handle EDQUOT errno as "not enough disk space" like ENOSPC.
Timo Sirainen <tss@iki.fi>
parents:
908
diff
changeset
|
237 |
1483
836c952e17ec
More robust error handling for mbox.
Timo Sirainen <tss@iki.fi>
parents:
1325
diff
changeset
|
238 /* EPERM is returned sometimes if device doesn't support such modification */ |
836c952e17ec
More robust error handling for mbox.
Timo Sirainen <tss@iki.fi>
parents:
1325
diff
changeset
|
239 #ifdef EROFS |
836c952e17ec
More robust error handling for mbox.
Timo Sirainen <tss@iki.fi>
parents:
1325
diff
changeset
|
240 # define ENOACCESS(errno) \ |
836c952e17ec
More robust error handling for mbox.
Timo Sirainen <tss@iki.fi>
parents:
1325
diff
changeset
|
241 ((errno) == EACCES || (errno) == EROFS || (errno) == EPERM) |
836c952e17ec
More robust error handling for mbox.
Timo Sirainen <tss@iki.fi>
parents:
1325
diff
changeset
|
242 #else |
836c952e17ec
More robust error handling for mbox.
Timo Sirainen <tss@iki.fi>
parents:
1325
diff
changeset
|
243 # define ENOACCESS(errno) ((errno) == EACCES || (errno) == EPERM) |
1325
e026f8e4d241
Handle EDQUOT errno as "not enough disk space" like ENOSPC.
Timo Sirainen <tss@iki.fi>
parents:
908
diff
changeset
|
244 #endif |
1483
836c952e17ec
More robust error handling for mbox.
Timo Sirainen <tss@iki.fi>
parents:
1325
diff
changeset
|
245 |
836c952e17ec
More robust error handling for mbox.
Timo Sirainen <tss@iki.fi>
parents:
1325
diff
changeset
|
246 #define ENOTFOUND(errno) \ |
836c952e17ec
More robust error handling for mbox.
Timo Sirainen <tss@iki.fi>
parents:
1325
diff
changeset
|
247 ((errno) == ENOENT || (errno) == ENOTDIR || (errno) == ELOOP) |
836c952e17ec
More robust error handling for mbox.
Timo Sirainen <tss@iki.fi>
parents:
1325
diff
changeset
|
248 |
4404
76e2177be0bf
Handle EMLINK and EPERM errors the same way as EXDEV when handling hardlink
Timo Sirainen <tss@iki.fi>
parents:
3932
diff
changeset
|
249 #define ECANTLINK(errno) \ |
76e2177be0bf
Handle EMLINK and EPERM errors the same way as EXDEV when handling hardlink
Timo Sirainen <tss@iki.fi>
parents:
3932
diff
changeset
|
250 ((errno) == EXDEV || (errno) == EMLINK || (errno) == EPERM) |
76e2177be0bf
Handle EMLINK and EPERM errors the same way as EXDEV when handling hardlink
Timo Sirainen <tss@iki.fi>
parents:
3932
diff
changeset
|
251 |
4909
5ea3e08af1e2
Added EDESTDIREXISTS() macro, and changed rename() calls to use it.
Timo Sirainen <tss@iki.fi>
parents:
4404
diff
changeset
|
252 /* EBUSY is given by some NFS implementations */ |
5ea3e08af1e2
Added EDESTDIREXISTS() macro, and changed rename() calls to use it.
Timo Sirainen <tss@iki.fi>
parents:
4404
diff
changeset
|
253 #define EDESTDIREXISTS(errno) \ |
5ea3e08af1e2
Added EDESTDIREXISTS() macro, and changed rename() calls to use it.
Timo Sirainen <tss@iki.fi>
parents:
4404
diff
changeset
|
254 ((errno) == EEXIST || (errno) == ENOTEMPTY || (errno) == EBUSY) |
5ea3e08af1e2
Added EDESTDIREXISTS() macro, and changed rename() calls to use it.
Timo Sirainen <tss@iki.fi>
parents:
4404
diff
changeset
|
255 |
1483
836c952e17ec
More robust error handling for mbox.
Timo Sirainen <tss@iki.fi>
parents:
1325
diff
changeset
|
256 #endif |