Skip to content

Instantly share code, notes, and snippets.

@tao12345666333
Created July 28, 2020 09:36
  • Select an option

Select an option

package main
import "fmt"
import "golang.org/x/sys/unix"
func DeviceFromPath(path string) {
var stat unix.Stat_t
err := unix.Lstat(path, &stat)
if err != nil {
fmt.Println(err)
}
var mode = stat.Mode
switch mode & unix.S_IFMT {
case unix.S_IFCHR:
fmt.Println("CharDevice")
case unix.S_IFLNK:
fmt.Println("linkDevice")
default:
fmt.Println("vim-go")
}
}
func main() {
DeviceFromPath("/dev/zero")
DeviceFromPath("/dev/core")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment