readdir issue 4674

zack leung zakthertemsdev at gmail.com
Sat Mar 4 21:59:37 UTC 2023


- hi guys i am working on #4674
- currently i'm not able to get it to produce the error
- my code looks like this
-

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <dirent.h>
#include <stdio.h>
#include <sys/types.h>
#include <fcntl.h>
#include <dirent.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <rtems/imfs.h>

const char rtems_test_name[] = "FSREADDIR ";
int test( void );

int test( void )
{
   char *many_files[] = {"a", "b","c"};


  printf( "\nchdir to the root directory\n" );
 int  status = chdir( "/" );
  printf( "chdir() status : %d\n\n", status );
for (int i = 0; i<3; i++) {
    printf("Create %s\n", many_files[i]);
    int fd = open (many_files[i], O_CREAT, S_IRWXU);
    close (fd);
  }
    struct dirent* direntp;
     DIR* dirp;
    dirp = opendir( "/" );
    if( dirp != NULL ) {
        for(;;) {
            direntp = readdir( dirp );
            if( direntp == NULL ) break;

            printf( "%s\n", direntp->d_name );
        }

        closedir( dirp );

    }

   status =  unlink("/b");
    printf( "removing the second directory  : %d\n\n", status );
   dirp = opendir( "/" );
    if( dirp != NULL ) {
        for(;;) {
            direntp = readdir( dirp );
            if( direntp == NULL ) break;

            printf( "%s\n", direntp->d_name );
        }

        closedir( dirp );

    }

   return 0;

}

Am i unlinking it correctly?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rtems.org/pipermail/devel/attachments/20230304/19f9fad1/attachment.htm>


More information about the devel mailing list