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