]>
Commit | Line | Data |
---|---|---|
e02ed81e ILT |
1 | /* 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> | |
324612b3 | 16 | #include <math.h> |
e0f69f36 | 17 | #include <pthread.h> |
e02ed81e | 18 | #include <stdint.h> |
e0f69f36 ILT |
19 | #include <stdlib.h> |
20 | #include <string.h> | |
e02ed81e | 21 | #include <sys/types.h> |
e0f69f36 | 22 | #include <sys/resource.h> |
d6f2922e | 23 | #include <sys/socket.h> |
e02ed81e ILT |
24 | #include <sys/stat.h> |
25 | #include <sys/time.h> | |
e0f69f36 | 26 | #include <sys/wait.h> |
d6f2922e | 27 | #include <time.h> |
e02ed81e ILT |
28 | #include <unistd.h> |
29 | ||
30 | #ifndef HAVE_OFF64_T | |
31 | typedef signed int off64_t __attribute__ ((mode (DI))); | |
32 | #endif | |
33 | ||
34 | #ifndef HAVE_LOFF_T | |
35 | typedef off64_t loff_t; | |
36 | #endif | |
37 | ||
d6f2922e ILT |
38 | #ifndef HAVE_ACCEPT4 |
39 | struct sockaddr; | |
40 | int | |
41 | accept4 (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 | ||
d5b18b0b ILT |
51 | #ifndef HAVE_DUP3 |
52 | int | |
53 | dup3 (int oldfd __attribute__ ((unused)), | |
54 | int newfd __attribute__ ((unused)), | |
134e6225 | 55 | int flags __attribute__ ((unused))) |
d5b18b0b ILT |
56 | { |
57 | errno = ENOSYS; | |
58 | return -1; | |
59 | } | |
60 | #endif | |
61 | ||
e02ed81e ILT |
62 | #ifndef HAVE_EPOLL_CREATE1 |
63 | int | |
64 | epoll_create1 (int flags __attribute__ ((unused))) | |
65 | { | |
1c69e5e2 ILT |
66 | errno = ENOSYS; |
67 | return -1; | |
e02ed81e ILT |
68 | } |
69 | #endif | |
70 | ||
71 | #ifndef HAVE_FACCESSAT | |
72 | int | |
73 | faccessat (int fd __attribute__ ((unused)), | |
74 | const char *pathname __attribute__ ((unused)), | |
75 | int mode __attribute__ ((unused)), | |
76 | int flags __attribute__ ((unused))) | |
5d46bf05 ILT |
77 | { |
78 | errno = ENOSYS; | |
79 | return -1; | |
80 | } | |
81 | #endif | |
82 | ||
83 | #ifndef HAVE_FALLOCATE | |
84 | int | |
85 | fallocate (int fd __attribute__ ((unused)), | |
86 | int mode __attribute__ ((unused)), | |
2ef7cdff | 87 | off_t offset __attribute__ ((unused)), |
5d46bf05 | 88 | off_t len __attribute__ ((unused))) |
e02ed81e | 89 | { |
1c69e5e2 ILT |
90 | errno = ENOSYS; |
91 | return -1; | |
e02ed81e ILT |
92 | } |
93 | #endif | |
94 | ||
95 | #ifndef HAVE_FCHMODAT | |
96 | int | |
97 | fchmodat (int dirfd __attribute__ ((unused)), | |
98 | const char *pathname __attribute__ ((unused)), | |
99 | mode_t mode __attribute__ ((unused)), | |
100 | int flags __attribute__ ((unused))) | |
101 | { | |
1c69e5e2 ILT |
102 | errno = ENOSYS; |
103 | return -1; | |
e02ed81e ILT |
104 | } |
105 | #endif | |
106 | ||
107 | #ifndef HAVE_FCHOWNAT | |
108 | int | |
109 | fchownat (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 | { | |
1c69e5e2 ILT |
115 | errno = ENOSYS; |
116 | return -1; | |
e02ed81e ILT |
117 | } |
118 | #endif | |
119 | ||
120 | #ifndef HAVE_FUTIMESAT | |
121 | int | |
122 | futimesat (int dirfd __attribute__ ((unused)), | |
123 | const char *pathname __attribute__ ((unused)), | |
124 | const struct timeval times[2] __attribute__ ((unused))) | |
125 | { | |
1c69e5e2 ILT |
126 | errno = ENOSYS; |
127 | return -1; | |
e02ed81e ILT |
128 | } |
129 | #endif | |
130 | ||
d5b18b0b ILT |
131 | #ifndef HAVE_GETXATTR |
132 | ssize_t | |
133 | getxattr (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 | ||
e02ed81e ILT |
143 | #ifndef HAVE_INOTIFY_ADD_WATCH |
144 | int | |
145 | inotify_add_watch (int fd __attribute__ ((unused)), | |
146 | const char* pathname __attribute__ ((unused)), | |
147 | uint32_t mask __attribute__ ((unused))) | |
148 | { | |
1c69e5e2 ILT |
149 | errno = ENOSYS; |
150 | return -1; | |
e02ed81e ILT |
151 | } |
152 | #endif | |
153 | ||
154 | #ifndef HAVE_INOTIFY_INIT | |
155 | int | |
156 | inotify_init (void) | |
157 | { | |
1c69e5e2 ILT |
158 | errno = ENOSYS; |
159 | return -1; | |
e02ed81e ILT |
160 | } |
161 | #endif | |
162 | ||
b65734ac ILT |
163 | #ifndef HAVE_INOTIFY_INIT1 |
164 | int | |
165 | inotify_init1 (int flags __attribute__ ((unused))) | |
166 | { | |
167 | errno = ENOSYS; | |
168 | return -1; | |
169 | } | |
170 | #endif | |
171 | ||
e02ed81e ILT |
172 | #ifndef HAVE_INOTIFY_RM_WATCH |
173 | int | |
174 | inotify_rm_watch (int fd __attribute__ ((unused)), | |
175 | uint32_t wd __attribute__ ((unused))) | |
176 | { | |
1c69e5e2 ILT |
177 | errno = ENOSYS; |
178 | return -1; | |
e02ed81e ILT |
179 | } |
180 | #endif | |
181 | ||
d5b18b0b ILT |
182 | #ifndef HAVE_LISTXATTR |
183 | ssize_t | |
184 | listxattr (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 | ||
e02ed81e ILT |
193 | #ifndef HAVE_MKDIRAT |
194 | int | |
195 | mkdirat (int dirfd __attribute__ ((unused)), | |
196 | const char *pathname __attribute__ ((unused)), | |
197 | mode_t mode __attribute__ ((unused))) | |
198 | { | |
1c69e5e2 ILT |
199 | errno = ENOSYS; |
200 | return -1; | |
e02ed81e ILT |
201 | } |
202 | #endif | |
203 | ||
204 | #ifndef HAVE_MKNODAT | |
205 | int | |
206 | mknodat (int dirfd __attribute__ ((unused)), | |
207 | const char *pathname __attribute__ ((unused)), | |
208 | mode_t mode __attribute__ ((unused)), | |
209 | dev_t dev __attribute__ ((unused))) | |
210 | { | |
1c69e5e2 ILT |
211 | errno = ENOSYS; |
212 | return -1; | |
e02ed81e ILT |
213 | } |
214 | #endif | |
215 | ||
216 | #ifndef HAVE_OPENAT | |
217 | int | |
218 | openat (int dirfd __attribute__ ((unused)), | |
219 | const char *pathname __attribute__ ((unused)), | |
220 | int oflag __attribute__ ((unused)), | |
221 | ...) | |
222 | { | |
1c69e5e2 ILT |
223 | errno = ENOSYS; |
224 | return -1; | |
e02ed81e ILT |
225 | } |
226 | #endif | |
227 | ||
d6f2922e ILT |
228 | #ifndef HAVE_PIPE2 |
229 | int | |
230 | pipe2 (int pipefd[2] __attribute__ ((unused)), | |
231 | int flags __attribute__ ((unused))) | |
232 | { | |
233 | errno = ENOSYS; | |
234 | return -1; | |
235 | } | |
236 | #endif | |
237 | ||
d5b18b0b ILT |
238 | #ifndef HAVE_REMOVEXATTR |
239 | int | |
240 | removexattr (const char *path __attribute__ ((unused)), | |
241 | const char *name __attribute__ ((unused))) | |
242 | { | |
243 | errno = ENOSYS; | |
244 | return -1; | |
245 | } | |
246 | #endif | |
247 | ||
e02ed81e ILT |
248 | #ifndef HAVE_RENAMEAT |
249 | int | |
250 | renameat (int olddirfd __attribute__ ((unused)), | |
251 | const char *oldpath __attribute__ ((unused)), | |
252 | int newdirfd __attribute__ ((unused)), | |
253 | const char *newpath __attribute__ ((unused))) | |
254 | { | |
1c69e5e2 ILT |
255 | errno = ENOSYS; |
256 | return -1; | |
e02ed81e ILT |
257 | } |
258 | #endif | |
259 | ||
d5b18b0b ILT |
260 | #ifndef HAVE_SETXATTR |
261 | int | |
262 | setxattr (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 | ||
e02ed81e ILT |
273 | #ifndef HAVE_SPLICE |
274 | int | |
275 | splice (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 | { | |
1c69e5e2 ILT |
282 | errno = ENOSYS; |
283 | return -1; | |
e02ed81e ILT |
284 | } |
285 | #endif | |
286 | ||
b65734ac ILT |
287 | #ifndef HAVE_SYNC_FILE_RANGE |
288 | int | |
289 | sync_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 | ||
e02ed81e ILT |
299 | #ifndef HAVE_TEE |
300 | int | |
301 | tee (int fd_in __attribute__ ((unused)), | |
302 | int fd_out __attribute__ ((unused)), | |
303 | size_t len __attribute__ ((unused)), | |
304 | unsigned int flags __attribute__ ((unused))) | |
305 | { | |
1c69e5e2 ILT |
306 | errno = ENOSYS; |
307 | return -1; | |
e02ed81e ILT |
308 | } |
309 | #endif | |
310 | ||
311 | #ifndef HAVE_UNLINKAT | |
312 | int | |
313 | unlinkat (int dirfd __attribute__ ((unused)), | |
314 | const char *pathname __attribute__ ((unused)), | |
315 | int flags __attribute__ ((unused))) | |
316 | { | |
1c69e5e2 ILT |
317 | errno = ENOSYS; |
318 | return -1; | |
e02ed81e ILT |
319 | } |
320 | #endif | |
321 | ||
322 | #ifndef HAVE_UNSHARE | |
323 | int | |
324 | unshare (int flags __attribute__ ((unused))) | |
325 | { | |
1c69e5e2 ILT |
326 | errno = ENOSYS; |
327 | return -1; | |
e02ed81e ILT |
328 | } |
329 | #endif | |
324612b3 | 330 | |
d6f2922e ILT |
331 | #ifndef HAVE_UTIMENSAT |
332 | struct timespec; | |
333 | int | |
334 | utimensat(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 | ||
f163907e ILT |
344 | |
345 | #ifndef HAVE_MINCORE | |
346 | int | |
347 | mincore(void *addr __attribute__ ((unused)), | |
348 | size_t length __attribute__ ((unused)), | |
349 | unsigned char *vec __attribute__ ((unused))) | |
350 | { | |
351 | errno = ENOSYS; | |
352 | return -1; | |
353 | } | |
354 | #endif | |
355 | ||
324612b3 ILT |
356 | /* Long double math functions. These are needed on old i386 systems |
357 | that don't have them in libm. The compiler translates calls to | |
358 | these functions on float64 to call an 80-bit floating point | |
359 | function instead, because when optimizing that function can be | |
360 | executed as an x87 instructure. However, when not optimizing, this | |
361 | translates into a call to the math function. So on systems that | |
362 | don't provide these functions, we provide a version that just calls | |
363 | the float64 version. */ | |
364 | ||
365 | #ifndef HAVE_COSL | |
366 | long double | |
367 | cosl (long double a) | |
368 | { | |
369 | return (long double) cos ((double) a); | |
370 | } | |
371 | #endif | |
372 | ||
373 | #ifndef HAVE_EXPL | |
374 | long double | |
375 | expl (long double a) | |
376 | { | |
377 | return (long double) exp ((double) a); | |
378 | } | |
379 | #endif | |
380 | ||
381 | #ifndef HAVE_LOGL | |
382 | long double | |
383 | logl (long double a) | |
384 | { | |
385 | return (long double) log ((double) a); | |
386 | } | |
387 | #endif | |
388 | ||
389 | #ifndef HAVE_SINL | |
390 | long double | |
391 | sinl (long double a) | |
392 | { | |
393 | return (long double) sin ((double) a); | |
394 | } | |
395 | #endif | |
396 | ||
397 | #ifndef HAVE_TANL | |
398 | long double | |
399 | tanl (long double a) | |
400 | { | |
401 | return (long double) tan ((double) a); | |
402 | } | |
403 | #endif | |
404 | ||
405 | #ifndef HAVE_ACOSL | |
406 | long double | |
407 | acosl (long double a) | |
408 | { | |
409 | return (long double) acos ((double) a); | |
410 | } | |
411 | #endif | |
412 | ||
413 | #ifndef HAVE_ASINL | |
414 | long double | |
415 | asinl (long double a) | |
416 | { | |
417 | return (long double) asin ((double) a); | |
418 | } | |
419 | #endif | |
420 | ||
421 | #ifndef HAVE_ATANL | |
422 | long double | |
423 | atanl (long double a) | |
424 | { | |
425 | return (long double) atan ((double) a); | |
426 | } | |
427 | #endif | |
428 | ||
429 | #ifndef HAVE_ATAN2L | |
430 | long double | |
431 | atan2l (long double a, long double b) | |
432 | { | |
433 | return (long double) atan2 ((double) a, (double) b); | |
434 | } | |
435 | #endif | |
436 | ||
437 | #ifndef HAVE_EXPM1L | |
438 | long double | |
439 | expm1l (long double a) | |
440 | { | |
441 | return (long double) expm1 ((double) a); | |
442 | } | |
443 | #endif | |
444 | ||
445 | #ifndef HAVE_LDEXPL | |
446 | long double | |
447 | ldexpl (long double a, int exp) | |
448 | { | |
449 | return (long double) ldexp ((double) a, exp); | |
450 | } | |
451 | #endif | |
452 | ||
453 | #ifndef HAVE_LOG10L | |
454 | long double | |
455 | log10l (long double a) | |
456 | { | |
457 | return (long double) log10 ((double) a); | |
458 | } | |
459 | #endif | |
460 | ||
461 | #ifndef HAVE_LOG1PL | |
462 | long double | |
463 | log1pl (long double a) | |
464 | { | |
465 | return (long double) log1p ((double) a); | |
466 | } | |
467 | #endif | |
e0f69f36 ILT |
468 | |
469 | #ifndef HAVE_STRERROR_R | |
470 | ||
471 | /* Some old systems do not have strerror_r. This is a replacement. | |
472 | It assumes that nothing else in the program calls strerror. */ | |
473 | ||
474 | static pthread_mutex_t strerror_lock = PTHREAD_MUTEX_INITIALIZER; | |
475 | ||
476 | int | |
477 | strerror_r (int errnum, char *buf, size_t buflen) | |
478 | { | |
479 | int i; | |
480 | char *errmsg; | |
481 | size_t len; | |
482 | int ret; | |
483 | ||
484 | i = pthread_mutex_lock (&strerror_lock); | |
485 | if (i != 0) | |
486 | abort (); | |
487 | ||
488 | errmsg = strerror (errnum); | |
489 | len = strlen (errmsg); | |
490 | if (len >= buflen) | |
491 | ret = ERANGE; | |
492 | else | |
493 | { | |
494 | memcpy (buf, errmsg, len + 1); | |
495 | ret = 0; | |
496 | } | |
497 | ||
498 | i = pthread_mutex_unlock (&strerror_lock); | |
499 | if (i != 0) | |
500 | abort (); | |
501 | ||
502 | return ret; | |
503 | } | |
504 | ||
505 | #endif /* ! HAVE_STRERROR_R */ | |
506 | ||
f163907e ILT |
507 | #ifndef HAVE_SYSCALL |
508 | int | |
6fa7df98 | 509 | syscall(int number __attribute__ ((unused)), ...) |
f163907e ILT |
510 | { |
511 | errno = ENOSYS; | |
512 | return -1; | |
513 | } | |
514 | #endif | |
515 | ||
e0f69f36 ILT |
516 | #ifndef HAVE_WAIT4 |
517 | ||
518 | /* Some old systems do not have wait4. This is a replacement that | |
519 | uses waitpid. */ | |
520 | ||
521 | pid_t | |
522 | wait4 (pid_t pid, int *status, int options, struct rusage *rusage __attribute__ ((unused))) | |
523 | { | |
524 | return waitpid (pid, status, options); | |
525 | } | |
526 | ||
527 | #endif |