CC=${CC:-gcc}
+if [[ "$GOOS" -eq "solaris" ]]; then
+ # Assumes GNU versions of utilities in PATH.
+ export PATH=/usr/gnu/bin:$PATH
+fi
+
uname=$(uname)
includes_Darwin='
'
includes_SunOS='
+#include <limits.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/sockio.h>
exit 1;
}
+if($ENV{'GOARCH'} eq "" || $ENV{'GOOS'} eq "") {
+ print STDERR "GOARCH or GOOS not defined in environment\n";
+ exit 1;
+}
+
sub parseparamlist($) {
my ($list) = @_;
$list =~ s/^\s*//;
my $package = "";
my $text = "";
-my $vars = "";
my $dynimports = "";
my $linknames = "";
+my @vars = ();
while(<>) {
chomp;
s/\s+/ /g;
}
# System call pointer variable name.
- my $sysvarname = "libc_$sysname";
+ my $sysvarname = "libc_${sysname}";
my $strconvfunc = "BytePtrFromString";
my $strconvtype = "*byte";
- # Library proc address variable.
$sysname =~ y/A-Z/a-z/; # All libc functions are lowercase.
- if($vars eq "") {
- $vars .= "\t$sysvarname";
- } else {
- $vars .= ",\n\t$sysvarname";
- }
- $dynimports .= "//go:cgo_import_dynamic $sysvarname $sysname \"$modname.so\"\n";
- $linknames .= "//go:linkname $sysvarname $sysvarname\n";
+
+ # Runtime import of function to allow cross-platform builds.
+ $dynimports .= "//go:cgo_import_dynamic ${sysvarname} ${sysname} \"$modname.so\"\n";
+ # Link symbol to proc address variable.
+ $linknames .= "//go:linkname ${sysvarname} ${sysvarname}\n";
+ # Library proc address variable.
+ push @vars, $sysvarname;
# Go function header.
$out = join(', ', @out);
// $cmdline
// MACHINE GENERATED BY THE COMMAND ABOVE; DO NOT EDIT
+// +build $ENV{'GOARCH'},$ENV{'GOOS'}
+
package $package
import "unsafe"
print "import \"syscall\"\n" if $package ne "syscall";
-print <<EOF;
+my $vardecls = "\t" . join(",\n\t", @vars);
+$vardecls .= " libcFunc";
+
+chomp($_=<<EOF);
$dynimports
$linknames
type libcFunc uintptr
var (
-$vars libcFunc
+$vardecls
)
$text
-
EOF
+print $_;
exit 0;
return anyToSockaddr(&rsa)
}
-// The const provides a compile-time constant so clients
-// can adjust to whether there is a working Getwd and avoid
-// even linking this function into the binary. See ../os/getwd.go.
-const ImplementsGetwd = false
+const ImplementsGetwd = true
-func Getwd() (string, error) { return "", ENOTSUP }
+//sys Getcwd(buf []byte) (n int, err error)
+
+func Getwd() (wd string, err error) {
+ var buf [PathMax]byte
+ // Getcwd will return an error if it failed for any reason.
+ _, err = Getcwd(buf[0:])
+ if err != nil {
+ return "", err
+ }
+ n := clen(buf[:])
+ if n < 1 {
+ return "", EINVAL
+ }
+ return string(buf[:n]), nil
+}
/*
* Wrapped
/*
#define KERNEL
+// These defines ensure that builds done on newer versions of Solaris are
+// backwards-compatible with older versions of Solaris and
+// OpenSolaris-based derivatives.
+#define __USE_SUNOS_SOCKETS__ // msghdr
+#define __USE_LEGACY_PROTOTYPES__ // iovec
#include <dirent.h>
#include <fcntl.h>
+#include <limits.h>
#include <signal.h>
#include <termios.h>
#include <stdio.h>
sizeofInt = C.sizeof_int
sizeofLong = C.sizeof_long
sizeofLongLong = C.sizeof_longlong
+ PathMax = C.PATH_MAX
)
// Basic types
import "unsafe"
+//go:cgo_import_dynamic libc_Getcwd getcwd "libc.so"
//go:cgo_import_dynamic libc_getgroups getgroups "libc.so"
//go:cgo_import_dynamic libc_setgroups setgroups "libc.so"
//go:cgo_import_dynamic libc_fcntl fcntl "libc.so"
//go:cgo_import_dynamic libc_recvfrom recvfrom "libsocket.so"
//go:cgo_import_dynamic libc_recvmsg recvmsg "libsocket.so"
+//go:linkname libc_Getcwd libc_Getcwd
//go:linkname libc_getgroups libc_getgroups
//go:linkname libc_setgroups libc_setgroups
//go:linkname libc_fcntl libc_fcntl
type libcFunc uintptr
var (
+ libc_Getcwd,
libc_getgroups,
libc_setgroups,
libc_fcntl,
libc_recvmsg libcFunc
)
+func Getcwd(buf []byte) (n int, err error) {
+ var _p0 *byte
+ if len(buf) > 0 {
+ _p0 = &buf[0]
+ }
+ r0, _, e1 := sysvicall6(uintptr(unsafe.Pointer(&libc_Getcwd)), 2, uintptr(unsafe.Pointer(_p0)), uintptr(len(buf)), 0, 0, 0, 0)
+ n = int(r0)
+ if e1 != 0 {
+ err = errnoErr(e1)
+ }
+ return
+}
+
func getgroups(ngid int, gid *_Gid_t) (n int, err error) {
r0, _, e1 := rawSysvicall6(uintptr(unsafe.Pointer(&libc_getgroups)), 2, uintptr(ngid), uintptr(unsafe.Pointer(gid)), 0, 0, 0, 0)
n = int(r0)
sizeofInt = 0x4
sizeofLong = 0x8
sizeofLongLong = 0x8
+ PathMax = 0x400
)
type (