Port: replace opendir() by g_dir_open()
authorMichael Jeanson <mjeanson@efficios.com>
Fri, 7 Jul 2017 20:08:23 +0000 (20:08 +0000)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Wed, 19 Jul 2017 18:18:41 +0000 (14:18 -0400)
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
plugins/ctf/fs-sink/write.c

index a0c9d7d9f6d79ab3d0527e1ea81a7c96830a3bc8..9495787d2fc2b22b7967e248da64b857e4821227 100644 (file)
@@ -36,6 +36,7 @@
 #include <babeltrace/ctf-writer/stream-class.h>
 #include <babeltrace/ctf-writer/stream.h>
 #include <assert.h>
+#include <glib.h>
 
 #include <ctfcopytrace.h>
 
@@ -198,37 +199,35 @@ enum fs_writer_stream_state *insert_new_stream_state(
 static
 bool valid_single_trace_path(const char *path)
 {
-       int n = 0;
-       struct dirent *d;
-       DIR *dir = opendir(path);
-       int ret;
+       GError *error = NULL;
+       GDir *dir = NULL;
+       int ret = 0;
+
+       dir = g_dir_open(path, 0, &error);
 
        /* Non-existent directory. */
        if (!dir) {
-               ret = 0;
-               goto end;
-       }
-
-       while ((d = readdir(dir)) != NULL) {
-               /* Ignore "." and ".." directories. */
-               if (++n > 2) {
-                       break;
+               /* For any other error, return an error */
+               if (error->code != G_FILE_ERROR_NOENT) {
+                       ret = -1;
                }
-       }
-
-       ret = closedir(dir);
-       if (ret) {
-               perror("closedir");
                goto end;
        }
 
-       if (n <= 2) {
-               ret = 0;
-       } else {
+       /* g_dir_read_name skips "." and "..", error out on first result */
+       while (g_dir_read_name(dir) != NULL) {
                ret = -1;
+               break;
        }
 
 end:
+       if (dir) {
+               g_dir_close(dir);
+       }
+       if (error) {
+               g_error_free(error);
+       }
+
        return ret;
 }
 
This page took 0.025671 seconds and 4 git commands to generate.