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
16 /* The syscall package calls C functions. The Go compiler can not
17 represent a C varargs functions. On some systems it's important
18 that the declaration of a function match the call. This function
19 holds non-varargs C functions that the Go code can call. */
20
21 int
__go_open(char * path,int mode,mode_t perm)22 __go_open (char *path, int mode, mode_t perm)
23 {
24 return open (path, mode, perm);
25 }
26
27 int
__go_fcntl(int fd,int cmd,int arg)28 __go_fcntl (int fd, int cmd, int arg)
29 {
30 return fcntl (fd, cmd, arg);
31 }
32
33 int
__go_fcntl_flock(int fd,int cmd,struct flock * arg)34 __go_fcntl_flock (int fd, int cmd, struct flock *arg)
35 {
36 return fcntl (fd, cmd, arg);
37 }
38
39 // This is for the net package. We use uintptr_t to make sure that
40 // the types match, since the Go and C "int" types are not the same.
41 struct go_fcntl_ret {
42 uintptr_t r;
43 uintptr_t err;
44 };
45
46 struct go_fcntl_ret
__go_fcntl_uintptr(uintptr_t fd,uintptr_t cmd,uintptr_t arg)47 __go_fcntl_uintptr (uintptr_t fd, uintptr_t cmd, uintptr_t arg)
48 {
49 int r;
50 struct go_fcntl_ret ret;
51
52 r = fcntl ((int) fd, (int) cmd, (int) arg);
53 ret.r = (uintptr_t) r;
54 if (r < 0)
55 ret.err = (uintptr_t) errno;
56 else
57 ret.err = 0;
58 return ret;
59 }
60
61 int
__go_ioctl(int d,int request,int arg)62 __go_ioctl (int d, int request, int arg)
63 {
64 return ioctl (d, request, arg);
65 }
66
67 int
__go_ioctl_ptr(int d,int request,void * arg)68 __go_ioctl_ptr (int d, int request, void *arg)
69 {
70 return ioctl (d, request, arg);
71 }
72
73 #ifdef HAVE_OPEN64
74
75 int
__go_open64(char * path,int mode,mode_t perm)76 __go_open64 (char *path, int mode, mode_t perm)
77 {
78 return open64 (path, mode, perm);
79 }
80
81 #endif
82
83 #ifdef HAVE_OPENAT
84
85 int
__go_openat(int fd,char * path,int flags,mode_t mode)86 __go_openat (int fd, char *path, int flags, mode_t mode)
87 {
88 return openat (fd, path, flags, mode);
89 }
90
91 #endif
92