• irfan sharif's avatar
    unix: add {get,set,remove,list}xattr on darwin · 0b6bef99
    irfan sharif authored
    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/113995Reviewed-by: 's avatarTobias Klauser <tobias.klauser@gmail.com>
    Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
    TryBot-Result: Gobot Gobot <gobot@golang.org>
    0b6bef99
zsyscall_darwin_arm64.go 39.8 KB