blob: be8fb3ef19b936f1baf07e37081bb096fd3f7f66 [file] [log] [blame]
Ian Lance Taylore02ed812012-01-26 20:24:01 +00001/* go-nosys.c -- functions missing from system.
2
3 Copyright 2012 The Go Authors. All rights reserved.
4 Use of this source code is governed by a BSD-style
5 license that can be found in the LICENSE file. */
6
7/* This file exists to provide definitions for functions that are
8 missing from libc, according to the configure script. This permits
9 the Go syscall package to not worry about whether the functions
10 exist or not. */
11
12#include "config.h"
13
14#include <errno.h>
15#include <fcntl.h>
Ian Lance Taylor324612b2012-04-27 16:38:11 +000016#include <math.h>
Ian Lance Taylore0f69f32016-08-06 00:36:33 +000017#include <pthread.h>
Ian Lance Taylore02ed812012-01-26 20:24:01 +000018#include <stdint.h>
Ian Lance Taylore0f69f32016-08-06 00:36:33 +000019#include <stdlib.h>
20#include <string.h>
Ian Lance Taylore02ed812012-01-26 20:24:01 +000021#include <sys/types.h>
Ian Lance Taylore0f69f32016-08-06 00:36:33 +000022#include <sys/resource.h>
Ian Lance Taylord6f29222013-01-29 20:52:43 +000023#include <sys/socket.h>
Ian Lance Taylore02ed812012-01-26 20:24:01 +000024#include <sys/stat.h>
25#include <sys/time.h>
Ian Lance Taylore0f69f32016-08-06 00:36:33 +000026#include <sys/wait.h>
Ian Lance Taylord6f29222013-01-29 20:52:43 +000027#include <time.h>
Ian Lance Taylore02ed812012-01-26 20:24:01 +000028#include <unistd.h>
29
30#ifndef HAVE_OFF64_T
31typedef signed int off64_t __attribute__ ((mode (DI)));
32#endif
33
34#ifndef HAVE_LOFF_T
35typedef off64_t loff_t;
36#endif
37
Ian Lance Taylord6f29222013-01-29 20:52:43 +000038#ifndef HAVE_ACCEPT4
39struct sockaddr;
40int
41accept4 (int sockfd __attribute__ ((unused)),
42 struct sockaddr *addr __attribute__ ((unused)),
43 socklen_t *addrlen __attribute__ ((unused)),
44 int flags __attribute__ ((unused)))
45{
46 errno = ENOSYS;
47 return -1;
48}
49#endif
50
Ian Lance Taylord5b18b02013-10-17 18:41:12 +000051#ifndef HAVE_DUP3
52int
53dup3 (int oldfd __attribute__ ((unused)),
54 int newfd __attribute__ ((unused)),
Ian Lance Taylor134e6222013-10-18 13:26:40 +000055 int flags __attribute__ ((unused)))
Ian Lance Taylord5b18b02013-10-17 18:41:12 +000056{
57 errno = ENOSYS;
58 return -1;
59}
60#endif
61
Ian Lance Taylore02ed812012-01-26 20:24:01 +000062#ifndef HAVE_EPOLL_CREATE1
63int
64epoll_create1 (int flags __attribute__ ((unused)))
65{
Ian Lance Taylor1c69e5e2012-02-02 22:58:54 +000066 errno = ENOSYS;
67 return -1;
Ian Lance Taylore02ed812012-01-26 20:24:01 +000068}
69#endif
70
71#ifndef HAVE_FACCESSAT
72int
73faccessat (int fd __attribute__ ((unused)),
74 const char *pathname __attribute__ ((unused)),
75 int mode __attribute__ ((unused)),
76 int flags __attribute__ ((unused)))
77{
Ian Lance Taylor1c69e5e2012-02-02 22:58:54 +000078 errno = ENOSYS;
79 return -1;
Ian Lance Taylore02ed812012-01-26 20:24:01 +000080}
81#endif
82
Ian Lance Taylor5d46bf02012-02-18 01:22:02 +000083#ifndef HAVE_FALLOCATE
84int
85fallocate (int fd __attribute__ ((unused)),
86 int mode __attribute__ ((unused)),
Ian Lance Taylor2ef7cdf2012-02-25 02:11:29 +000087 off_t offset __attribute__ ((unused)),
Ian Lance Taylor5d46bf02012-02-18 01:22:02 +000088 off_t len __attribute__ ((unused)))
89{
90 errno = ENOSYS;
91 return -1;
92}
93#endif
94
Ian Lance Taylore02ed812012-01-26 20:24:01 +000095#ifndef HAVE_FCHMODAT
96int
97fchmodat (int dirfd __attribute__ ((unused)),
98 const char *pathname __attribute__ ((unused)),
99 mode_t mode __attribute__ ((unused)),
100 int flags __attribute__ ((unused)))
101{
Ian Lance Taylor1c69e5e2012-02-02 22:58:54 +0000102 errno = ENOSYS;
103 return -1;
Ian Lance Taylore02ed812012-01-26 20:24:01 +0000104}
105#endif
106
107#ifndef HAVE_FCHOWNAT
108int
109fchownat (int dirfd __attribute__ ((unused)),
110 const char *pathname __attribute__ ((unused)),
111 uid_t owner __attribute__ ((unused)),
112 gid_t group __attribute__ ((unused)),
113 int flags __attribute__ ((unused)))
114{
Ian Lance Taylor1c69e5e2012-02-02 22:58:54 +0000115 errno = ENOSYS;
116 return -1;
Ian Lance Taylore02ed812012-01-26 20:24:01 +0000117}
118#endif
119
120#ifndef HAVE_FUTIMESAT
121int
122futimesat (int dirfd __attribute__ ((unused)),
123 const char *pathname __attribute__ ((unused)),
124 const struct timeval times[2] __attribute__ ((unused)))
125{
Ian Lance Taylor1c69e5e2012-02-02 22:58:54 +0000126 errno = ENOSYS;
127 return -1;
Ian Lance Taylore02ed812012-01-26 20:24:01 +0000128}
129#endif
130
Ian Lance Taylord5b18b02013-10-17 18:41:12 +0000131#ifndef HAVE_GETXATTR
132ssize_t
133getxattr (const char *path __attribute__ ((unused)),
134 const char *name __attribute__ ((unused)),
135 void *value __attribute__ ((unused)),
136 size_t size __attribute__ ((unused)))
137{
138 errno = ENOSYS;
139 return -1;
140}
141#endif
142
Ian Lance Taylore02ed812012-01-26 20:24:01 +0000143#ifndef HAVE_INOTIFY_ADD_WATCH
144int
145inotify_add_watch (int fd __attribute__ ((unused)),
146 const char* pathname __attribute__ ((unused)),
147 uint32_t mask __attribute__ ((unused)))
148{
Ian Lance Taylor1c69e5e2012-02-02 22:58:54 +0000149 errno = ENOSYS;
150 return -1;
Ian Lance Taylore02ed812012-01-26 20:24:01 +0000151}
152#endif
153
154#ifndef HAVE_INOTIFY_INIT
155int
156inotify_init (void)
157{
Ian Lance Taylor1c69e5e2012-02-02 22:58:54 +0000158 errno = ENOSYS;
159 return -1;
Ian Lance Taylore02ed812012-01-26 20:24:01 +0000160}
161#endif
162
Ian Lance Taylorb65734a2012-02-29 20:02:31 +0000163#ifndef HAVE_INOTIFY_INIT1
164int
165inotify_init1 (int flags __attribute__ ((unused)))
166{
167 errno = ENOSYS;
168 return -1;
169}
170#endif
171
Ian Lance Taylore02ed812012-01-26 20:24:01 +0000172#ifndef HAVE_INOTIFY_RM_WATCH
173int
174inotify_rm_watch (int fd __attribute__ ((unused)),
175 uint32_t wd __attribute__ ((unused)))
176{
Ian Lance Taylor1c69e5e2012-02-02 22:58:54 +0000177 errno = ENOSYS;
178 return -1;
Ian Lance Taylore02ed812012-01-26 20:24:01 +0000179}
180#endif
181
Ian Lance Taylord5b18b02013-10-17 18:41:12 +0000182#ifndef HAVE_LISTXATTR
183ssize_t
184listxattr (const char *path __attribute__ ((unused)),
185 char *list __attribute__ ((unused)),
186 size_t size __attribute__ ((unused)))
187{
188 errno = ENOSYS;
189 return -1;
190}
191#endif
192
Ian Lance Taylore02ed812012-01-26 20:24:01 +0000193#ifndef HAVE_MKDIRAT
194int
195mkdirat (int dirfd __attribute__ ((unused)),
196 const char *pathname __attribute__ ((unused)),
197 mode_t mode __attribute__ ((unused)))
198{
Ian Lance Taylor1c69e5e2012-02-02 22:58:54 +0000199 errno = ENOSYS;
200 return -1;
Ian Lance Taylore02ed812012-01-26 20:24:01 +0000201}
202#endif
203
204#ifndef HAVE_MKNODAT
205int
206mknodat (int dirfd __attribute__ ((unused)),
207 const char *pathname __attribute__ ((unused)),
208 mode_t mode __attribute__ ((unused)),
209 dev_t dev __attribute__ ((unused)))
210{
Ian Lance Taylor1c69e5e2012-02-02 22:58:54 +0000211 errno = ENOSYS;
212 return -1;
Ian Lance Taylore02ed812012-01-26 20:24:01 +0000213}
214#endif
215
216#ifndef HAVE_OPENAT
217int
218openat (int dirfd __attribute__ ((unused)),
219 const char *pathname __attribute__ ((unused)),
220 int oflag __attribute__ ((unused)),
221 ...)
222{
Ian Lance Taylor1c69e5e2012-02-02 22:58:54 +0000223 errno = ENOSYS;
224 return -1;
Ian Lance Taylore02ed812012-01-26 20:24:01 +0000225}
226#endif
227
Ian Lance Taylord6f29222013-01-29 20:52:43 +0000228#ifndef HAVE_PIPE2
229int
230pipe2 (int pipefd[2] __attribute__ ((unused)),
231 int flags __attribute__ ((unused)))
232{
233 errno = ENOSYS;
234 return -1;
235}
236#endif
237
Ian Lance Taylord5b18b02013-10-17 18:41:12 +0000238#ifndef HAVE_REMOVEXATTR
239int
240removexattr (const char *path __attribute__ ((unused)),
241 const char *name __attribute__ ((unused)))
242{
243 errno = ENOSYS;
244 return -1;
245}
246#endif
247
Ian Lance Taylore02ed812012-01-26 20:24:01 +0000248#ifndef HAVE_RENAMEAT
249int
250renameat (int olddirfd __attribute__ ((unused)),
251 const char *oldpath __attribute__ ((unused)),
252 int newdirfd __attribute__ ((unused)),
253 const char *newpath __attribute__ ((unused)))
254{
Ian Lance Taylor1c69e5e2012-02-02 22:58:54 +0000255 errno = ENOSYS;
256 return -1;
Ian Lance Taylore02ed812012-01-26 20:24:01 +0000257}
258#endif
259
Ian Lance Taylord5b18b02013-10-17 18:41:12 +0000260#ifndef HAVE_SETXATTR
261int
262setxattr (const char *path __attribute__ ((unused)),
263 const char *name __attribute__ ((unused)),
264 const void *value __attribute__ ((unused)),
265 size_t size __attribute__ ((unused)),
266 int flags __attribute__ ((unused)))
267{
268 errno = ENOSYS;
269 return -1;
270}
271#endif
272
Ian Lance Taylore02ed812012-01-26 20:24:01 +0000273#ifndef HAVE_SPLICE
274int
275splice (int fd __attribute__ ((unused)),
276 loff_t *off_in __attribute__ ((unused)),
277 int fd_out __attribute__ ((unused)),
278 loff_t *off_out __attribute__ ((unused)),
279 size_t len __attribute__ ((unused)),
280 unsigned int flags __attribute__ ((unused)))
281{
Ian Lance Taylor1c69e5e2012-02-02 22:58:54 +0000282 errno = ENOSYS;
283 return -1;
Ian Lance Taylore02ed812012-01-26 20:24:01 +0000284}
285#endif
286
Ian Lance Taylorb65734a2012-02-29 20:02:31 +0000287#ifndef HAVE_SYNC_FILE_RANGE
288int
289sync_file_range (int fd __attribute__ ((unused)),
290 off64_t offset __attribute__ ((unused)),
291 off64_t nbytes __attribute__ ((unused)),
292 unsigned int flags __attribute__ ((unused)))
293{
294 errno = ENOSYS;
295 return -1;
296}
297#endif
298
Ian Lance Taylore02ed812012-01-26 20:24:01 +0000299#ifndef HAVE_TEE
300int
301tee (int fd_in __attribute__ ((unused)),
302 int fd_out __attribute__ ((unused)),
303 size_t len __attribute__ ((unused)),
304 unsigned int flags __attribute__ ((unused)))
305{
Ian Lance Taylor1c69e5e2012-02-02 22:58:54 +0000306 errno = ENOSYS;
307 return -1;
Ian Lance Taylore02ed812012-01-26 20:24:01 +0000308}
309#endif
310
311#ifndef HAVE_UNLINKAT
312int
313unlinkat (int dirfd __attribute__ ((unused)),
314 const char *pathname __attribute__ ((unused)),
315 int flags __attribute__ ((unused)))
316{
Ian Lance Taylor1c69e5e2012-02-02 22:58:54 +0000317 errno = ENOSYS;
318 return -1;
Ian Lance Taylore02ed812012-01-26 20:24:01 +0000319}
320#endif
321
322#ifndef HAVE_UNSHARE
323int
324unshare (int flags __attribute__ ((unused)))
325{
Ian Lance Taylor1c69e5e2012-02-02 22:58:54 +0000326 errno = ENOSYS;
327 return -1;
Ian Lance Taylore02ed812012-01-26 20:24:01 +0000328}
329#endif
Ian Lance Taylor324612b2012-04-27 16:38:11 +0000330
Ian Lance Taylord6f29222013-01-29 20:52:43 +0000331#ifndef HAVE_UTIMENSAT
332struct timespec;
333int
334utimensat(int dirfd __attribute__ ((unused)),
335 const char *pathname __attribute__ ((unused)),
336 const struct timespec times[2] __attribute__ ((unused)),
337 int flags __attribute__ ((unused)))
338{
339 errno = ENOSYS;
340 return -1;
341}
342#endif
343
Ian Lance Taylor324612b2012-04-27 16:38:11 +0000344/* Long double math functions. These are needed on old i386 systems
345 that don't have them in libm. The compiler translates calls to
346 these functions on float64 to call an 80-bit floating point
347 function instead, because when optimizing that function can be
348 executed as an x87 instructure. However, when not optimizing, this
349 translates into a call to the math function. So on systems that
350 don't provide these functions, we provide a version that just calls
351 the float64 version. */
352
353#ifndef HAVE_COSL
354long double
355cosl (long double a)
356{
357 return (long double) cos ((double) a);
358}
359#endif
360
361#ifndef HAVE_EXPL
362long double
363expl (long double a)
364{
365 return (long double) exp ((double) a);
366}
367#endif
368
369#ifndef HAVE_LOGL
370long double
371logl (long double a)
372{
373 return (long double) log ((double) a);
374}
375#endif
376
377#ifndef HAVE_SINL
378long double
379sinl (long double a)
380{
381 return (long double) sin ((double) a);
382}
383#endif
384
385#ifndef HAVE_TANL
386long double
387tanl (long double a)
388{
389 return (long double) tan ((double) a);
390}
391#endif
392
393#ifndef HAVE_ACOSL
394long double
395acosl (long double a)
396{
397 return (long double) acos ((double) a);
398}
399#endif
400
401#ifndef HAVE_ASINL
402long double
403asinl (long double a)
404{
405 return (long double) asin ((double) a);
406}
407#endif
408
409#ifndef HAVE_ATANL
410long double
411atanl (long double a)
412{
413 return (long double) atan ((double) a);
414}
415#endif
416
417#ifndef HAVE_ATAN2L
418long double
419atan2l (long double a, long double b)
420{
421 return (long double) atan2 ((double) a, (double) b);
422}
423#endif
424
425#ifndef HAVE_EXPM1L
426long double
427expm1l (long double a)
428{
429 return (long double) expm1 ((double) a);
430}
431#endif
432
433#ifndef HAVE_LDEXPL
434long double
435ldexpl (long double a, int exp)
436{
437 return (long double) ldexp ((double) a, exp);
438}
439#endif
440
441#ifndef HAVE_LOG10L
442long double
443log10l (long double a)
444{
445 return (long double) log10 ((double) a);
446}
447#endif
448
449#ifndef HAVE_LOG1PL
450long double
451log1pl (long double a)
452{
453 return (long double) log1p ((double) a);
454}
455#endif
Ian Lance Taylore0f69f32016-08-06 00:36:33 +0000456
457#ifndef HAVE_STRERROR_R
458
459/* Some old systems do not have strerror_r. This is a replacement.
460 It assumes that nothing else in the program calls strerror. */
461
462static pthread_mutex_t strerror_lock = PTHREAD_MUTEX_INITIALIZER;
463
464int
465strerror_r (int errnum, char *buf, size_t buflen)
466{
467 int i;
468 char *errmsg;
469 size_t len;
470 int ret;
471
472 i = pthread_mutex_lock (&strerror_lock);
473 if (i != 0)
474 abort ();
475
476 errmsg = strerror (errnum);
477 len = strlen (errmsg);
478 if (len >= buflen)
479 ret = ERANGE;
480 else
481 {
482 memcpy (buf, errmsg, len + 1);
483 ret = 0;
484 }
485
486 i = pthread_mutex_unlock (&strerror_lock);
487 if (i != 0)
488 abort ();
489
490 return ret;
491}
492
493#endif /* ! HAVE_STRERROR_R */
494
495#ifndef HAVE_WAIT4
496
497/* Some old systems do not have wait4. This is a replacement that
498 uses waitpid. */
499
500pid_t
501wait4 (pid_t pid, int *status, int options, struct rusage *rusage __attribute__ ((unused)))
502{
503 return waitpid (pid, status, options);
504}
505
506#endif