// +build darwin freebsd linux netbsd openbsd

package flags

import (
	"syscall"
	"unsafe"
)

// #include <sys/ioctl.h>
// enum { _GO_TIOCGWINSZ = TIOCGWINSZ };
import "C"

type winsize struct {
	ws_row, ws_col       uint16
	ws_xpixel, ws_ypixel uint16
}

func getTerminalColumns() int {
	ws := winsize{}

	syscall.Syscall(syscall.SYS_IOCTL,
		uintptr(0),
		uintptr(C._GO_TIOCGWINSZ),
		uintptr(unsafe.Pointer(&ws)))

	return int(ws.ws_col)
}

// +build darwin freebsd linux netbsd openbsd

package flags

import (
	"syscall"
	"unsafe"
)

type winsize struct {
	ws_row, ws_col       uint16
	ws_xpixel, ws_ypixel uint16
}

func getTerminalColumns() int {
	ws := winsize{}

	syscall.Syscall(syscall.SYS_IOCTL,
		uintptr(0),
		uintptr(0x5413),
		uintptr(unsafe.Pointer(&ws)))

	return int(ws.ws_col)
}

--- 
+++ 
@@ -6,6 +6,10 @@
 	"syscall"
 	"unsafe"
 )
+
+// #include <sys/ioctl.h>
+// enum { _GO_TIOCGWINSZ = TIOCGWINSZ };
+import "C"
 
 type winsize struct {
 	ws_row, ws_col       uint16
@@ -17,7 +21,7 @@
 
 	syscall.Syscall(syscall.SYS_IOCTL,
 		uintptr(0),
-		uintptr(0x5413),
+		uintptr(C._GO_TIOCGWINSZ),
 		uintptr(unsafe.Pointer(&ws)))
 
 	return int(ws.ws_col)
Use the TIOCGWINSZ macro from C to determine correct value of option
