int group_setuptaskfiles(FAR struct task_tcb_s *tcb)
{
#if CONFIG_NFILE_DESCRIPTORS > 0 || CONFIG_NSOCKET_DESCRIPTORS > 0
  FAR struct task_group_s *group = tcb->cmn.group;

  DEBUGASSERT(group);
#endif
#ifndef CONFIG_DISABLE_PTHREAD
  DEBUGASSERT((tcb->cmn.flags & TCB_FLAG_TTYPE_MASK) != TCB_FLAG_TTYPE_PTHREAD);
#endif

#if CONFIG_NFILE_DESCRIPTORS > 0
  /* Initialize file descriptors for the TCB */

  files_initlist(&group->tg_filelist);
#endif

#if CONFIG_NSOCKET_DESCRIPTORS > 0
  /* Allocate socket descriptors for the TCB */

  net_initlist(&group->tg_socketlist);
#endif

  /* Duplicate the parent task's file descriptors */

  sched_dupfiles(tcb);

  /* Duplicate the parent task's socket descriptors */

  sched_dupsockets(tcb);

  /* Allocate file/socket streams for the new TCB */

#if CONFIG_NFILE_STREAMS > 0
  return group_setupstreams(tcb);
#else
  return OK;
#endif
}
int sched_setuptaskfiles(FAR _TCB *tcb)
{
  /* Allocate file descriptors for the TCB */

#if CONFIG_NFILE_DESCRIPTORS > 0
  tcb->filelist = files_alloclist();
  if (!tcb->filelist)
    {
      return -ENOMEM;
    }
#endif

  /* Allocate socket descriptors for the TCB */

#if CONFIG_NSOCKET_DESCRIPTORS > 0
  tcb->sockets = net_alloclist();
  if (!tcb->sockets)
    {
      return -ENOMEM;
    }
#endif

  /* Duplicate the parent task's file descriptors */

  sched_dupfiles(tcb);

  /* Duplicate the parent task's socket descriptors */

  sched_dupsockets(tcb);

  /* Allocate file/socket streams for the new TCB */

#if CONFIG_NFILE_STREAMS > 0
  return sched_setupstreams(tcb);
#else
  return OK;
#endif
}