+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;
+}
+