7gUN4kB3ZfHwVdlDggodUY changeset

Changeset343337616435 (b)
ParentNone (a)
ab
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+
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
--- Revision None
+++ Revision 343337616435
@@ -0,0 +1,36 @@
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/xattr.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <string.h>
+
+int main(int argc, char *argv[])
+{
+ int fd;
+
+ if (argc != 2) {
+ printf("Use: %s <path>\n", argv[0]);
+ return 1;
+ }
+
+ /*
+ * with O_WRONLY or O_RDWR, opening a directory always fails, even when passing
+ * O_DIRECTORY. Opening with O_RDONLY, without O_DIRECTORY succeeds for both
+ * regular files and directories.
+ */
+ fd = open(argv[1], O_WRONLY);
+ if (fd == -1) {
+ printf("open error %d: %s\n", errno, strerror(errno));
+ } else {
+ int e;
+
+ e = fsetxattr(fd, "user.x1", "abc", 3, 0);
+ printf("file open fd = %d, setxattr(fd) = %d, fsync(fd) = %d\n", fd, e, fsync(fd));
+ close(fd);
+ }
+ return 0;
+}
+