Skip to content

Instantly share code, notes, and snippets.

@tao12345666333
Created July 28, 2020 09:36
Show Gist options
  • Save tao12345666333/9f5695c0173ba4ab6123d89b685ba52d to your computer and use it in GitHub Desktop.
Save tao12345666333/9f5695c0173ba4ab6123d89b685ba52d to your computer and use it in GitHub Desktop.
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