1 /* 2 * Copyright 2008-2009, Axel Dörfler, axeld@pinc-software.de. 3 * Distributed under the terms of the MIT License. 4 */ 5 6 7 #include <dirent.h> 8 #include <stdio.h> 9 #include <stdlib.h> 10 11 12 int 13 main(int argc, char** argv) 14 { 15 dirent *buf, *dirent; 16 DIR* dir = opendir("."); 17 18 printf("first pass:\n"); 19 while (true) { 20 dirent = readdir(dir); 21 if (dirent == NULL) 22 break; 23 24 printf("Entry: dev %ld, ino %lld, name \"%s\"\n", dirent->d_dev, 25 dirent->d_ino, dirent->d_name); 26 //printf(" left: %u, next: %d\n", dir->entries_left, dir->next_entry); 27 } 28 29 rewinddir(dir); 30 printf("second pass:\n"); 31 while (true) { 32 dirent = readdir(dir); 33 if (dirent == NULL) 34 break; 35 36 printf("Entry: dev %ld, ino %lld, name \"%s\"\n", dirent->d_dev, 37 dirent->d_ino, dirent->d_name); 38 //printf(" left: %u, next: %d\n", dir->entries_left, dir->next_entry); 39 } 40 41 42 closedir(dir); 43 44 dirent = NULL; 45 buf = (struct dirent*)malloc(sizeof(struct dirent) + NAME_MAX); 46 47 dir = opendir("."); 48 49 printf("first pass:\n"); 50 while (true) { 51 if (readdir_r(dir, buf, &dirent) != 0 || dirent == NULL) 52 break; 53 54 printf("Entry: dev %ld, ino %lld, name \"%s\"\n", dirent->d_dev, 55 dirent->d_ino, dirent->d_name); 56 //printf(" left: %u, next: %d\n", dir->entries_left, dir->next_entry); 57 } 58 59 rewinddir(dir); 60 printf("second pass:\n"); 61 while (true) { 62 if (readdir_r(dir, buf, &dirent) != 0 || dirent == NULL) 63 break; 64 65 printf("Entry: dev %ld, ino %lld, name \"%s\"\n", dirent->d_dev, 66 dirent->d_ino, dirent->d_name); 67 //printf(" left: %u, next: %d\n", dir->entries_left, dir->next_entry); 68 } 69 70 closedir(dir); 71 72 return 0; 73 } 74