-
Notifications
You must be signed in to change notification settings - Fork 0
/
dirtest.c
113 lines (77 loc) · 2.3 KB
/
dirtest.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <malloc.h>
#include <ctype.h>
#include <locale.h>
#include <errno.h>
#include <fcntl.h>
#include <math.h>
#include <time.h>
#include <limits.h>
#include <signal.h>
#include <assert.h>
//typedef struct dirent;
#include <sys/types.h>
#include <dirent.h>
//#include <bits/dirent.h>
//struct dirent {
// ino_t d_ino; /* inode number */
// off_t d_off; /* offset to the next dirent */
// unsigned short d_reclen; /* length of this record */
// unsigned char d_type; /* type of file; not supported
// by all file system types */
// char d_name[256]; /* filename */
//};
//extern struct dirent;
//typedef struct __direntDJA {
// ino_t d_ino; /* inode number */
// off_t d_off; /* offset to the next dirent */
// unsigned short d_reclen; /* length of this record */
// unsigned char d_type; /* type of file; not supported
// by all file system types */
// char d_name[256]; /* filename */
//} dirent;
//
int readsome(DIR *dirstruct) {
struct dirent *p_direntry;
int finished = 0;
int count = 0;
while (finished == 0 && count < 40) {
p_direntry = readdir(dirstruct);
if (p_direntry == NULL) {
finished = 1;
}
else {
printf("Found file %s \n", p_direntry->d_name);
}
count++;
}
printf("************\n");
return finished;
}
int main(int argc,char **argv) {
DIR *dirstruct;
DIR *dirstruct2;
int result;
dirstruct = opendir("./ImageMagick-6.9.0-0/coders");
if (dirstruct == NULL) {
printf("Failed to open dir \n");
return (-1);
}
readsome(dirstruct);
dirstruct2 = opendir("./ImageMagick-6.9.0-0/coders");
if (dirstruct2 == NULL) {
printf("Failed to open dir 2 \n");
return (-1);
}
readsome(dirstruct2);
readsome(dirstruct);
readsome(dirstruct2);
readsome(dirstruct2);
readsome(dirstruct);
result = closedir(dirstruct);
result = closedir(dirstruct2);
printf("close result is: %d \n", result);
return(0);
}