File tree Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Original file line number Diff line number Diff line change @@ -216,6 +216,44 @@ 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
+ // NOLINTNEXTLINE(concurrency-mt-unsafe)
233
+ struct dirent * dirent = readdir (dir );
234
+ if (dirent == NULL ) {
235
+ break ;
236
+ }
237
+
238
+ fprintf (stderr , "%s\n" , dirent -> d_name );
239
+ }
240
+ if (errno != 0 ) {
241
+ perror ("readdir() failed" );
242
+ return -1 ;
243
+ }
244
+ fputc ('\n' , stderr );
245
+
246
+ fprintf (stderr , "closedir(\"%s\")\n" , path );
247
+ int closed = closedir (dir );
248
+ if (closed == -1 ) {
249
+ perror ("closedir() failed" );
250
+ return -1 ;
251
+ }
252
+
253
+ fputc ('\n' , stderr );
254
+ return 0 ;
255
+ }
256
+
219
257
int main (void ) {
220
258
#ifdef __hermit__
221
259
const char * dir_path = "/my-dir" ;
@@ -240,6 +278,11 @@ int main(void) {
240
278
return EXIT_FAILURE ;
241
279
}
242
280
281
+ int readdir_status = print_readdir (dir_path );
282
+ if (readdir_status == -1 ) {
283
+ return EXIT_FAILURE ;
284
+ }
285
+
243
286
int unlink_status = unlink_files (dir_path , file_count );
244
287
if (unlink_status == -1 ) {
245
288
return EXIT_FAILURE ;
You can’t perform that action at this time.
0 commit comments