Skip to content

Commit

Permalink
Check if file is a tty
Browse files Browse the repository at this point in the history
  • Loading branch information
Tarmigan Casebolt committed Mar 4, 2011
1 parent 5fa411c commit c4bd917
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions serial_posix.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package serial

// #include <termios.h>
// #include <unistd.h>
import "C"

import (
Expand All @@ -25,6 +26,10 @@ func OpenPort(name string, baud int) (f *os.File, err os.Error) {
}

fd := C.int(f.Fd())
if C.isatty(fd) != 1 {
f.Close()
return nil, SError{"File is not a tty"}
}

var st C.struct_termios
_, err = C.tcgetattr(fd, &st)
Expand Down

0 comments on commit c4bd917

Please sign in to comment.