make librpc compatible with eglibc, unconditionally enable it for packages that need...
[openwrt/svn-archive/archive.git] / package / librpc / patches / 100-compat_fix.patch
1 --- a/compat.h
2 +++ /dev/null
3 @@ -1,32 +0,0 @@
4 -#ifndef __UCLIBC_COMPAT_H
5 -#define __UCLIBC_COMPAT_H
6 -
7 -#define _XOPEN_SOURCE
8 -#define _GNU_SOURCE
9 -
10 -#include <features.h>
11 -#include <errno.h>
12 -
13 -#undef __UCLIBC_HAS_THREADS__
14 -#include <bits/uClibc_mutex.h>
15 -#include <sys/poll.h>
16 -
17 -#if 0
18 -#undef __UCLIBC_MUTEX_LOCK
19 -#undef __UCLIBC_MUTEX_UNLOCK
20 -#define __UCLIBC_MUTEX_LOCK(M) pthread_mutex_lock(&(M))
21 -#define __UCLIBC_MUTEX_UNLOCK(M) pthread_mutex_unlock(&(M))
22 -#endif
23 -
24 -#define smallint int
25 -
26 -#define _(...) __VA_ARGS__
27 -#define internal_function
28 -#define attribute_hidden
29 -#define attribute_unused
30 -#define attribute_noreturn
31 -#define libc_hidden_def(...)
32 -
33 -#define __set_errno(_val) errno = _val
34 -
35 -#endif
36 --- a/rcmd.c
37 +++ b/rcmd.c
38 @@ -85,7 +85,6 @@ static char sccsid[] = "@(#)rcmd.c 8.3 (
39 #include <wchar.h>
40 #endif
41 #include <sys/uio.h>
42 -#include <bits/uClibc_alloc.h>
43
44
45 /* some forward declarations */
46 --- a/create_xid.c
47 +++ b/create_xid.c
48 @@ -28,7 +28,6 @@
49
50 /* The RPC code is not threadsafe, but new code should be threadsafe. */
51
52 -#include <bits/uClibc_mutex.h>
53 __UCLIBC_MUTEX_STATIC(mylock, PTHREAD_MUTEX_INITIALIZER);
54
55 static smallint is_initialized;
56 --- a/getrpcent.c
57 +++ b/getrpcent.c
58 @@ -257,7 +257,6 @@ static struct rpcent *interpret(register
59
60 #if defined(__UCLIBC_HAS_REENTRANT_RPC__)
61
62 -#include <bits/uClibc_mutex.h>
63 __UCLIBC_MUTEX_STATIC(mylock, PTHREAD_MUTEX_INITIALIZER);
64
65
66 --- a/CMakeLists.txt
67 +++ b/CMakeLists.txt
68 @@ -1,7 +1,7 @@
69 cmake_minimum_required(VERSION 2.6)
70
71 PROJECT(rpc C)
72 -ADD_DEFINITIONS(-Os -Wall --std=gnu99 -g3 -I. -include compat.h)
73 +ADD_DEFINITIONS(-Os -Wall --std=gnu99 -g3 -I. -include rpc/compat.h)
74
75 FILE(GLOB SOURCES *.c)
76
77 --- a/rpc/types.h
78 +++ b/rpc/types.h
79 @@ -33,6 +33,8 @@
80 #ifndef _RPC_TYPES_H
81 #define _RPC_TYPES_H 1
82
83 +#include "compat.h"
84 +
85 #ifdef _LIBC
86 /* Some adjustments to make the libc source from glibc
87 * compile more easily with uClibc... */
88 --- a/clnt_perror.c
89 +++ b/clnt_perror.c
90 @@ -246,7 +246,7 @@ clnt_sperror (CLIENT * rpch, const char
91
92 case RPC_CANTSEND:
93 case RPC_CANTRECV:
94 - __glibc_strerror_r (e.re_errno, chrbuf, sizeof chrbuf);
95 + strerror_r (e.re_errno, chrbuf, sizeof chrbuf);
96 len = sprintf (str, "; errno = %s", chrbuf);
97 str += len;
98 break;
99 @@ -336,7 +336,7 @@ clnt_spcreateerror (const char *msg)
100 (void) strcpy(cp, " - ");
101 cp += strlen(cp);
102
103 - __glibc_strerror_r (ce->cf_error.re_errno, chrbuf, sizeof chrbuf);
104 + strerror_r (ce->cf_error.re_errno, chrbuf, sizeof chrbuf);
105 (void) strcpy(cp, chrbuf);
106 cp += strlen(cp);
107 break;
108 --- a/rpc_thread.c
109 +++ b/rpc_thread.c
110 @@ -13,9 +13,6 @@
111
112 #ifdef __UCLIBC_HAS_THREADS__
113
114 -#include <bits/libc-tsd.h>
115 -#include <bits/libc-lock.h>
116 -
117 /* Variable used in non-threaded applications or for the first thread. */
118 static struct rpc_thread_variables __libc_tsd_RPC_VARS_mem;
119 __libc_tsd_define (, RPC_VARS)
120 @@ -52,16 +49,17 @@ rpc_thread_multi (void)
121 __libc_tsd_set (RPC_VARS, &__libc_tsd_RPC_VARS_mem);
122 }
123
124 +__UCLIBC_MUTEX_STATIC(mylock, PTHREAD_MUTEX_INITIALIZER);
125
126 struct rpc_thread_variables attribute_hidden *
127 __rpc_thread_variables (void)
128 {
129 - __libc_once_define (static, once);
130 struct rpc_thread_variables *tvp;
131
132 + __UCLIBC_MUTEX_LOCK(mylock);
133 tvp = __libc_tsd_get (RPC_VARS);
134 if (tvp == NULL) {
135 - __libc_once (once, rpc_thread_multi);
136 + rpc_thread_multi();
137 tvp = __libc_tsd_get (RPC_VARS);
138 if (tvp == NULL) {
139 tvp = calloc (1, sizeof *tvp);
140 @@ -71,6 +69,7 @@ __rpc_thread_variables (void)
141 tvp = __libc_tsd_get (RPC_VARS);
142 }
143 }
144 + __UCLIBC_MUTEX_UNLOCK(mylock);
145 return tvp;
146 }
147
148 --- /dev/null
149 +++ b/rpc/compat.h
150 @@ -0,0 +1,53 @@
151 +#ifndef __UCLIBC_COMPAT_H
152 +#define __UCLIBC_COMPAT_H
153 +
154 +#define _XOPEN_SOURCE
155 +#define _GNU_SOURCE
156 +
157 +#include <features.h>
158 +#include <errno.h>
159 +
160 +#ifndef __UCLIBC_HAS_THREADS__
161 +#define __UCLIBC_HAS_THREADS__
162 +#endif
163 +
164 +#include <sys/poll.h>
165 +#include <pthread.h>
166 +
167 +#ifdef __UCLIBC__
168 +#include <bits/libc-lock.h>
169 +#else
170 +#undef __UCLIBC_MUTEX_STATIC
171 +#undef __UCLIBC_MUTEX_LOCK
172 +#undef __UCLIBC_MUTEX_UNLOCK
173 +#define __UCLIBC_MUTEX_STATIC(M,I) static pthread_mutex_t M = I
174 +#define __UCLIBC_MUTEX_LOCK(M) pthread_mutex_lock(&(M))
175 +#define __UCLIBC_MUTEX_UNLOCK(M) pthread_mutex_unlock(&(M))
176 +#endif
177 +
178 +#define smallint int
179 +
180 +#define _(...) __VA_ARGS__
181 +#define internal_function
182 +#define attribute_hidden
183 +#define attribute_unused
184 +#define attribute_noreturn
185 +#define libc_hidden_def(...)
186 +
187 +#ifndef libc_hidden_proto
188 +#define libc_hidden_proto(name, attrs...)
189 +#endif
190 +
191 +#define __set_errno(_val) errno = _val
192 +
193 +# define attribute_tls_model_ie __attribute__ ((tls_model ("initial-exec")))
194 +
195 +# define __libc_tsd_define(CLASS, KEY) \
196 + CLASS __thread void *__libc_tsd_##KEY attribute_tls_model_ie;
197 +
198 +# define __libc_tsd_address(KEY) (&__libc_tsd_##KEY)
199 +# define __libc_tsd_get(KEY) (__libc_tsd_##KEY)
200 +# define __libc_tsd_set(KEY, VALUE) (__libc_tsd_##KEY = (VALUE))
201 +
202 +
203 +#endif