File tree Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Original file line number Diff line number Diff line change @@ -216,6 +216,43 @@ static int print_getdents64(const char *path) {
216
216
return 0 ;
217
217
}
218
218
219
+ static int print_readdir (const char * path ) {
220
+ fprintf (stderr , "print_readdir(\"%s\")\n" , path );
221
+
222
+ fprintf (stderr , "opendir(\"%s\")\n" , path );
223
+ DIR * dir = opendir (path );
224
+ if (dir == NULL ) {
225
+ perror ("opendir() failed" );
226
+ return -1 ;
227
+ }
228
+
229
+ fputc ('\n' , stderr );
230
+ for (;;) {
231
+ errno = 0 ;
232
+ struct dirent * dirent = readdir (dir );
233
+ if (dirent == NULL ) {
234
+ break ;
235
+ }
236
+
237
+ fprintf (stderr , "%s\n" , dirent -> d_name );
238
+ }
239
+ if (errno != 0 ) {
240
+ perror ("readdir() failed" );
241
+ return -1 ;
242
+ }
243
+ fputc ('\n' , stderr );
244
+
245
+ fprintf (stderr , "closedir(\"%s\")\n" , path );
246
+ int closed = closedir (dir );
247
+ if (closed == -1 ) {
248
+ perror ("closedir() failed" );
249
+ return -1 ;
250
+ }
251
+
252
+ fputc ('\n' , stderr );
253
+ return 0 ;
254
+ }
255
+
219
256
int main (void ) {
220
257
#ifdef __hermit__
221
258
const char * dir_path = "/my-dir" ;
@@ -240,6 +277,11 @@ int main(void) {
240
277
return EXIT_FAILURE ;
241
278
}
242
279
280
+ int readdir_status = print_readdir (dir_path );
281
+ if (readdir_status == -1 ) {
282
+ return EXIT_FAILURE ;
283
+ }
284
+
243
285
int unlink_status = unlink_files (dir_path , file_count );
244
286
if (unlink_status == -1 ) {
245
287
return EXIT_FAILURE ;
You can’t perform that action at this time.
0 commit comments