go-nosys.c 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451
  1. /* go-nosys.c -- functions missing from system.
  2. Copyright 2012 The Go Authors. All rights reserved.
  3. Use of this source code is governed by a BSD-style
  4. license that can be found in the LICENSE file. */
  5. /* This file exists to provide definitions for functions that are
  6. missing from libc, according to the configure script. This permits
  7. the Go syscall package to not worry about whether the functions
  8. exist or not. */
  9. #include "config.h"
  10. #include <errno.h>
  11. #include <fcntl.h>
  12. #include <math.h>
  13. #include <stdint.h>
  14. #include <sys/types.h>
  15. #include <sys/socket.h>
  16. #include <sys/stat.h>
  17. #include <sys/time.h>
  18. #include <time.h>
  19. #include <unistd.h>
  20. #ifndef HAVE_OFF64_T
  21. typedef signed int off64_t __attribute__ ((mode (DI)));
  22. #endif
  23. #ifndef HAVE_LOFF_T
  24. typedef off64_t loff_t;
  25. #endif
  26. #ifndef HAVE_ACCEPT4
  27. struct sockaddr;
  28. int
  29. accept4 (int sockfd __attribute__ ((unused)),
  30. struct sockaddr *addr __attribute__ ((unused)),
  31. socklen_t *addrlen __attribute__ ((unused)),
  32. int flags __attribute__ ((unused)))
  33. {
  34. errno = ENOSYS;
  35. return -1;
  36. }
  37. #endif
  38. #ifndef HAVE_DUP3
  39. int
  40. dup3 (int oldfd __attribute__ ((unused)),
  41. int newfd __attribute__ ((unused)),
  42. int flags __attribute__ ((unused)))
  43. {
  44. errno = ENOSYS;
  45. return -1;
  46. }
  47. #endif
  48. #ifndef HAVE_EPOLL_CREATE1
  49. int
  50. epoll_create1 (int flags __attribute__ ((unused)))
  51. {
  52. errno = ENOSYS;
  53. return -1;
  54. }
  55. #endif
  56. #ifndef HAVE_FACCESSAT
  57. int
  58. faccessat (int fd __attribute__ ((unused)),
  59. const char *pathname __attribute__ ((unused)),
  60. int mode __attribute__ ((unused)),
  61. int flags __attribute__ ((unused)))
  62. {
  63. errno = ENOSYS;
  64. return -1;
  65. }
  66. #endif
  67. #ifndef HAVE_FALLOCATE
  68. int
  69. fallocate (int fd __attribute__ ((unused)),
  70. int mode __attribute__ ((unused)),
  71. off_t offset __attribute__ ((unused)),
  72. off_t len __attribute__ ((unused)))
  73. {
  74. errno = ENOSYS;
  75. return -1;
  76. }
  77. #endif
  78. #ifndef HAVE_FCHMODAT
  79. int
  80. fchmodat (int dirfd __attribute__ ((unused)),
  81. const char *pathname __attribute__ ((unused)),
  82. mode_t mode __attribute__ ((unused)),
  83. int flags __attribute__ ((unused)))
  84. {
  85. errno = ENOSYS;
  86. return -1;
  87. }
  88. #endif
  89. #ifndef HAVE_FCHOWNAT
  90. int
  91. fchownat (int dirfd __attribute__ ((unused)),
  92. const char *pathname __attribute__ ((unused)),
  93. uid_t owner __attribute__ ((unused)),
  94. gid_t group __attribute__ ((unused)),
  95. int flags __attribute__ ((unused)))
  96. {
  97. errno = ENOSYS;
  98. return -1;
  99. }
  100. #endif
  101. #ifndef HAVE_FUTIMESAT
  102. int
  103. futimesat (int dirfd __attribute__ ((unused)),
  104. const char *pathname __attribute__ ((unused)),
  105. const struct timeval times[2] __attribute__ ((unused)))
  106. {
  107. errno = ENOSYS;
  108. return -1;
  109. }
  110. #endif
  111. #ifndef HAVE_GETXATTR
  112. ssize_t
  113. getxattr (const char *path __attribute__ ((unused)),
  114. const char *name __attribute__ ((unused)),
  115. void *value __attribute__ ((unused)),
  116. size_t size __attribute__ ((unused)))
  117. {
  118. errno = ENOSYS;
  119. return -1;
  120. }
  121. #endif
  122. #ifndef HAVE_INOTIFY_ADD_WATCH
  123. int
  124. inotify_add_watch (int fd __attribute__ ((unused)),
  125. const char* pathname __attribute__ ((unused)),
  126. uint32_t mask __attribute__ ((unused)))
  127. {
  128. errno = ENOSYS;
  129. return -1;
  130. }
  131. #endif
  132. #ifndef HAVE_INOTIFY_INIT
  133. int
  134. inotify_init (void)
  135. {
  136. errno = ENOSYS;
  137. return -1;
  138. }
  139. #endif
  140. #ifndef HAVE_INOTIFY_INIT1
  141. int
  142. inotify_init1 (int flags __attribute__ ((unused)))
  143. {
  144. errno = ENOSYS;
  145. return -1;
  146. }
  147. #endif
  148. #ifndef HAVE_INOTIFY_RM_WATCH
  149. int
  150. inotify_rm_watch (int fd __attribute__ ((unused)),
  151. uint32_t wd __attribute__ ((unused)))
  152. {
  153. errno = ENOSYS;
  154. return -1;
  155. }
  156. #endif
  157. #ifndef HAVE_LISTXATTR
  158. ssize_t
  159. listxattr (const char *path __attribute__ ((unused)),
  160. char *list __attribute__ ((unused)),
  161. size_t size __attribute__ ((unused)))
  162. {
  163. errno = ENOSYS;
  164. return -1;
  165. }
  166. #endif
  167. #ifndef HAVE_MKDIRAT
  168. int
  169. mkdirat (int dirfd __attribute__ ((unused)),
  170. const char *pathname __attribute__ ((unused)),
  171. mode_t mode __attribute__ ((unused)))
  172. {
  173. errno = ENOSYS;
  174. return -1;
  175. }
  176. #endif
  177. #ifndef HAVE_MKNODAT
  178. int
  179. mknodat (int dirfd __attribute__ ((unused)),
  180. const char *pathname __attribute__ ((unused)),
  181. mode_t mode __attribute__ ((unused)),
  182. dev_t dev __attribute__ ((unused)))
  183. {
  184. errno = ENOSYS;
  185. return -1;
  186. }
  187. #endif
  188. #ifndef HAVE_OPENAT
  189. int
  190. openat (int dirfd __attribute__ ((unused)),
  191. const char *pathname __attribute__ ((unused)),
  192. int oflag __attribute__ ((unused)),
  193. ...)
  194. {
  195. errno = ENOSYS;
  196. return -1;
  197. }
  198. #endif
  199. #ifndef HAVE_PIPE2
  200. int
  201. pipe2 (int pipefd[2] __attribute__ ((unused)),
  202. int flags __attribute__ ((unused)))
  203. {
  204. errno = ENOSYS;
  205. return -1;
  206. }
  207. #endif
  208. #ifndef HAVE_REMOVEXATTR
  209. int
  210. removexattr (const char *path __attribute__ ((unused)),
  211. const char *name __attribute__ ((unused)))
  212. {
  213. errno = ENOSYS;
  214. return -1;
  215. }
  216. #endif
  217. #ifndef HAVE_RENAMEAT
  218. int
  219. renameat (int olddirfd __attribute__ ((unused)),
  220. const char *oldpath __attribute__ ((unused)),
  221. int newdirfd __attribute__ ((unused)),
  222. const char *newpath __attribute__ ((unused)))
  223. {
  224. errno = ENOSYS;
  225. return -1;
  226. }
  227. #endif
  228. #ifndef HAVE_SETXATTR
  229. int
  230. setxattr (const char *path __attribute__ ((unused)),
  231. const char *name __attribute__ ((unused)),
  232. const void *value __attribute__ ((unused)),
  233. size_t size __attribute__ ((unused)),
  234. int flags __attribute__ ((unused)))
  235. {
  236. errno = ENOSYS;
  237. return -1;
  238. }
  239. #endif
  240. #ifndef HAVE_SPLICE
  241. int
  242. splice (int fd __attribute__ ((unused)),
  243. loff_t *off_in __attribute__ ((unused)),
  244. int fd_out __attribute__ ((unused)),
  245. loff_t *off_out __attribute__ ((unused)),
  246. size_t len __attribute__ ((unused)),
  247. unsigned int flags __attribute__ ((unused)))
  248. {
  249. errno = ENOSYS;
  250. return -1;
  251. }
  252. #endif
  253. #ifndef HAVE_SYNC_FILE_RANGE
  254. int
  255. sync_file_range (int fd __attribute__ ((unused)),
  256. off64_t offset __attribute__ ((unused)),
  257. off64_t nbytes __attribute__ ((unused)),
  258. unsigned int flags __attribute__ ((unused)))
  259. {
  260. errno = ENOSYS;
  261. return -1;
  262. }
  263. #endif
  264. #ifndef HAVE_TEE
  265. int
  266. tee (int fd_in __attribute__ ((unused)),
  267. int fd_out __attribute__ ((unused)),
  268. size_t len __attribute__ ((unused)),
  269. unsigned int flags __attribute__ ((unused)))
  270. {
  271. errno = ENOSYS;
  272. return -1;
  273. }
  274. #endif
  275. #ifndef HAVE_UNLINKAT
  276. int
  277. unlinkat (int dirfd __attribute__ ((unused)),
  278. const char *pathname __attribute__ ((unused)),
  279. int flags __attribute__ ((unused)))
  280. {
  281. errno = ENOSYS;
  282. return -1;
  283. }
  284. #endif
  285. #ifndef HAVE_UNSHARE
  286. int
  287. unshare (int flags __attribute__ ((unused)))
  288. {
  289. errno = ENOSYS;
  290. return -1;
  291. }
  292. #endif
  293. #ifndef HAVE_UTIMENSAT
  294. struct timespec;
  295. int
  296. utimensat(int dirfd __attribute__ ((unused)),
  297. const char *pathname __attribute__ ((unused)),
  298. const struct timespec times[2] __attribute__ ((unused)),
  299. int flags __attribute__ ((unused)))
  300. {
  301. errno = ENOSYS;
  302. return -1;
  303. }
  304. #endif
  305. /* Long double math functions. These are needed on old i386 systems
  306. that don't have them in libm. The compiler translates calls to
  307. these functions on float64 to call an 80-bit floating point
  308. function instead, because when optimizing that function can be
  309. executed as an x87 instructure. However, when not optimizing, this
  310. translates into a call to the math function. So on systems that
  311. don't provide these functions, we provide a version that just calls
  312. the float64 version. */
  313. #ifndef HAVE_COSL
  314. long double
  315. cosl (long double a)
  316. {
  317. return (long double) cos ((double) a);
  318. }
  319. #endif
  320. #ifndef HAVE_EXPL
  321. long double
  322. expl (long double a)
  323. {
  324. return (long double) exp ((double) a);
  325. }
  326. #endif
  327. #ifndef HAVE_LOGL
  328. long double
  329. logl (long double a)
  330. {
  331. return (long double) log ((double) a);
  332. }
  333. #endif
  334. #ifndef HAVE_SINL
  335. long double
  336. sinl (long double a)
  337. {
  338. return (long double) sin ((double) a);
  339. }
  340. #endif
  341. #ifndef HAVE_TANL
  342. long double
  343. tanl (long double a)
  344. {
  345. return (long double) tan ((double) a);
  346. }
  347. #endif
  348. #ifndef HAVE_ACOSL
  349. long double
  350. acosl (long double a)
  351. {
  352. return (long double) acos ((double) a);
  353. }
  354. #endif
  355. #ifndef HAVE_ASINL
  356. long double
  357. asinl (long double a)
  358. {
  359. return (long double) asin ((double) a);
  360. }
  361. #endif
  362. #ifndef HAVE_ATANL
  363. long double
  364. atanl (long double a)
  365. {
  366. return (long double) atan ((double) a);
  367. }
  368. #endif
  369. #ifndef HAVE_ATAN2L
  370. long double
  371. atan2l (long double a, long double b)
  372. {
  373. return (long double) atan2 ((double) a, (double) b);
  374. }
  375. #endif
  376. #ifndef HAVE_EXPM1L
  377. long double
  378. expm1l (long double a)
  379. {
  380. return (long double) expm1 ((double) a);
  381. }
  382. #endif
  383. #ifndef HAVE_LDEXPL
  384. long double
  385. ldexpl (long double a, int exp)
  386. {
  387. return (long double) ldexp ((double) a, exp);
  388. }
  389. #endif
  390. #ifndef HAVE_LOG10L
  391. long double
  392. log10l (long double a)
  393. {
  394. return (long double) log10 ((double) a);
  395. }
  396. #endif
  397. #ifndef HAVE_LOG1PL
  398. long double
  399. log1pl (long double a)
  400. {
  401. return (long double) log1p ((double) a);
  402. }
  403. #endif