Go version
go version go1.23.1 linux/amd64
Output of go env
in your module/workspace:
GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/tstirrat/.cache/go-build'
GOENV='/home/tstirrat/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/tstirrat/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/tstirrat/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/home/tstirrat/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.23.1.linux-amd64'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/home/tstirrat/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.23.1.linux-amd64/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.23.1'
GODEBUG=''
GOTELEMETRY='local'
GOTELEMETRYDIR='/home/tstirrat/.config/go/telemetry'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/home/tstirrat/authzed/zed/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build3673824231=/tmp/go-build -gno-record-gcc-switches'
What did you do?
The documentation recommends getting the file descriptor with the following:
oldState, err := term.MakeRaw(int(os.Stdin.Fd()))
os.Stdin.Fd
returns a uintptr
, which can't (technically) be safely cast to an int. I was under the impression that the only negative fd value is -1
, which would indicate an error state and wouldn't be valid as an input. Is there a reason (other than legacy) that the fd
args in this lib are int
s rather than uint
s or uintptr
s?
What did you see happen?
I had to do an awkward cast.
What did you expect to see?
I'd expect the types to line up nicely.
Comment From: gabyhelp
Related Issues and Documentation
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)
Comment From: tstirrat15
I read the issue above, and it talks about making an assumption that an fd on a unix system can be cast to an int, but it sounds like that isn't necessarily the case for Windows. The binary in question is supposed to be cross-platform, including windows. Is there additional work that would need to be done?
Comment From: timothy-king
We don't really use our issue tracker for questions. A better place to ask this kind of question is golang-nuts. See https://golang.org/wiki/Questions.
Comment From: tstirrat15
It's unexpected behavior that I'd characterize as a proposal or bug or feature request if the question doesn't have a neat answer. Would you like me to reopen the issue but not phrased as a question?
Comment From: tstirrat15
See here: #69453
Comment From: timothy-king
The original comment was asking a question:
Is there a reason (other than legacy) that the fd args in this lib are ints rather than uints or uintptrs?
As mentioned, there are better places to ask questions.
If you feel an API change is warranted, filing a proposal is an appropriate next step.