unix: add ioctl functions on Dragonfly

Add IoctlGetInt/IoctlSetInt, IoctlGetTermios/IoctlSetTermios and
IoctlGetWinsize/IoctlSetWinsize on Dragonfly. These are similar to the
already existing implementations on Linux, Darwin and Solaris.

Change-Id: I5a5a7ef69f02e01a4216779df5c927f241e5cec0
Reviewed-on: https://go-review.googlesource.com/76170
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
diff --git a/unix/syscall_dragonfly.go b/unix/syscall_dragonfly.go
index 25eeada..49c65ea 100644
--- a/unix/syscall_dragonfly.go
+++ b/unix/syscall_dragonfly.go
@@ -130,6 +130,45 @@
 	return ENOSYS
 }
 
+//sys	ioctl(fd int, req uint, arg uintptr) (err error)
+
+// ioctl itself should not be exposed directly, but additional get/set
+// functions for specific types are permissible.
+
+// IoctlSetInt performs an ioctl operation which sets an integer value
+// on fd, using the specified request number.
+func IoctlSetInt(fd int, req uint, value int) error {
+	return ioctl(fd, req, uintptr(value))
+}
+
+func IoctlSetWinsize(fd int, req uint, value *Winsize) error {
+	return ioctl(fd, req, uintptr(unsafe.Pointer(value)))
+}
+
+func IoctlSetTermios(fd int, req uint, value *Termios) error {
+	return ioctl(fd, req, uintptr(unsafe.Pointer(value)))
+}
+
+// IoctlGetInt performs an ioctl operation which gets an integer value
+// from fd, using the specified request number.
+func IoctlGetInt(fd int, req uint) (int, error) {
+	var value int
+	err := ioctl(fd, req, uintptr(unsafe.Pointer(&value)))
+	return value, err
+}
+
+func IoctlGetWinsize(fd int, req uint) (*Winsize, error) {
+	var value Winsize
+	err := ioctl(fd, req, uintptr(unsafe.Pointer(&value)))
+	return &value, err
+}
+
+func IoctlGetTermios(fd int, req uint) (*Termios, error) {
+	var value Termios
+	err := ioctl(fd, req, uintptr(unsafe.Pointer(&value)))
+	return &value, err
+}
+
 /*
  * Exposed directly
  */
@@ -230,7 +269,6 @@
 // Getlogin
 // Sigpending
 // Sigaltstack
-// Ioctl
 // Reboot
 // Execve
 // Vfork
diff --git a/unix/types_dragonfly.go b/unix/types_dragonfly.go
index 78ce32a..46d7da9 100644
--- a/unix/types_dragonfly.go
+++ b/unix/types_dragonfly.go
@@ -242,6 +242,8 @@
 
 type Termios C.struct_termios
 
+type Winsize C.struct_winsize
+
 // fchmodat-like syscalls.
 
 const (
diff --git a/unix/zsyscall_dragonfly_amd64.go b/unix/zsyscall_dragonfly_amd64.go
index 7576147..2ed340f 100644
--- a/unix/zsyscall_dragonfly_amd64.go
+++ b/unix/zsyscall_dragonfly_amd64.go
@@ -423,6 +423,16 @@
 
 // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
 
+func ioctl(fd int, req uint, arg uintptr) (err error) {
+	_, _, e1 := Syscall(SYS_IOCTL, uintptr(fd), uintptr(req), uintptr(arg))
+	if e1 != 0 {
+		err = errnoErr(e1)
+	}
+	return
+}
+
+// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
+
 func Access(path string, mode uint32) (err error) {
 	var _p0 *byte
 	_p0, err = BytePtrFromString(path)
diff --git a/unix/ztypes_dragonfly_amd64.go b/unix/ztypes_dragonfly_amd64.go
index ab515c3..1ca0e3e 100644
--- a/unix/ztypes_dragonfly_amd64.go
+++ b/unix/ztypes_dragonfly_amd64.go
@@ -442,6 +442,13 @@
 	Ospeed uint32
 }
 
+type Winsize struct {
+	Row    uint16
+	Col    uint16
+	Xpixel uint16
+	Ypixel uint16
+}
+
 const (
 	AT_FDCWD            = 0xfffafdcd
 	AT_SYMLINK_NOFOLLOW = 0x1