Port: dirfd is not portable, replace it
[babeltrace.git] / cli / babeltrace-log.c
index a2d4884c825bc64919456285ef621173b23ce668..040af75947f6a63dcf3f7a078b46dc365e09c264 100644 (file)
@@ -30,7 +30,7 @@
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <babeltrace/compat/mman-internal.h>
-#include <babeltrace/compat/dirent-internal.h>
+#include <dirent.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdint.h>
@@ -388,8 +388,8 @@ int main(int argc, char **argv)
 {
        int fd, metadata_fd, ret;
        DIR *dir;
-       int dir_fd;
        FILE *metadata_fp;
+       char *file_path;
 
        ret = parse_args(argc, argv);
        if (ret) {
@@ -414,23 +414,30 @@ int main(int argc, char **argv)
                perror("opendir");
                goto error_rmdir;
        }
-       dir_fd = bt_dirfd(dir);
-       if (dir_fd < 0) {
-               perror("dirfd");
+
+       file_path = g_build_filename(s_outputname, "datastream", NULL);
+       if (file_path == NULL) {
+               perror("g_build_filename");
                goto error_closedir;
        }
-
-       fd = openat(dir_fd, "datastream", O_RDWR|O_CREAT,
+       fd = open(file_path, O_RDWR|O_CREAT,
                    S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP);
+       g_free(file_path);
        if (fd < 0) {
-               perror("openat");
-               goto error_closedirfd;
+               perror("open");
+               goto error_closedir;
        }
 
-       metadata_fd = openat(dir_fd, "metadata", O_RDWR|O_CREAT,
+       file_path = g_build_filename(s_outputname, "metadata", NULL);
+       if (file_path == NULL) {
+               perror("g_build_filename");
+               goto error_closedatastream;
+       }
+       metadata_fd = open(file_path, O_RDWR|O_CREAT,
                             S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP);
+       g_free(file_path);
        if (metadata_fd < 0) {
-               perror("openat");
+               perror("open");
                goto error_closedatastream;
        }
        metadata_fp = fdopen(metadata_fd, "w");
@@ -457,10 +464,6 @@ error_closedatastream:
        ret = close(fd);
        if (ret)
                perror("close");
-error_closedirfd:
-       ret = close(dir_fd);
-       if (ret)
-               perror("close");
 error_closedir:
        ret = closedir(dir);
        if (ret)
This page took 0.023391 seconds and 4 git commands to generate.