Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
R
riscv-gcc-1
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
riscv-gcc-1
Commits
c417a082
Commit
c417a082
authored
13 years ago
by
Ian Lance Taylor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
exp/terminal: Use tcgetattr/tcsetattr rather than ioctl.
From-SVN: r180780
parent
e1bb1acc
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
8 deletions
+13
-8
libgo/go/exp/terminal/terminal.go
+7
-8
libgo/go/syscall/libcall_posix.go
+6
-0
No files found.
libgo/go/exp/terminal/terminal.go
View file @
c417a082
...
...
@@ -17,7 +17,6 @@ package terminal
import
(
"os"
"syscall"
"unsafe"
)
// State contains the state of a terminal.
...
...
@@ -28,7 +27,7 @@ type State struct {
// IsTerminal returns true if the given file descriptor is a terminal.
func
IsTerminal
(
fd
int
)
bool
{
var
termios
syscall
.
Termios
_
,
_
,
e
:=
syscall
.
Syscall6
(
syscall
.
SYS_IOCTL
,
uintptr
(
fd
),
uintptr
(
syscall
.
TCGETS
),
uintptr
(
unsafe
.
Pointer
(
&
termios
)),
0
,
0
,
0
)
e
:=
syscall
.
Tcgetattr
(
fd
,
&
termios
)
return
e
==
0
}
...
...
@@ -37,14 +36,14 @@ func IsTerminal(fd int) bool {
// restored.
func
MakeRaw
(
fd
int
)
(
*
State
,
os
.
Error
)
{
var
oldState
State
if
_
,
_
,
e
:=
syscall
.
Syscall6
(
syscall
.
SYS_IOCTL
,
uintptr
(
fd
),
uintptr
(
syscall
.
TCGETS
),
uintptr
(
unsafe
.
Pointer
(
&
oldState
.
termios
)),
0
,
0
,
0
);
e
!=
0
{
if
e
:=
syscall
.
Tcgetattr
(
fd
,
&
oldState
.
termios
);
e
!=
0
{
return
nil
,
os
.
Errno
(
e
)
}
newState
:=
oldState
.
termios
newState
.
Iflag
&^=
syscall
.
ISTRIP
|
syscall
.
INLCR
|
syscall
.
ICRNL
|
syscall
.
IGNCR
|
syscall
.
IXON
|
syscall
.
IXOFF
newState
.
Lflag
&^=
syscall
.
ECHO
|
syscall
.
ICANON
|
syscall
.
ISIG
if
_
,
_
,
e
:=
syscall
.
Syscall6
(
syscall
.
SYS_IOCTL
,
uintptr
(
fd
),
uintptr
(
syscall
.
TCSETS
),
uintptr
(
unsafe
.
Pointer
(
&
newState
)),
0
,
0
,
0
);
e
!=
0
{
if
e
:=
syscall
.
Tcsetattr
(
fd
,
syscall
.
TCSANOW
,
&
newState
);
e
!=
0
{
return
nil
,
os
.
Errno
(
e
)
}
...
...
@@ -54,7 +53,7 @@ func MakeRaw(fd int) (*State, os.Error) {
// Restore restores the terminal connected to the given file descriptor to a
// previous state.
func
Restore
(
fd
int
,
state
*
State
)
os
.
Error
{
_
,
_
,
e
:=
syscall
.
Syscall6
(
syscall
.
SYS_IOCTL
,
uintptr
(
fd
),
uintptr
(
syscall
.
TCSETS
),
uintptr
(
unsafe
.
Pointer
(
&
state
.
termios
)),
0
,
0
,
0
)
e
:=
syscall
.
Tcsetattr
(
fd
,
syscall
.
TCSANOW
,
&
state
.
termios
)
return
os
.
Errno
(
e
)
}
...
...
@@ -63,18 +62,18 @@ func Restore(fd int, state *State) os.Error {
// returned does not include the \n.
func
ReadPassword
(
fd
int
)
([]
byte
,
os
.
Error
)
{
var
oldState
syscall
.
Termios
if
_
,
_
,
e
:=
syscall
.
Syscall6
(
syscall
.
SYS_IOCTL
,
uintptr
(
fd
),
uintptr
(
syscall
.
TCGETS
),
uintptr
(
unsafe
.
Pointer
(
&
oldState
)),
0
,
0
,
0
);
e
!=
0
{
if
e
:=
syscall
.
Tcgetattr
(
fd
,
&
oldState
);
e
!=
0
{
return
nil
,
os
.
Errno
(
e
)
}
newState
:=
oldState
newState
.
Lflag
&^=
syscall
.
ECHO
if
_
,
_
,
e
:=
syscall
.
Syscall6
(
syscall
.
SYS_IOCTL
,
uintptr
(
fd
),
uintptr
(
syscall
.
TCSETS
),
uintptr
(
unsafe
.
Pointer
(
&
newState
)),
0
,
0
,
0
);
e
!=
0
{
if
e
:=
syscall
.
Tcsetattr
(
fd
,
syscall
.
TCSANOW
,
&
newState
);
e
!=
0
{
return
nil
,
os
.
Errno
(
e
)
}
defer
func
()
{
syscall
.
Syscall6
(
syscall
.
SYS_IOCTL
,
uintptr
(
fd
),
uintptr
(
syscall
.
TCSETS
),
uintptr
(
unsafe
.
Pointer
(
&
oldState
)),
0
,
0
,
0
)
syscall
.
Tcsetattr
(
fd
,
syscall
.
TCSANOW
,
&
oldState
)
}()
var
buf
[
16
]
byte
...
...
This diff is collapsed.
Click to expand it.
libgo/go/syscall/libcall_posix.go
View file @
c417a082
...
...
@@ -377,3 +377,9 @@ func NsecToTimeval(nsec int64) (tv Timeval) {
tv
.
Usec
=
Timeval_usec_t
(
nsec
%
1e9
/
1e3
)
return
}
//sysnb Tcgetattr(fd int, p *Termios) (errno int)
//tcgetattr(fd int, p *Termios) int
//sys Tcsetattr(fd int, actions int, p *Termios) (errno int)
//tcsetattr(fd int, actions int, p *Termios) int
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment