2007-12-28 01:44:34 +00:00
|
|
|
/****************************************************************************
|
2016-08-07 08:25:30 -06:00
|
|
|
* sched/group/group_setupstreams.c
|
2007-02-17 23:21:28 +00:00
|
|
|
*
|
2020-05-22 22:58:52 -06: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-17 23:21:28 +00:00
|
|
|
*
|
2020-05-22 22:58:52 -06:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2007-02-17 23:21:28 +00:00
|
|
|
*
|
2020-05-22 22:58:52 -06: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-17 23:21:28 +00:00
|
|
|
*
|
2007-12-28 01:44:34 +00:00
|
|
|
****************************************************************************/
|
2007-02-17 23:21:28 +00:00
|
|
|
|
2007-12-28 01:44:34 +00:00
|
|
|
/****************************************************************************
|
2007-02-17 23:21:28 +00:00
|
|
|
* Included Files
|
2007-12-28 01:44:34 +00:00
|
|
|
****************************************************************************/
|
2007-02-17 23:21:28 +00:00
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
2007-09-01 18:06:15 +00:00
|
|
|
|
2007-02-17 23:21:28 +00:00
|
|
|
#include <sched.h>
|
2011-04-04 23:02:00 +00:00
|
|
|
#include <fcntl.h>
|
|
|
|
|
2012-03-21 18:01:07 +00:00
|
|
|
#include <nuttx/fs/fs.h>
|
2012-03-03 23:18:34 +00:00
|
|
|
#include <nuttx/net/net.h>
|
2016-07-21 14:05:44 -06:00
|
|
|
#include <nuttx/lib/lib.h>
|
2007-02-17 23:21:28 +00:00
|
|
|
|
2014-08-08 14:06:42 -06:00
|
|
|
#include "group/group.h"
|
2013-01-27 15:52:58 +00:00
|
|
|
|
2012-07-14 19:30:31 +00: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 01:44:34 +00:00
|
|
|
|
|
|
|
/****************************************************************************
|
2007-02-17 23:21:28 +00:00
|
|
|
* Public Functions
|
2007-12-28 01:44:34 +00:00
|
|
|
****************************************************************************/
|
2007-02-17 23:21:28 +00:00
|
|
|
|
2012-07-14 19:30:31 +00:00
|
|
|
/****************************************************************************
|
2013-01-26 23:49:02 +00:00
|
|
|
* Name: group_setupstreams
|
2012-07-14 19:30:31 +00:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Setup streams data structures that may be used for standard C buffered
|
2015-08-16 11:07:23 -06:00
|
|
|
* I/O with underlying socket or file descriptors
|
2012-07-14 19:30:31 +00:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2013-02-04 21:24:00 +00:00
|
|
|
int group_setupstreams(FAR struct task_tcb_s *tcb)
|
2007-02-17 23:21:28 +00:00
|
|
|
{
|
2013-02-04 21:24:00 +00:00
|
|
|
DEBUGASSERT(tcb && tcb->cmn.group);
|
2013-01-26 22:25:21 +00:00
|
|
|
|
|
|
|
/* Initialize file streams for the task group */
|
|
|
|
|
2014-09-11 08:37:06 -06:00
|
|
|
lib_stream_initialize(tcb->cmn.group);
|
2013-01-26 22:25:21 +00: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-22 22:58:52 -06: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-17 23:21:28 +00:00
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2012-07-14 19:30:31 +00:00
|
|
|
#endif /* CONFIG_NFILE_STREAMS > 0 */
|