unix: add {get,set,remove,list}xattr on darwin

It's only when dest is set to NULL that the OS X implementations of
getxattr() and listxattr() return the current sizes of the named
attributes. An empty byte array is not sufficient. To maintain the same
behaviour as the linux implementation, we wrap around the system calls
and pass in NULL when dest is empty.

The parameters for the OS X implementation of setxattr() vary slightly
compared to the linux system call, specifically the 'position'
parameter:

 linux:
     int setxattr(
         const char *path,
         const char *name,
         const void *value,
         size_t size,
         int flags
     );

 darwin:
     int setxattr(
         const char *path,
         const char *name,
         void *value,
         size_t size,
         u_int32_t position,
         int options
     );

'position' specifies the offset within the extended attribute. In the
current implementation, only the resource fork extended attribute makes
use of this argument. For all others, position is reserved.  We simply
default to setting it to zero.  If that's needed by the package user, a
function with a different name needs to be implemented instead.

Similarly for removexattr(), we wrap around and explicitly zero out the
options provided. We do so for interoperability with the linux variant.
If options are needed by the package user, a function with a different
name needs to be implemented instead.

Fixes golang/go#14456

Change-Id: I2581e1fa8dc9324bced7fda7f8ada10fe2ede3f5
Reviewed-on: https://go-review.googlesource.com/113995
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
5 files changed
tree: 63ef26f4e85fba22304b9fa54e6c5872edf0f9c9
  1. cpu/
  2. plan9/
  3. unix/
  4. windows/
  5. .gitattributes
  6. .gitignore
  7. AUTHORS
  8. codereview.cfg
  9. CONTRIBUTING.md
  10. CONTRIBUTORS
  11. LICENSE
  12. PATENTS
  13. README.md
README.md

sys

This repository holds supplemental Go packages for low-level interactions with the operating system.

Download/Install

The easiest way to install is to run go get -u golang.org/x/sys. You can also manually git clone the repository to $GOPATH/src/golang.org/x/sys.

Report Issues / Send Patches

This repository uses Gerrit for code changes. To learn how to submit changes to this repository, see https://golang.org/doc/contribute.html.

The main issue tracker for the sys repository is located at https://github.com/golang/go/issues. Prefix your issue with “x/sys:” in the subject line, so it is easy to find.