Port: dirfd is not portable, replace it
[babeltrace.git] / lib / ctf-writer / writer.c
index a5efe4775c37468b296dfb990f78e39fb6f46834..2978cdfb78a02affa2f7b0e32193eb44225d10cd 100644 (file)
@@ -109,6 +109,7 @@ struct bt_ctf_writer *bt_ctf_writer_create(const char *path)
        int ret;
        struct bt_ctf_writer *writer = NULL;
        unsigned char uuid[16];
+       char *metadata_path = NULL;
 
        if (!path) {
                goto error;
@@ -119,6 +120,8 @@ struct bt_ctf_writer *bt_ctf_writer_create(const char *path)
                goto error;
        }
 
+       metadata_path = g_build_filename(path, "metadata", NULL);
+
        bt_object_init(writer, bt_ctf_writer_destroy);
        writer->path = g_string_new(path);
        if (!writer->path) {
@@ -161,22 +164,21 @@ struct bt_ctf_writer *bt_ctf_writer_create(const char *path)
                goto error_destroy;
        }
 
-       writer->trace_dir_fd = open(path, O_RDONLY, S_IRWXU | S_IRWXG);
-       if (writer->trace_dir_fd < 0) {
+       writer->metadata_fd = open(metadata_path,
+               O_WRONLY | O_CREAT | O_TRUNC,
+               S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
+       if (writer->metadata_fd < 0) {
                perror("open");
                goto error_destroy;
        }
 
-       writer->metadata_fd = openat(writer->trace_dir_fd, "metadata",
-               O_WRONLY | O_CREAT | O_TRUNC,
-               S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
-
+       g_free(metadata_path);
        return writer;
 
 error_destroy:
-       unlinkat(writer->trace_dir_fd, "metadata", 0);
        BT_PUT(writer);
 error:
+       g_free(metadata_path);
        return writer;
 }
 
@@ -190,12 +192,6 @@ void bt_ctf_writer_destroy(struct bt_object *obj)
                g_string_free(writer->path, TRUE);
        }
 
-       if (writer->trace_dir_fd > 0) {
-               if (close(writer->trace_dir_fd)) {
-                       perror("close");
-               }
-       }
-
        if (writer->metadata_fd > 0) {
                if (close(writer->metadata_fd)) {
                        perror("close");
This page took 0.02385 seconds and 4 git commands to generate.