1
0
Fork 0
forked from nuttx/nuttx-update

libs/libc/unistd: Implement pipe2(2) syscall

See the reference here:
https://www.man7.org/linux/man-pages/man2/pipe2.2.html

Change-Id: Ife19b9bdbde73c7421be381a094da67017819e63
Signed-off-by: chao.an <anchao@xiaomi.com>
This commit is contained in:
chao.an 2020-08-28 18:00:26 +08:00 committed by Xiang Xiao
parent 8f52d4536c
commit 614ac5b0f2
8 changed files with 94 additions and 36 deletions

View file

@ -186,7 +186,7 @@ static int pipe_close(FAR struct file *filep)
*
****************************************************************************/
int nx_pipe(int fd[2], size_t bufsize)
int nx_pipe(int fd[2], size_t bufsize, int flags)
{
FAR struct pipe_dev_s *dev = NULL;
char devname[16];
@ -249,7 +249,7 @@ int nx_pipe(int fd[2], size_t bufsize)
/* Get a write file descriptor */
fd[1] = nx_open(devname, O_WRONLY);
fd[1] = nx_open(devname, O_WRONLY | flags);
if (fd[1] < 0)
{
ret = fd[1];
@ -258,7 +258,7 @@ int nx_pipe(int fd[2], size_t bufsize)
/* Get a read file descriptor */
fd[0] = nx_open(devname, O_RDONLY);
fd[0] = nx_open(devname, O_RDONLY | flags);
if (fd[0] < 0)
{
ret = fd[0];

View file

@ -1119,13 +1119,13 @@ int pty_register(int minor)
* pipe_b: Master sink, slave source (RX, master-to-slave)
*/
ret = nx_pipe(pipe_a, CONFIG_PSEUDOTERM_TXBUFSIZE);
ret = nx_pipe(pipe_a, CONFIG_PSEUDOTERM_TXBUFSIZE, 0);
if (ret < 0)
{
goto errout_with_devpair;
}
ret = nx_pipe(pipe_b, CONFIG_PSEUDOTERM_RXBUFSIZE);
ret = nx_pipe(pipe_b, CONFIG_PSEUDOTERM_RXBUFSIZE, 0);
if (ret < 0)
{
goto errout_with_pipea;

View file

@ -233,6 +233,7 @@ ssize_t bchlib_write(FAR void *handle, FAR const char *buffer, size_t offset,
* fd[2] - The user provided array in which to catch the pipe file
* descriptors
* bufsize - The size of the in-memory, circular buffer in bytes.
* flags - The file status flags.
*
* Returned Value:
* 0 is returned on success; otherwise, the negative error code return
@ -241,7 +242,7 @@ ssize_t bchlib_write(FAR void *handle, FAR const char *buffer, size_t offset,
****************************************************************************/
#if defined(CONFIG_PIPES) && CONFIG_DEV_PIPE_SIZE > 0
int nx_pipe(int fd[2], size_t bufsize);
int nx_pipe(int fd[2], size_t bufsize, int flags);
#endif
/****************************************************************************

View file

@ -343,6 +343,7 @@ FAR void *sbrk(intptr_t incr);
/* Special devices */
int pipe(int fd[2]);
int pipe2(int pipefd[2], int flags);
/* Schedule an alarm */

View file

@ -60,7 +60,7 @@ CSRCS += lib_truncate.c
endif
ifeq ($(CONFIG_PIPES),y)
CSRCS += lib_pipe.c
CSRCS += lib_pipe.c lib_pipe2.c
endif
CSRCS += lib_gethostname.c lib_sethostname.c

View file

@ -1,35 +1,20 @@
/****************************************************************************
* libs/libc/unistd/lib_pipe.c
*
* Copyright (C) 2016 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
* 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
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* http://www.apache.org/licenses/LICENSE-2.0
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
* 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.
*
****************************************************************************/
@ -72,7 +57,7 @@ int pipe(int fd[2])
{
int ret;
ret = nx_pipe(fd, CONFIG_DEV_PIPE_SIZE);
ret = nx_pipe(fd, CONFIG_DEV_PIPE_SIZE, 0);
if (ret < 0)
{
set_errno(-ret);

View file

@ -0,0 +1,71 @@
/****************************************************************************
* libs/libc/unistd/lib_pipe2.c
*
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <errno.h>
#include <unistd.h>
#include <nuttx/drivers/drivers.h>
#if defined(CONFIG_PIPES) && CONFIG_DEV_PIPE_SIZE > 0
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: pipe2
*
* Description:
* pipe2() creates a pair of file descriptors, pointing to a pipe inode,
* and places them in the array pointed to by 'fd'. fd[0] is for reading,
* fd[1] is for writing. If flags is 0, then pipe2() is the same as pipe().
*
* Input Parameters:
* fd[2] - The user provided array in which to catch the pipe file
* descriptors
* flags - The file status flags.
*
* Returned Value:
* 0 is returned on success; otherwise, -1 is returned with errno set
* appropriately.
*
****************************************************************************/
int pipe2(int fd[2], int flags)
{
int ret;
ret = nx_pipe(fd, CONFIG_DEV_PIPE_SIZE, flags);
if (ret < 0)
{
set_errno(-ret);
ret = ERROR;
}
return ret;
}
#endif /* CONFIG_PIPES && CONFIG_DEV_PIPE_SIZE > 0 */

View file

@ -64,7 +64,7 @@
"mq_unlink","mqueue.h","!defined(CONFIG_DISABLE_MQUEUE)","int","FAR const char *"
"munmap","sys/mman.h","defined(CONFIG_FS_RAMMAP)","int","FAR void *","size_t"
"nx_mkfifo","nuttx/drivers/drivers.h","defined(CONFIG_PIPES) && CONFIG_DEV_FIFO_SIZE > 0","int","FAR const char *","mode_t","size_t"
"nx_pipe","nuttx/drivers/drivers.h","defined(CONFIG_PIPES) && CONFIG_DEV_PIPE_SIZE > 0","int","int [2]|FAR int *","size_t"
"nx_pipe","nuttx/drivers/drivers.h","defined(CONFIG_PIPES) && CONFIG_DEV_PIPE_SIZE > 0","int","int [2]|FAR int *","size_t","int"
"nx_task_spawn","nuttx/spawn.h","defined(CONFIG_LIB_SYSCALL) && !defined(CONFIG_BUILD_KERNEL)","int","FAR const struct spawn_syscall_parms_s *"
"nx_vsyslog","nuttx/syslog/syslog.h","","int","int","FAR const IPTR char *","FAR va_list *"
"on_exit","stdlib.h","defined(CONFIG_SCHED_ONEXIT)","int","CODE void (*)(int, FAR void *)","FAR void *"

Can't render this file because it has a wrong number of fields in line 2.