Get errno in Go

package main

import (
    "fmt"
    "log"
    "os"
    "syscall"
)

func main() {
    f, err := os.Open("/tmp/dat")
    if err != nil {
        fmt.Printf("%#v\n", err.(*os.PathError))
        errno := uintptr(err.(*os.PathError).Err.(syscall.Errno))
        fmt.Println("errno is ", errno)
        log.Fatal(err)
    }
    defer f.Close()
    fmt.Println(f.Name())
}
comments powered by Disqus