Exemple #1
0
int group_setupstreams(FAR struct task_tcb_s *tcb)
{
    DEBUGASSERT(tcb && tcb->cmn.group);

    /* Initialize file streams for the task group */

    lib_stream_initialize(tcb->cmn.group);

    /* fdopen to get the stdin, stdout and stderr streams. The following logic
     * depends on the fact that the library layer will allocate FILEs in order.
     *
     * fd = 0 is stdin  (read-only)
     * fd = 1 is stdout (write-only, append)
     * fd = 2 is stderr (write-only, append)
     */

    (void)fs_fdopen(0, O_RDONLY,         (FAR struct tcb_s *)tcb);
    (void)fs_fdopen(1, O_WROK | O_CREAT, (FAR struct tcb_s *)tcb);
    (void)fs_fdopen(2, O_WROK | O_CREAT, (FAR struct tcb_s *)tcb);

    return OK;
}
int sched_setupstreams(FAR _TCB *tcb)
{
  /* Allocate file strems for the TCB */

  tcb->streams = lib_alloclist();
  if (tcb->streams)
    {
      /* fdopen to get the stdin, stdout and stderr streams.
       * The following logic depends on the fact that the library
       * layer will allocate FILEs in order.
       *
       * fd = 0 is stdin  (read-only)
       * fd = 1 is stdout (write-only, append)
       * fd = 2 is stderr (write-only, append)
       */

      (void)fs_fdopen(0, O_RDONLY,       tcb);
      (void)fs_fdopen(1, O_WROK|O_CREAT, tcb);
      (void)fs_fdopen(2, O_WROK|O_CREAT, tcb);
    }

  return OK;
}
Exemple #3
0
FAR FILE *fdopen(int fd, FAR const char *mode)
{
  FAR FILE *ret = NULL;
  int oflags;

  /* Map the open mode string to open flags */

  oflags = lib_mode2oflags(mode);
  if (oflags >= 0)
    {
      ret = fs_fdopen(fd, oflags, NULL);
    }

  return ret;
}
Exemple #4
0
FAR FILE *fopen(FAR const char *path, FAR const char *mode)
{
  FAR FILE *ret = NULL;
  int oflags;
  int fd;

  /* Map the open mode string to open flags */

  oflags = lib_mode2oflags(mode);
  if (oflags < 0)
    {
      return NULL;
    }

  /* Open the file */

  fd = open(path, oflags, 0666);

  /* If the open was successful, then fdopen() the fil using the file
   * desciptor returned by open.  If open failed, then just return the
   * NULL stream -- open() has already set the errno.
   */

  if (fd >= 0)
    {
      ret = fs_fdopen(fd, oflags, NULL);
      if (!ret)
        {
          /* Don't forget to close the file descriptor if any other
           * failures are reported by fdopen().
           */

          (void)close(fd);
        }
    }
  return ret;
}