From 418593def3022a9a89bfbc503bbbe877b3757910 Mon Sep 17 00:00:00 2001 From: Vitaly Potyarkin Date: Fri, 28 Apr 2023 10:09:56 +0000 Subject: [PATCH] Restore support for older Go versions When compiled with go older than 1.12 creack/pty will not include a fix for blocking Read() and will be prone to data races - but at least it will work For more information see issues: #88 #114 #156 #162 --- io_test.go | 3 +++ ioctl.go | 5 ++--- ioctl_legacy.go | 10 ++++++++++ 3 files changed, 15 insertions(+), 3 deletions(-) create mode 100644 ioctl_legacy.go diff --git a/io_test.go b/io_test.go index f68956c..57fbd3d 100644 --- a/io_test.go +++ b/io_test.go @@ -1,3 +1,6 @@ +//go:build go1.12 +// +build go1.12 + package pty import ( diff --git a/ioctl.go b/ioctl.go index 4e26755..60ac9b8 100644 --- a/ioctl.go +++ b/ioctl.go @@ -1,7 +1,6 @@ -//go:build !windows -// +build !windows +//go:build !windows && go1.12 +// +build !windows,go1.12 -// package pty import "os" diff --git a/ioctl_legacy.go b/ioctl_legacy.go new file mode 100644 index 0000000..f00b1a1 --- /dev/null +++ b/ioctl_legacy.go @@ -0,0 +1,10 @@ +//go:build !windows && !go1.12 +// +build !windows,!go1.12 + +package pty + +import "os" + +func ioctl(f *os.File, cmd, ptr uintptr) error { + return ioctl_inner(f.Fd(), cmd, ptr) // fall back to blocking io (old behavior) +}