Created
July 28, 2020 09:36
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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