+int prepare_symlink_tree(void)
+{
+ int i;
+ char tmppath[PATH_MAX];
+
+ /* Create the temporary directory */
+ if (mkdtemp(tree_origin) == NULL) {
+ printerr("mkdtemp");
+ goto error;
+ }
+
+ /* Create the directories of the test tree */
+ for (i = 0; i < num_tree_dirs; i++) {
+ snprintf(tmppath, PATH_MAX, "%s/%s", tree_origin, tree_dirs[i]);
+
+ if (mkdir(tmppath, 0755) != 0) {
+ snprintf(errmsg, ERRSIZE, "mkdir %s", tmppath);
+ printerr(errmsg);
+ goto error;
+ }
+ }
+
+ /* Create the symlinks of the test tree */
+ for (i = 0; i < num_tree_symlinks; i++) {
+ snprintf(tmppath, PATH_MAX, "%s/%s",
+ tree_origin, tree_symlinks[i].orig);
+
+ if (symlink(tree_symlinks[i].dest, tmppath) != 0) {
+ snprintf(errmsg, ERRSIZE, "symlink %s to %s",
+ tmppath, tree_symlinks[i].dest);
+ printerr(errmsg);
+ goto error;
+ }
+ }
+
+ return 0;
+
+error:
+ return 1;
+}
+
+int free_symlink_tree(void)
+{
+ int i;
+ char tmppath[PATH_MAX];
+
+ /* Remove the symlinks from the test tree */
+ for (i = num_tree_symlinks - 1; i > -1; i--) {
+ snprintf(tmppath, PATH_MAX, "%s/%s",
+ tree_origin, tree_symlinks[i].orig);
+
+ if (unlink(tmppath) != 0) {
+ snprintf(errmsg, ERRSIZE, "unlink %s", tmppath);
+ printerr(errmsg);
+ goto error;
+ }
+ }
+
+ /* Remove the directories from the test tree */
+ for (i = num_tree_dirs - 1; i > -1; i--) {
+ snprintf(tmppath, PATH_MAX, "%s/%s", tree_origin, tree_dirs[i]);
+
+ if (rmdir(tmppath) != 0) {
+ snprintf(errmsg, ERRSIZE, "rmdir %s", tmppath);
+ printerr(errmsg);
+ goto error;
+ }
+ }
+
+ /* Remove the temporary directory */
+ if (rmdir(tree_origin) != 0) {
+ snprintf(errmsg, ERRSIZE, "rmdir %s", tree_origin);
+ printerr(errmsg);
+ goto error;
+ }
+
+ return 0;
+
+error:
+ return 1;
+}
+