2007-12-28 02:44:34 +01:00
|
|
|
/****************************************************************************
|
2016-08-07 16:25:30 +02:00
|
|
|
* sched/group/group_setupstreams.c
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2020-05-23 06:58:52 +02:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2020-05-23 06:58:52 +02:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2020-05-23 06:58:52 +02:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2007-12-28 02:44:34 +01:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2007-12-28 02:44:34 +01:00
|
|
|
/****************************************************************************
|
2007-02-18 00:21:28 +01:00
|
|
|
* Included Files
|
2007-12-28 02:44:34 +01:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
2007-09-01 20:06:15 +02:00
|
|
|
|
2007-02-18 00:21:28 +01:00
|
|
|
#include <sched.h>
|
2011-04-05 01:02:00 +02:00
|
|
|
#include <fcntl.h>
|
|
|
|
|
2012-03-21 19:01:07 +01:00
|
|
|
#include <nuttx/fs/fs.h>
|
2012-03-04 00:18:34 +01:00
|
|
|
#include <nuttx/net/net.h>
|
2016-07-21 22:05:44 +02:00
|
|
|
#include <nuttx/lib/lib.h>
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2014-08-08 22:06:42 +02:00
|
|
|
#include "group/group.h"
|
2013-01-27 16:52:58 +01:00
|
|
|
|
2012-07-14 21:30:31 +02:00
|
|
|
/* Make sure that there are file or socket descriptors in the system and
|
|
|
|
* that some number of streams have been configured.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#if CONFIG_NFILE_STREAMS > 0
|
2007-12-28 02:44:34 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
2007-02-18 00:21:28 +01:00
|
|
|
* Public Functions
|
2007-12-28 02:44:34 +01:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2012-07-14 21:30:31 +02:00
|
|
|
/****************************************************************************
|
2013-01-27 00:49:02 +01:00
|
|
|
* Name: group_setupstreams
|
2012-07-14 21:30:31 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Setup streams data structures that may be used for standard C buffered
|
2015-08-16 19:07:23 +02:00
|
|
|
* I/O with underlying socket or file descriptors
|
2012-07-14 21:30:31 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2013-02-04 22:24:00 +01:00
|
|
|
int group_setupstreams(FAR struct task_tcb_s *tcb)
|
2007-02-18 00:21:28 +01:00
|
|
|
{
|
2013-02-04 22:24:00 +01:00
|
|
|
DEBUGASSERT(tcb && tcb->cmn.group);
|
2013-01-26 23:25:21 +01:00
|
|
|
|
|
|
|
/* Initialize file streams for the task group */
|
|
|
|
|
2014-09-11 16:37:06 +02:00
|
|
|
lib_stream_initialize(tcb->cmn.group);
|
2013-01-26 23:25:21 +01:00
|
|
|
|
|
|
|
/* 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)
|
|
|
|
*/
|
|
|
|
|
2020-05-23 06:58:52 +02:00
|
|
|
fs_fdopen(0, O_RDONLY, (FAR struct tcb_s *)tcb, NULL);
|
|
|
|
fs_fdopen(1, O_WROK | O_CREAT, (FAR struct tcb_s *)tcb, NULL);
|
|
|
|
fs_fdopen(2, O_WROK | O_CREAT, (FAR struct tcb_s *)tcb, NULL);
|
2007-02-18 00:21:28 +01:00
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2012-07-14 21:30:31 +02:00
|
|
|
#endif /* CONFIG_NFILE_STREAMS > 0 */
|