mirror of
https://github.com/go-sylixos/elvish.git
synced 2024-12-13 09:57:51 +08:00
e6f0375f64
IO redirections use os module now, which uses uintptr for fd.
50 lines
878 B
Go
50 lines
878 B
Go
package parse
|
|
|
|
// Redir represents a single IO redirection. Its concrete type may be one of
|
|
// the *Redir types below.
|
|
type Redir interface {
|
|
Fd() uintptr
|
|
// ensure only structs in this package can satisfy this interface
|
|
unexported()
|
|
}
|
|
|
|
type redir struct {
|
|
fd uintptr
|
|
}
|
|
|
|
func (r *redir) Fd() uintptr {
|
|
return r.fd
|
|
}
|
|
|
|
func (r *redir) unexported() {
|
|
}
|
|
|
|
type FdRedir struct {
|
|
redir
|
|
OldFd uintptr
|
|
}
|
|
|
|
// Public since we need to turn FilenameRedir -> FdRedir when evaluating
|
|
// commands.
|
|
func NewFdRedir(fd, oldFd uintptr) *FdRedir {
|
|
return &FdRedir{redir{fd}, oldFd}
|
|
}
|
|
|
|
type CloseRedir struct {
|
|
redir
|
|
}
|
|
|
|
func newCloseRedir(fd uintptr) *CloseRedir {
|
|
return &CloseRedir{redir{fd}}
|
|
}
|
|
|
|
type FilenameRedir struct {
|
|
redir
|
|
Flag int
|
|
Filename Node
|
|
}
|
|
|
|
func newFilenameRedir(fd uintptr, flag int, filename Node) *FilenameRedir {
|
|
return &FilenameRedir{redir{fd}, flag, filename}
|
|
}
|