a | b | |
---|
| 0 | + | #include <stdio.h> |
---|
| 0 | + | #include <sys/types.h> |
---|
| 0 | + | #include <sys/stat.h> |
---|
| 0 | + | #include <sys/xattr.h> |
---|
| 0 | + | #include <unistd.h> |
---|
| 0 | + | #include <fcntl.h> |
---|
| 0 | + | #include <errno.h> |
---|
| 0 | + | #include <string.h> |
---|
| 0 | + | |
---|
| 0 | + | int main(int argc, char *argv[]) |
---|
| 0 | + | { |
---|
| 0 | + | int fd; |
---|
| 0 | + | |
---|
| 0 | + | if (argc != 2) { |
---|
| 0 | + | printf("Use: %s <path>\n", argv[0]); |
---|
| 0 | + | return 1; |
---|
| 0 | + | } |
---|
| 0 | + | |
---|
| 0 | + | /* |
---|
| 0 | + | * with O_WRONLY or O_RDWR, opening a directory always fails, even when passing |
---|
| 0 | + | * O_DIRECTORY. Opening with O_RDONLY, without O_DIRECTORY succeeds for both |
---|
| 0 | + | * regular files and directories. |
---|
| 0 | + | */ |
---|
| 0 | + | fd = open(argv[1], O_WRONLY); |
---|
| 0 | + | if (fd == -1) { |
---|
| 0 | + | printf("open error %d: %s\n", errno, strerror(errno)); |
---|
| 0 | + | } else { |
---|
| 0 | + | int e; |
---|
| 0 | + | |
---|
| 0 | + | e = fsetxattr(fd, "user.x1", "abc", 3, 0); |
---|
| 0 | + | printf("file open fd = %d, setxattr(fd) = %d, fsync(fd) = %d\n", fd, e, fsync(fd)); |
---|
| 0 | + | close(fd); |
---|
| 0 | + | } |
---|
| 0 | + | return 0; |
---|
| 0 | + | } |
---|
| 0 | + | |
---|
... | |
---|