Move pipe() and mkpipe() to nuttx/libc. Change syscalls to pipe2() and mkfifo2()
This commit is contained in:
parent
671d7fae31
commit
b28fa8a609
@ -130,38 +130,4 @@ int mkfifo2(FAR const char *pathname, mode_t mode, size_t bufsize)
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: mkfifo
|
||||
*
|
||||
* Description:
|
||||
* mkfifo() makes a FIFO device driver file with name 'pathname.' Unlike
|
||||
* Linux, a NuttX FIFO is not a special file type but simply a device
|
||||
* driver instance. 'mode' specifies the FIFO's permissions.
|
||||
*
|
||||
* Once the FIFO has been created by mkfifo(), any thread can open it for
|
||||
* reading or writing, in the same way as an ordinary file. However, it
|
||||
* must have been opened from both reading and writing before input or
|
||||
* output can be performed. This FIFO implementation will block all
|
||||
* attempts to open a FIFO read-only until at least one thread has opened
|
||||
* the FIFO for writing.
|
||||
*
|
||||
* If all threads that write to the FIFO have closed, subsequent calls to
|
||||
* read() on the FIFO will return 0 (end-of-file).
|
||||
*
|
||||
* Inputs:
|
||||
* pathname - The full path to the FIFO instance to attach to or to create
|
||||
* (if not already created).
|
||||
* mode - Ignored for now
|
||||
*
|
||||
* Return:
|
||||
* 0 is returned on success; otherwise, -1 is returned with errno set
|
||||
* appropriately.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int mkfifo(FAR const char *pathname, mode_t mode)
|
||||
{
|
||||
return mkfifo2(pathname, mode, CONFIG_DEV_FIFO_SIZE);
|
||||
}
|
||||
|
||||
#endif /* CONFIG_DEV_FIFO_SIZE > 0 */
|
||||
|
@ -294,26 +294,4 @@ errout:
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: pipe2
|
||||
*
|
||||
* Description:
|
||||
* pipe() 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.
|
||||
*
|
||||
* Inputs:
|
||||
* fd[2] - The user provided array in which to catch the pipe file
|
||||
* descriptors
|
||||
*
|
||||
* Return:
|
||||
* 0 is returned on success; otherwise, -1 is returned with errno set
|
||||
* appropriately.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int pipe(int fd[2])
|
||||
{
|
||||
return pipe2(fd, CONFIG_DEV_PIPE_SIZE);
|
||||
}
|
||||
#endif /* CONFIG_DEV_PIPE_SIZE > 0 */
|
||||
|
@ -292,11 +292,11 @@
|
||||
# define SYS_dup2 (__SYS_filedesc+2)
|
||||
# define SYS_fcntl (__SYS_filedesc+3)
|
||||
# define SYS_lseek (__SYS_filedesc+4)
|
||||
# define SYS_mkfifo (__SYS_filedesc+5)
|
||||
# define SYS_mkfifo2 (__SYS_filedesc+5)
|
||||
# define SYS_mmap (__SYS_filedesc+6)
|
||||
# define SYS_open (__SYS_filedesc+7)
|
||||
# define SYS_opendir (__SYS_filedesc+8)
|
||||
# define SYS_pipe (__SYS_filedesc+9)
|
||||
# define SYS_pipe2 (__SYS_filedesc+9)
|
||||
# define SYS_readdir (__SYS_filedesc+10)
|
||||
# define SYS_rewinddir (__SYS_filedesc+11)
|
||||
# define SYS_seekdir (__SYS_filedesc+12)
|
||||
|
@ -1,7 +1,7 @@
|
||||
############################################################################
|
||||
# libc/misc/Make.defs
|
||||
#
|
||||
# Copyright (C) 2011-2012, 2014 Gregory Nutt. All rights reserved.
|
||||
# Copyright (C) 2011-2012, 2014, 2016 Gregory Nutt. All rights reserved.
|
||||
# Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
@ -57,7 +57,11 @@ ifeq ($(CONFIG_LIBC_IOCTL_VARIADIC),y)
|
||||
CSRCS += lib_ioctl.c
|
||||
endif
|
||||
|
||||
else
|
||||
ifeq ($(CONFIG_PIPES),y)
|
||||
CSRCS += lib_mkfifo.c
|
||||
endif
|
||||
|
||||
else # CONFIG_NFILE_DESCRIPTORS > 0
|
||||
ifneq ($(CONFIG_NSOCKET_DESCRIPTORS),0)
|
||||
|
||||
CSRCS += lib_sendfile.c
|
||||
@ -70,8 +74,8 @@ ifeq ($(CONFIG_LIBC_IOCTL_VARIADIC),y)
|
||||
CSRCS += lib_ioctl.c
|
||||
endif
|
||||
|
||||
endif
|
||||
endif
|
||||
endif # CONFIG_NSOCKET_DESCRIPTORS > 0
|
||||
endif # CONFIG_NFILE_DESCRIPTORS > 0
|
||||
|
||||
# Add the miscellaneous C files to the build
|
||||
|
||||
|
86
libc/misc/lib_mkfifo.c
Normal file
86
libc/misc/lib_mkfifo.c
Normal file
@ -0,0 +1,86 @@
|
||||
/****************************************************************************
|
||||
* libc/misc/lib_mkfifo.c
|
||||
*
|
||||
* Copyright (C) 2016 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#if CONFIG_DEV_FIFO_SIZE > 0
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: mkfifo
|
||||
*
|
||||
* Description:
|
||||
* mkfifo() makes a FIFO device driver file with name 'pathname.' Unlike
|
||||
* Linux, a NuttX FIFO is not a special file type but simply a device
|
||||
* driver instance. 'mode' specifies the FIFO's permissions.
|
||||
*
|
||||
* Once the FIFO has been created by mkfifo(), any thread can open it for
|
||||
* reading or writing, in the same way as an ordinary file. However, it
|
||||
* must have been opened from both reading and writing before input or
|
||||
* output can be performed. This FIFO implementation will block all
|
||||
* attempts to open a FIFO read-only until at least one thread has opened
|
||||
* the FIFO for writing.
|
||||
*
|
||||
* If all threads that write to the FIFO have closed, subsequent calls to
|
||||
* read() on the FIFO will return 0 (end-of-file).
|
||||
*
|
||||
* Inputs:
|
||||
* pathname - The full path to the FIFO instance to attach to or to create
|
||||
* (if not already created).
|
||||
* mode - Ignored for now
|
||||
*
|
||||
* Return:
|
||||
* 0 is returned on success; otherwise, -1 is returned with errno set
|
||||
* appropriately.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int mkfifo(FAR const char *pathname, mode_t mode)
|
||||
{
|
||||
return mkfifo2(pathname, mode, CONFIG_DEV_FIFO_SIZE);
|
||||
}
|
||||
|
||||
#endif /* CONFIG_DEV_FIFO_SIZE > 0 */
|
||||
|
@ -46,6 +46,10 @@ endif
|
||||
ifeq ($(CONFIG_LIBC_EXECFUNCS),y)
|
||||
CSRCS += lib_execl.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_PIPES),y)
|
||||
CSRCS += lib_pipe.c
|
||||
endif
|
||||
endif
|
||||
|
||||
ifneq ($(CONFIG_DISABLE_SIGNALS),y)
|
||||
|
74
libc/unistd/lib_pipe.c
Normal file
74
libc/unistd/lib_pipe.c
Normal file
@ -0,0 +1,74 @@
|
||||
/****************************************************************************
|
||||
* libc/unistd/lib_pipe.c
|
||||
*
|
||||
* Copyright (C) 2016 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
#if CONFIG_DEV_PIPE_SIZE > 0
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: pipe
|
||||
*
|
||||
* Description:
|
||||
* pipe() 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.
|
||||
*
|
||||
* Inputs:
|
||||
* fd[2] - The user provided array in which to catch the pipe file
|
||||
* descriptors
|
||||
*
|
||||
* Return:
|
||||
* 0 is returned on success; otherwise, -1 is returned with errno set
|
||||
* appropriately.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int pipe(int fd[2])
|
||||
{
|
||||
return pipe2(fd, CONFIG_DEV_PIPE_SIZE);
|
||||
}
|
||||
|
||||
#endif /* CONFIG_DEV_PIPE_SIZE > 0 */
|
||||
|
@ -34,7 +34,7 @@
|
||||
"listen","sys/socket.h","CONFIG_NSOCKET_DESCRIPTORS > 0 && defined(CONFIG_NET)","int","int","int"
|
||||
"lseek","unistd.h","CONFIG_NFILE_DESCRIPTORS > 0","off_t","int","off_t","int"
|
||||
"mkdir","sys/stat.h","CONFIG_NFILE_DESCRIPTORS > 0 && !defined(CONFIG_DISABLE_MOUNTPOINT)","int","FAR const char*","mode_t"
|
||||
"mkfifo","sys/stat.h","CONFIG_NFILE_DESCRIPTORS > 0","int","FAR const char*","mode_t"
|
||||
"mkfifo2","sys/stat.h","CONFIG_NFILE_DESCRIPTORS > 0","int","FAR const char*","mode_t","size_t"
|
||||
"mmap","sys/mman.h","CONFIG_NFILE_DESCRIPTORS > 0","FAR void*","FAR void*","size_t","int","int","int","off_t"
|
||||
"mount","sys/mount.h","CONFIG_NFILE_DESCRIPTORS > 0 && !defined(CONFIG_DISABLE_MOUNTPOINT) && defined(CONFIG_FS_READABLE)","int","const char*","const char*","const char*","unsigned long","const void*"
|
||||
"mq_close","mqueue.h","!defined(CONFIG_DISABLE_MQUEUE)","int","mqd_t"
|
||||
@ -52,7 +52,7 @@
|
||||
"open","fcntl.h","CONFIG_NFILE_DESCRIPTORS > 0","int","const char*","int","..."
|
||||
"opendir","dirent.h","CONFIG_NFILE_DESCRIPTORS > 0","FAR DIR*","FAR const char*"
|
||||
"pgalloc", "nuttx/arch.h", "defined(CONFIG_BUILD_KERNEL)", "uintptr_t", "uintptr_t", "unsigned int"
|
||||
"pipe","unistd.h","CONFIG_NFILE_DESCRIPTORS > 0","int","int [2]|int*"
|
||||
"pipe2","unistd.h","CONFIG_NFILE_DESCRIPTORS > 0","int","int [2]|int*","size_t"
|
||||
"poll","poll.h","!defined(CONFIG_DISABLE_POLL) && (CONFIG_NSOCKET_DESCRIPTORS > 0 || CONFIG_NFILE_DESCRIPTORS > 0)","int","FAR struct pollfd*","nfds_t","int"
|
||||
"prctl","sys/prctl.h", "CONFIG_TASK_NAME_SIZE > 0","int","int","..."
|
||||
"pread","unistd.h","CONFIG_NSOCKET_DESCRIPTORS > 0 || CONFIG_NFILE_DESCRIPTORS > 0","ssize_t","int","FAR void*","size_t","off_t"
|
||||
|
Can't render this file because it has a wrong number of fields in line 2.
|
@ -183,10 +183,10 @@ SYSCALL_LOOKUP(up_assert, 2, STUB_up_assert)
|
||||
SYSCALL_LOOKUP(pread, 4, STUB_pread)
|
||||
SYSCALL_LOOKUP(pwrite, 4, STUB_pwrite)
|
||||
# ifdef CONFIG_FS_AIO
|
||||
SYSCALL_LOOKUP(aio_read, 1, SYS_aio_read)
|
||||
SYSCALL_LOOKUP(aio_write, 1, SYS_aio_write)
|
||||
SYSCALL_LOOKUP(aio_fsync, 2, SYS_aio_fsync)
|
||||
SYSCALL_LOOKUP(aio_cancel, 2, SYS_aio_cancel)
|
||||
SYSCALL_LOOKUP(aio_read, 1, STUB_aio_read)
|
||||
SYSCALL_LOOKUP(aio_write, 1, STUB_aio_write)
|
||||
SYSCALL_LOOKUP(aio_fsync, 2, STUB_aio_fsync)
|
||||
SYSCALL_LOOKUP(aio_cancel, 2, STUB_aio_cancel)
|
||||
# endif
|
||||
# ifndef CONFIG_DISABLE_POLL
|
||||
SYSCALL_LOOKUP(poll, 3, STUB_poll)
|
||||
@ -208,11 +208,11 @@ SYSCALL_LOOKUP(up_assert, 2, STUB_up_assert)
|
||||
SYSCALL_LOOKUP(dup2, 2, STUB_dup2)
|
||||
SYSCALL_LOOKUP(fcntl, 6, STUB_fcntl)
|
||||
SYSCALL_LOOKUP(lseek, 3, STUB_lseek)
|
||||
SYSCALL_LOOKUP(mkfifo, 2, STUB_mkfifo)
|
||||
SYSCALL_LOOKUP(mkfifo2, 3, STUB_mkfifo2)
|
||||
SYSCALL_LOOKUP(mmap, 6, STUB_mmap)
|
||||
SYSCALL_LOOKUP(open, 6, STUB_open)
|
||||
SYSCALL_LOOKUP(opendir, 1, STUB_opendir)
|
||||
SYSCALL_LOOKUP(pipe, 1, STUB_pipe)
|
||||
SYSCALL_LOOKUP(pipe2, 2, STUB_pipe2)
|
||||
SYSCALL_LOOKUP(readdir, 1, STUB_readdir)
|
||||
SYSCALL_LOOKUP(rewinddir, 1, STUB_rewinddir)
|
||||
SYSCALL_LOOKUP(seekdir, 2, STUB_seekdir)
|
||||
|
@ -214,7 +214,8 @@ uintptr_t STUB_fcntl(int nbr, uintptr_t parm1, uintptr_t parm2,
|
||||
uintptr_t parm6);
|
||||
uintptr_t STUB_lseek(int nbr, uintptr_t parm1, uintptr_t parm2,
|
||||
uintptr_t parm3);
|
||||
uintptr_t STUB_mkfifo(int nbr, uintptr_t parm1, uintptr_t parm2);
|
||||
uintptr_t STUB_mkfifo2(int nbr, uintptr_t parm1, uintptr_t parm2,
|
||||
uintptr_t parm3);
|
||||
uintptr_t STUB_mmap(int nbr, uintptr_t parm1, uintptr_t parm2,
|
||||
uintptr_t parm3, uintptr_t parm4, uintptr_t parm5,
|
||||
uintptr_t parm6);
|
||||
@ -222,7 +223,7 @@ uintptr_t STUB_open(int nbr, uintptr_t parm1, uintptr_t parm2,
|
||||
uintptr_t parm3, uintptr_t parm4, uintptr_t parm5,
|
||||
uintptr_t parm6);
|
||||
uintptr_t STUB_opendir(int nbr, uintptr_t parm1);
|
||||
uintptr_t STUB_pipe(int nbr, uintptr_t parm1);
|
||||
uintptr_t STUB_pipe2(int nbr, uintptr_t parm1, uinptr_t parm2);
|
||||
uintptr_t STUB_readdir(int nbr, uintptr_t parm1);
|
||||
uintptr_t STUB_rewinddir(int nbr, uintptr_t parm1);
|
||||
uintptr_t STUB_seekdir(int nbr, uintptr_t parm1, uintptr_t parm2);
|
||||
|
Loading…
Reference in New Issue
Block a user