Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
#include <babeltrace/ctf-writer/stream-class.h>
#include <babeltrace/ctf-writer/stream.h>
#include <assert.h>
#include <babeltrace/ctf-writer/stream-class.h>
#include <babeltrace/ctf-writer/stream.h>
#include <assert.h>
#include <ctfcopytrace.h>
#include <ctfcopytrace.h>
static
bool valid_single_trace_path(const char *path)
{
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) {
/* 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");
- if (n <= 2) {
- ret = 0;
- } else {
+ /* g_dir_read_name skips "." and "..", error out on first result */
+ while (g_dir_read_name(dir) != NULL) {
+ if (dir) {
+ g_dir_close(dir);
+ }
+ if (error) {
+ g_error_free(error);
+ }
+