+static int create_dir(char **ppath, const char *fmt, const char *dir)
+{
+ const char *path;
+ struct stat st;
+
+ if (asprintf(ppath, fmt, dir) == -1) {
+ return 1;
+ }
+ path = *ppath;
+ if (stat(path, &st) == 0) {
+ fprintf(stderr, "%s: Test area directory %s must not exist for test area creation.\n",
+ __progname, path);
+ return 1;
+ }
+ if (mkdir(path, 0777) != 0) {
+ fprintf(stderr, "%s: error creating directory %s: %s\n", __progname, path, strerror(errno));
+ return 1;
+ }
+ return 0;
+}
+
+static int create_file(char **ppath, const char *fmt, const char *dir)
+{
+ const char *path;
+ int fd;
+
+ if (asprintf(ppath, fmt, dir) == -1) {
+ return 1;
+ }
+ path = *ppath;
+ if ((fd = open(path, O_WRONLY|O_CREAT|O_EXCL, 0666)) == -1) {
+ fprintf(stderr, "%s: error creating file %s: %s\n", __progname, path, strerror(errno));
+ return 1;
+ }
+ return fd;
+}
+
+static int create_xattrs(int fd)
+{
+ if (fsetxattr(fd, "trusted.test", "readonly", strlen("readonly"), XATTR_CREATE) != 0) {
+ if (errno != EOPNOTSUPP) {
+ perror("setxattr");
+ return 1;
+ }
+ }
+ if (fsetxattr(fd, "user.test", "readonly", strlen("readonly"), XATTR_CREATE) != 0) {
+ if (errno != EOPNOTSUPP) {
+ perror("setxattr");
+ return 1;
+ }
+ }
+ return 0;
+}
+