int readdir_test() { int ret = 0; printf("readdir_test: Start\n"); printf("\tbegin: look for \".\"\n"); if((ret = do_readdir(DIR_PATH, ".")) != 0){ goto out; } printf("\tend: Success\n"); printf("\tbegin: look for \"..\"\n"); if((ret = do_readdir(DIR_PATH, "..")) != 0){ goto out; } printf("\tend: Success\n"); printf("\tbegin: look for \"%s\"\n", FILE_NAME); if((ret = do_readdir(DIR_PATH, NEW_FILE_NAME_1)) != 0){ goto out; } printf("\tend: Success\n"); out: if (ret) { printf("\tend: Failed\n"); } printf("readdir_test: Finish\n"); return ret; }
static int seaf_fuse_readdir(const char *path, void *buf, fuse_fill_dir_t filler, off_t offset, struct fuse_file_info *info) { filler(buf, ".", NULL, 0); filler(buf, "..", NULL, 0); return do_readdir(seaf, path, buf, filler, offset, info); }
static void * fudge_opendir(const char *path) { struct SFTP_OPENDIR *r; r = xmalloc(sizeof(*r)); if (do_readdir(cur.conn, (char *)path, &r->dir)) { xfree(r); return(NULL); } r->offset = 0; return((void *)r); }
int stest_fuse_readdir(struct redfish_dirp* dp, stest_fuse_readdir_fn fn, void *data) { struct dirent *de; int ret, noda = 0; while (1) { de = do_readdir(dp); if (!de) return noda; if (!strcmp(de->d_name, ".")) continue; if (!strcmp(de->d_name, "..")) continue; ret = fn(de, data); if (ret) return ret; ++noda; } return noda; }
/* sftp ls.1 replacement for directories */ static int do_ls_dir(struct sftp_conn *conn, char *path, char *strip_path, int lflag) { int n; u_int c = 1, colspace = 0, columns = 1; SFTP_DIRENT **d; if ((n = do_readdir(conn, path, &d)) != 0) return (n); if (!(lflag & LS_SHORT_VIEW)) { u_int m = 0, width = 80; struct winsize ws; char *tmp; /* Count entries for sort and find longest filename */ for (n = 0; d[n] != NULL; n++) { if (d[n]->filename[0] != '.' || (lflag & LS_SHOW_ALL)) m = MAX(m, strlen(d[n]->filename)); } /* Add any subpath that also needs to be counted */ tmp = path_strip(path, strip_path); m += strlen(tmp); xfree(tmp); if (ioctl(fileno(stdin), TIOCGWINSZ, &ws) != -1) width = ws.ws_col; columns = width / (m + 2); columns = MAX(columns, 1); colspace = width / columns; colspace = MIN(colspace, width); } if (lflag & SORT_FLAGS) { for (n = 0; d[n] != NULL; n++) ; /* count entries */ sort_flag = lflag & (SORT_FLAGS|LS_REVERSE_SORT); qsort(d, n, sizeof(*d), sdirent_comp); } for (n = 0; d[n] != NULL && !interrupted; n++) { char *tmp, *fname; if (d[n]->filename[0] == '.' && !(lflag & LS_SHOW_ALL)) continue; tmp = path_append(path, d[n]->filename); fname = path_strip(tmp, strip_path); xfree(tmp); if (lflag & LS_LONG_VIEW) { if (lflag & LS_NUMERIC_VIEW) { char *lname; struct stat sb; memset(&sb, 0, sizeof(sb)); attrib_to_stat(&d[n]->a, &sb); lname = ls_file(fname, &sb, 1); printf("%s\n", lname); xfree(lname); } else printf("%s\n", d[n]->longname); } else { printf("%-*s", colspace, fname); if (c >= columns) { printf("\n"); c = 1; } else c++; } xfree(fname); } if (!(lflag & LS_LONG_VIEW) && (c != 1)) printf("\n"); free_sftp_dirents(d); return (0); }