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