github.com/guyezi/gofrontend@v0.0.0-20200228202240-7a62a49e62c0/libgo/runtime/go-varargs.c (about) 1 /* go-varargs.c -- functions for calling C varargs functions. 2 3 Copyright 2013 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 #include "config.h" 8 9 #include <errno.h> 10 #include <stdint.h> 11 #include <unistd.h> 12 #include <sys/types.h> 13 #include <fcntl.h> 14 #include <sys/ioctl.h> 15 #ifdef HAVE_SYSCALL_H 16 #include <syscall.h> 17 #endif 18 #ifdef HAVE_SYS_SYSCALL_H 19 #include <sys/syscall.h> 20 #endif 21 22 /* The syscall package calls C functions. The Go compiler can not 23 represent a C varargs functions. On some systems it's important 24 that the declaration of a function match the call. This function 25 holds non-varargs C functions that the Go code can call. */ 26 27 int 28 __go_open (char *path, int mode, mode_t perm) 29 { 30 return open (path, mode, perm); 31 } 32 33 int 34 __go_fcntl (int fd, int cmd, int arg) 35 { 36 return fcntl (fd, cmd, arg); 37 } 38 39 int 40 __go_fcntl_flock (int fd, int cmd, struct flock *arg) 41 { 42 return fcntl (fd, cmd, arg); 43 } 44 45 // This is for the net package. We use uintptr_t to make sure that 46 // the types match, since the Go and C "int" types are not the same. 47 struct go_fcntl_ret { 48 uintptr_t r; 49 uintptr_t err; 50 }; 51 52 struct go_fcntl_ret 53 __go_fcntl_uintptr (uintptr_t fd, uintptr_t cmd, uintptr_t arg) 54 { 55 int r; 56 struct go_fcntl_ret ret; 57 58 r = fcntl ((int) fd, (int) cmd, (int) arg); 59 ret.r = (uintptr_t) r; 60 if (r < 0) 61 ret.err = (uintptr_t) errno; 62 else 63 ret.err = 0; 64 return ret; 65 } 66 67 int 68 __go_ioctl (int d, int request, int arg) 69 { 70 return ioctl (d, request, arg); 71 } 72 73 int 74 __go_ioctl_ptr (int d, int request, void *arg) 75 { 76 return ioctl (d, request, arg); 77 } 78 79 #ifdef HAVE_OPEN64 80 81 int 82 __go_open64 (char *path, int mode, mode_t perm) 83 { 84 return open64 (path, mode, perm); 85 } 86 87 #endif 88 89 #ifdef HAVE_OPENAT 90 91 int 92 __go_openat (int fd, char *path, int flags, mode_t mode) 93 { 94 return openat (fd, path, flags, mode); 95 } 96 97 #endif 98 99 #ifdef HAVE_SYSCALL 100 101 // __go_syscall6 is called by both the runtime and syscall packages. 102 // We use uintptr_t to make sure that the types match, since the Go 103 // and C "int" types are not the same. 104 105 uintptr_t 106 __go_syscall6(uintptr_t flag, uintptr_t a1, uintptr_t a2, uintptr_t a3, 107 uintptr_t a4, uintptr_t a5, uintptr_t a6) 108 { 109 return syscall (flag, a1, a2, a3, a4, a5, a6); 110 } 111 112 #endif