| import "golang.org/x/sys/unix" |
| // Returns a []byte slice if the xattr is set and nil otherwise |
| // Requires path and its attribute as arguments |
| func Lgetxattr(path string, attr string) ([]byte, error) { |
| // Start with a 128 length byte array |
| dest := make([]byte, 128) |
| sz, errno := unix.Lgetxattr(path, attr, dest) |
| case errno == unix.ENODATA: |
| case errno == unix.ENOTSUP: |
| case errno == unix.ERANGE: |
| // 128 byte array might just not be good enough, |
| // A dummy buffer is used to get the real size |
| sz, errno = unix.Lgetxattr(path, attr, []byte{}) |
| sz, errno = unix.Lgetxattr(path, attr, dest) |