Skip to content

Commit

Permalink
Add conditional compilation to deal with OS differences
Browse files Browse the repository at this point in the history
  • Loading branch information
gsexton committed Sep 12, 2024
1 parent 47b0b70 commit 0ffd4b2
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 21 deletions.
1 change: 0 additions & 1 deletion gpioioctl/basic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
// folder.

//go:build linux
// +build linux

package gpioioctl

Expand Down
1 change: 0 additions & 1 deletion gpioioctl/example_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build linux
// +build linux

package gpioioctl_test

Expand Down
1 change: 0 additions & 1 deletion gpioioctl/gpio.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build linux
// +build linux

package gpioioctl

Expand Down
1 change: 0 additions & 1 deletion gpioioctl/ioctl.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build linux
// +build linux

package gpioioctl

Expand Down
1 change: 0 additions & 1 deletion gpioioctl/lineset.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build linux
// +build linux

package gpioioctl

Expand Down
5 changes: 0 additions & 5 deletions netlink/netlink_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ import (

const isLinux = true

// connSocket is a simple wrapper around a Linux netlink connector socket.
type connSocket struct {
fd int
}

// newConnSocket returns a socket instance.
func newConnSocket() (*connSocket, error) {
// Open netlink socket.
Expand Down
4 changes: 0 additions & 4 deletions netlink/netlink_other.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ import "errors"

const isLinux = false

type connSocket struct {
fd int
}

func newConnSocket() (*connSocket, error) {
return nil, errors.New("netlink sockets are not supported")
}
Expand Down
7 changes: 0 additions & 7 deletions netlink/onewire.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,13 +263,6 @@ type socket interface {
close() error
}

// w1Socket is a netlink connector socket for communicating with the w1 Linux
// kernel module.
type w1Socket struct {
s socket
fd int
}

// newW1Socket returns a socket instance.
func newW1Socket() (*w1Socket, error) {
// Open netlink socket.
Expand Down
15 changes: 15 additions & 0 deletions netlink/socket.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//go:build !windows

package netlink

// connSocket is a simple wrapper around a Linux netlink connector socket.
type connSocket struct {
fd int
}

// w1Socket is a netlink connector socket for communicating with the w1 Linux
// kernel module.
type w1Socket struct {
s socket
fd int
}
21 changes: 21 additions & 0 deletions netlink/socket_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package netlink

// Copyright 2024 The Periph Authors. All rights reserved.
// Use of this source code is governed under the Apache License, Version 2.0
// that can be found in the LICENSE file.

import (
"syscall"
)

// connSocket is a simple wrapper around a Linux netlink connector socket.
type connSocket struct {
fd syscall.Handle
}

// w1Socket is a netlink connector socket for communicating with the w1 Linux
// kernel module.
type w1Socket struct {
s socket
fd syscall.Handle
}

0 comments on commit 0ffd4b2

Please sign in to comment.