100-compat_fix.patch 4.9 KB

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