fs/dirent/fs_readdir.c
static struct dirent *__readdir(DIR *dirp, int *lencnt)
{
  struct fs_dirent_s *idir = (struct fs_dirent_s *)dirp;
  struct Vnode *vnode_ptr = NULL;
  int ret = 0;
  int file_cnt = 0;

  /* Verify that we were provided with a valid directory structure */

  if (!idir)
    {
      ret = -EBADF;
      goto errout;
    }

  vnode_ptr = idir->fd_root;
  if (vnode_ptr == NULL)
    {
      /* End of file and error conditions are not distinguishable
       * with readdir.  We return NULL to signal either case.
       */

      ret = -ENOENT;
      goto errout;
    }

  /* Perform the readdir() operation */
#ifdef LOSCFG_ENABLE_READ_BUFFER
  idir->read_cnt = MAX_DIRENT_NUM;
#else
  idir->read_cnt = 1;
#endif

  if (vnode_ptr->vop != NULL && vnode_ptr->vop->Readdir != NULL)
    {
      file_cnt = vnode_ptr->vop->Readdir(vnode_ptr, idir);
    }
  else
    {
      ret = -ENOSYS;
      goto errout;
    }

  if (file_cnt > 0)
    {
      *lencnt = file_cnt * sizeof(struct dirent);
      return &(idir->fd_dir[0]);
    }

errout:
  if (ret < 0)
    {
      set_errno(ret);
    }
  else if (file_cnt <= 0)
    {
      set_errno(ENOENT);
    }

  return (struct dirent *)NULL;
}
/****************************************************************************
 * Name: do_readdir
 *
 * Description:
 *   The do_readdir() function returns a pointer to a dirent structure
 *   representing the next directory entry in the directory stream pointed
 *   to by dir.  It returns NULL on reaching the end-of-file or if an error
 *   occurred.
 *
 * Input Parameters:
 *   dirp -- An instance of type DIR created by a previous call to opendir();
 *
 * Returned Value:
 *   The do_readdir() function returns a pointer to a dirent structure, or NULL
 *   if an error occurs or end-of-file is reached.  On error, errno is set
 *   appropriately.
 *
 *   EBADF   - Invalid directory stream descriptor dir
 *
 ****************************************************************************/
do_readdir
Description:
The do_readdir() function returns a pointer to a dirent structure
representing the next directory entry in the directory stream pointed
to by dir.  It returns NULL on reaching the end-of-file or if an error
occurred.

Input Parameters:
dirp -- An instance of type DIR created by a previous call to opendir().

Returned Value:
The do_readdir() function returns a pointer to a dirent structure, or NULL
if an error occurs or end-of-file is reached.  On error, errno is set
appropriately.

EBADF   - Invalid directory stream descriptor dir
do_readdir Description : The do_readdir () function returns a pointer to a dirent structure representing the next directory entry in the directory stream pointed to by dir . It returns NULL on reaching the end - of - file or if an error occurred . Input Parameters : dirp -- An instance of type DIR created by a previous call to opendir () . Returned Value : The do_readdir () function returns a pointer to a dirent structure or NULL if an error occurs or end - of - file is reached . On error errno is set appropriately . EBADF - Invalid directory stream descriptor dir
static struct dirent *__readdir(DIR *dirp, int *lencnt)
{
  struct fs_dirent_s *idir = (struct fs_dirent_s *)dirp;
  struct Vnode *vnode_ptr = NULL;
  int ret = 0;
  int file_cnt = 0;
  if (!idir)
    {
      ret = -EBADF;
      goto errout;
    }
  vnode_ptr = idir->fd_root;
  if (vnode_ptr == NULL)
    {
      ret = -ENOENT;
      goto errout;
    }
#ifdef LOSCFG_ENABLE_READ_BUFFER
  idir->read_cnt = MAX_DIRENT_NUM;
#else
  idir->read_cnt = 1;
#endif
  if (vnode_ptr->vop != NULL && vnode_ptr->vop->Readdir != NULL)
    {
      file_cnt = vnode_ptr->vop->Readdir(vnode_ptr, idir);
    }
  else
    {
      ret = -ENOSYS;
      goto errout;
    }
  if (file_cnt > 0)
    {
      *lencnt = file_cnt * sizeof(struct dirent);
      return &(idir->fd_dir[0]);
    }
errout:
  if (ret < 0)
    {
      set_errno(ret);
    }
  else if (file_cnt <= 0)
    {
      set_errno(ENOENT);
    }
  return (struct dirent *)NULL;
}
static struct dirent * __readdir ( DIR * dirp , int * lencnt ) { struct fs_dirent_s * idir = ( struct fs_dirent_s * ) dirp ; struct Vnode * vnode_ptr = NULL ; int ret = 0 ; int file_cnt = 0 ; if ( ! idir ) { ret = - EBADF ; goto errout ; } vnode_ptr = idir -> fd_root ; if ( vnode_ptr == NULL ) { ret = - ENOENT ; goto errout ; } #ifdef LOSCFG_ENABLE_READ_BUFFER idir -> read_cnt = MAX_DIRENT_NUM ; #else idir -> read_cnt = 1 ; #endif if ( vnode_ptr -> vop != NULL && vnode_ptr -> vop -> Readdir != NULL ) { file_cnt = vnode_ptr -> vop -> Readdir ( vnode_ptr , idir ) ; } else { ret = - ENOSYS ; goto errout ; } if ( file_cnt > 0 ) { * lencnt = file_cnt * sizeof ( struct dirent ) ; return & ( idir -> fd_dir [ 0 ] ) ; } errout : if ( ret < 0 ) { set_errno ( ret ) ; } else if ( file_cnt <= 0 ) { set_errno ( ENOENT ) ; } return ( struct dirent * ) NULL ; }
Name: do_readdir
 Description:
   The do_readdir() function returns a pointer to a dirent structure
   representing the next directory entry in the directory stream pointed
   to by dir.
Name : do_readdir Description : The do_readdir () function returns a pointer to a dirent structure representing the next directory entry in the directory stream pointed to by dir .
/* Verify that we were provided with a valid directory structure */ /* End of file and error conditions are not distinguishable
       * with readdir.  We return NULL to signal either case.
       */ /* Perform the readdir() operation */