1// Package zos implements functions for interfacing with the operating system. 2package zos 3 4import "os" 5 6const ( 7 Setuid uint32 = 1 << (12 - 1 - iota) 8 Setgid 9 Sticky 10 UserRead 11 UserWrite 12 UserExecute 13 GroupRead 14 GroupWrite 15 GroupExecute 16 OtherRead 17 OtherWrite 18 OtherExecute 19) 20 21type Permissions struct { 22 User Permission 23 Group Permission 24 Other Permission 25} 26 27type Permission struct { 28 Read bool 29 Write bool 30 Execute bool 31} 32 33// ReadPermissions reads all Unix permissions. 34func ReadPermissions(mode os.FileMode) Permissions { 35 m := uint32(mode) 36 return Permissions{ 37 User: Permission{ 38 Read: m&UserRead != 0, 39 Write: m&UserWrite != 0, 40 Execute: m&UserExecute != 0, 41 }, 42 Group: Permission{ 43 Read: m&GroupRead != 0, 44 Write: m&GroupWrite != 0, 45 Execute: m&GroupExecute != 0, 46 }, 47 Other: Permission{ 48 Read: m&OtherRead != 0, 49 Write: m&OtherWrite != 0, 50 Execute: m&OtherExecute != 0, 51 }, 52 } 53} 54 55// Arg gets the nth argument from os.Args, or an empty string if os.Args is too 56// short. 57func Arg(n int) string { 58 if n > len(os.Args)-1 { 59 return "" 60 } 61 return os.Args[n] 62} 63