Getting and setting filesystem extended attributes is pretty straightforward. Listing them isn't. There's more than meets the eye, and the documentation is pretty slim.
Conversation
Replying to
You need to pass a buffer to listxattr and then iterate over the NUL-terminated strings. The return value tells you when to stop so you know how many times you need to look past the NUL terminator for another string.
At least on Linux, it has a limit on how much it can return.
1
2
Since the API isn't designed with a form of pagination like readdir, I guess the limit is there to prevent the kernel from needing to hold a lock for a ridiculously long time. The readdir approach has issues itself since it can't give a complete snapshot of a given point in time.

