File: serial_open_unix.go

package info (click to toggle)
golang-github-albenik-go-serial 2.6.1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 308 kB
  • sloc: makefile: 2
file content (30 lines) | stat: -rw-r--r-- 718 bytes parent folder | download
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
//
// 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

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),
		),
	}
}