forked from albenik/go-serial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserial_open_unix.go
More file actions
31 lines (26 loc) · 766 Bytes
/
serial_open_unix.go
File metadata and controls
31 lines (26 loc) · 766 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
//
// Copyright 2014-2018 Cristian Maglie. All rights reserved.
// Copyright 2019-2022 Veniamin Albaev <albenik@gmail.com>.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//
//go:build (linux && !android) || darwin || freebsd || openbsd
// +build linux,!android darwin freebsd openbsd
package serial
import (
"go.uber.org/multierr"
"golang.org/x/sys/unix"
)
func accquireExclusiveAccess(h int) error {
return unix.IoctlSetInt(h, unix.TIOCEXCL, 0)
}
func (p *Port) closeAndReturnError(code PortErrorCode, err error) *PortError {
return &PortError{
code: code,
wrapped: multierr.Combine(
err,
unix.IoctlSetInt(p.internal.handle, unix.TIOCNXCL, 0),
unix.Close(p.internal.handle),
),
}
}