+static int
+test_lstat(const char *pathname, struct stat *buf)
+{
+ if (!strcmp(pathname, "/tmp/toto/")) {
+ struct stat st = { .st_mode = S_IFDIR };
+ memcpy(buf, &st, sizeof(*buf));
+ return 0;
+ }
+
+ errno = ENOENT;
+ return -1;
+}
+
+static DIR *
+test_opendir(const char *name)
+{
+ int *p;
+
+ if (strcmp(name, "/tmp/toto/")) {
+ errno = ENOENT;
+ return NULL;
+ }
+
+ p = malloc(sizeof(int));
+ if (p)
+ *p = 0;
+
+ return (DIR *)p;
+}
+
+static struct dirent *
+test_readdir(DIR *dirp)
+{
+ static struct dirent de[] = {
+ { .d_type = DT_DIR, .d_name = ".." },
+ { .d_type = DT_DIR, .d_name = "." },
+ { .d_type = DT_REG, .d_name = "bar" },
+ { .d_type = DT_UNKNOWN, .d_name = "bar2" },
+ { .d_type = DT_REG, .d_name = "foo" },
+ { .d_type = DT_DIR, .d_name = "titi" },
+ { .d_type = DT_UNKNOWN, .d_name = "tutu" },
+ { .d_name = "" },
+ };
+ int *p = (int *)dirp;
+ struct dirent *ret = &de[*p];
+
+ if (!strcmp(ret->d_name, ""))
+ return NULL;
+
+ *p = *p + 1;
+
+ return ret;
+}
+
+static int
+test_closedir(DIR *dirp)
+{
+ free(dirp);
+ return 0;
+}
+
+static int
+test_dirfd(DIR *dirp)
+{
+ int *p = (int *)dirp;
+ return *p;
+}
+
+static int
+test_fstatat(int dirfd, const char *pathname, struct stat *buf,
+ int flags)
+{
+ (void)dirfd;
+ (void)flags;
+
+ if (!strcmp(pathname, "bar2")) {
+ struct stat st = { .st_mode = S_IFREG };
+ memcpy(buf, &st, sizeof(*buf));
+ return 0;
+ } else if (!strcmp(pathname, "tutu")) {
+ struct stat st = { .st_mode = S_IFDIR };
+ memcpy(buf, &st, sizeof(*buf));
+ return 0;
+ }
+
+ errno = ENOENT;
+ return -1;
+}
+
+static int
+ec_node_file_override_functions(struct ec_node *gen_node)
+{
+ struct ec_node_file *node = (struct ec_node_file *)gen_node;
+
+ node->lstat = test_lstat;
+ node->opendir = test_opendir;
+ node->readdir = test_readdir;
+ node->closedir = test_closedir;
+ node->dirfd = test_dirfd;
+ node->fstatat = test_fstatat;
+
+ return 0;
+}
+