example how to check write access to file

This commit is contained in:
sm
2017-02-12 23:03:21 -08:00
commit 4d1533004e
3 changed files with 49 additions and 0 deletions
+20
View File
@@ -0,0 +1,20 @@
package main
import (
"fmt"
"os"
"golang.org/x/sys/unix"
)
func main() {
if len(os.Args) != 2 {
fmt.Fprintf(os.Stderr, "usage: access <path>\n")
os.Exit(1)
}
filename := os.Args[1]
if err := unix.Access(filename, unix.W_OK); err != nil {
fmt.Printf("%v: %v\n", filename, err)
}
}