How to get extended attributes of a file(UNIX/C)?

后端 未结 2 1884
旧时难觅i
旧时难觅i 2021-01-05 23:19

When I type ls -l in the command line, sometimes an @ or + symbol comes up alongside the file permissions(btw, I am on OS X), as shown

2条回答
  •  北荒
    北荒 (楼主)
    2021-01-05 23:41

    @ means the file has extended attributes. Use listxattr() to get a list of the names of all the extended attributes, and getxattr() to get the value of a particular attribute. If listxattr returns a non-zero result, you would display @ to indicate this.

    Extended attributes are not in POSIX, but this API is available in Linux and OS X, at least.

    You can find an example of how to use these functions here.

    + means the file has an access control list. In some filesystems, this is stored as a special extended attribute; in others it's stored separately. For access control lists, see acl(5) for a reference, and you can find an example program that displays it here.

提交回复
热议问题