Add a copy method to lttng_directory_handle
[lttng-tools.git] / src / common / compat / directory-handle.c
index 781f2574b0ea652cadd2d8b8bb0e9e487d891d91..562a7928719031856164f5a7fb2333fe30bcfc75 100644 (file)
@@ -88,6 +88,24 @@ void lttng_directory_handle_fini(struct lttng_directory_handle *handle)
        }
 }
 
+LTTNG_HIDDEN
+int lttng_directory_handle_copy(const struct lttng_directory_handle *handle,
+               struct lttng_directory_handle *new_copy)
+{
+       int ret = 0;
+
+       if (handle->dirfd == AT_FDCWD) {
+               new_copy->dirfd = handle->dirfd;
+       } else {
+               new_copy->dirfd = dup(handle->dirfd);
+               if (new_copy->dirfd == -1) {
+                       PERROR("Failed to duplicate directory fd of directory handle");
+                       ret = -1;
+               }
+       }
+       return ret;
+}
+
 static
 int lttng_directory_handle_stat(const struct lttng_directory_handle *handle,
                const char *path, struct stat *st)
@@ -225,6 +243,14 @@ void lttng_directory_handle_fini(struct lttng_directory_handle *handle)
        free(handle->base_path);
 }
 
+LTTNG_HIDDEN
+int lttng_directory_handle_copy(const struct lttng_directory_handle *handle,
+               struct lttng_directory_handle *new_copy)
+{
+       new_copy->base_path = strdup(handle->base_path);
+       return new_copy->base_path ? 0 : -1;
+}
+
 static
 int get_full_path(const struct lttng_directory_handle *handle,
                const char *subdirectory, char *fullpath, size_t size)
This page took 0.02516 seconds and 5 git commands to generate.