diff --git a/drivers/pipes/fifo.c b/drivers/pipes/fifo.c index cf32107f0ea..497559d1900 100644 --- a/drivers/pipes/fifo.c +++ b/drivers/pipes/fifo.c @@ -74,15 +74,15 @@ static const struct file_operations fifo_fops = ****************************************************************************/ /**************************************************************************** - * Name: mkfifo2 + * Name: nx_mkfifo * * Description: - * mkfifo() makes a FIFO device driver file with name 'pathname.' Unlike + * nx_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 + * Once the FIFO has been created by nx_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 @@ -91,7 +91,7 @@ static const struct file_operations fifo_fops = * If all threads that write to the FIFO have closed, subsequent calls to * read() on the FIFO will return 0 (end-of-file). * - * NOTE: mkfifo2 is a special, non-standard, NuttX-only interface. Since + * NOTE: nx_mkfifo is a special, non-standard, NuttX-only interface. Since * the NuttX FIFOs are based in in-memory, circular buffers, the ability * to control the size of those buffers is critical for system tuning. * @@ -102,15 +102,14 @@ static const struct file_operations fifo_fops = * bufsize - The size of the in-memory, circular buffer in bytes. * * Returned Value: - * 0 is returned on success; otherwise, -1 is returned with errno set + * 0 is returned on success; otherwise, the negative error code return * appropriately. * ****************************************************************************/ -int mkfifo2(FAR const char *pathname, mode_t mode, size_t bufsize) +int nx_mkfifo(FAR const char *pathname, mode_t mode, size_t bufsize) { FAR struct pipe_dev_s *dev; - int errcode; int ret; /* Allocate and initialize a new device structure instance */ @@ -118,23 +117,16 @@ int mkfifo2(FAR const char *pathname, mode_t mode, size_t bufsize) dev = pipecommon_allocdev(bufsize); if (!dev) { - errcode = ENOMEM; - goto errout; + return -ENOMEM; } ret = register_driver(pathname, &fifo_fops, mode, (FAR void *)dev); if (ret != 0) { pipecommon_freedev(dev); - errcode = -ret; - goto errout; } - return OK; - -errout: - set_errno(errcode); - return ERROR; + return ret; } #endif /* CONFIG_DEV_FIFO_SIZE > 0 */ diff --git a/drivers/pipes/pipe.c b/drivers/pipes/pipe.c index d595d1655c5..e5e70f9ed6a 100644 --- a/drivers/pipes/pipe.c +++ b/drivers/pipes/pipe.c @@ -164,14 +164,14 @@ static int pipe_close(FAR struct file *filep) ****************************************************************************/ /**************************************************************************** - * Name: pipe2 + * Name: nx_pipe * * Description: - * pipe() creates a pair of file descriptors, pointing to a pipe inode, + * nx_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. * - * NOTE: pipe2 is a special, non-standard, NuttX-only interface. Since + * NOTE: nx_pipe is a special, non-standard, NuttX-only interface. Since * the NuttX FIFOs are based in in-memory, circular buffers, the ability * to control the size of those buffers is critical for system tuning. * @@ -186,12 +186,11 @@ static int pipe_close(FAR struct file *filep) * ****************************************************************************/ -int pipe2(int fd[2], size_t bufsize) +int nx_pipe(int fd[2], size_t bufsize) { FAR struct pipe_dev_s *dev = NULL; char devname[16]; int pipeno; - int errcode; int ret; /* Get exclusive access to the pipe allocation data */ @@ -199,7 +198,6 @@ int pipe2(int fd[2], size_t bufsize) ret = nxsem_wait(&g_pipesem); if (ret < 0) { - errcode = -ret; goto errout; } @@ -209,7 +207,7 @@ int pipe2(int fd[2], size_t bufsize) if (pipeno < 0) { nxsem_post(&g_pipesem); - errcode = -pipeno; + ret = pipeno; goto errout; } @@ -227,7 +225,7 @@ int pipe2(int fd[2], size_t bufsize) if (!dev) { nxsem_post(&g_pipesem); - errcode = ENOMEM; + ret = -ENOMEM; goto errout_with_pipe; } @@ -239,7 +237,6 @@ int pipe2(int fd[2], size_t bufsize) if (ret != 0) { nxsem_post(&g_pipesem); - errcode = -ret; goto errout_with_dev; } @@ -255,7 +252,7 @@ int pipe2(int fd[2], size_t bufsize) fd[1] = nx_open(devname, O_WRONLY); if (fd[1] < 0) { - errcode = -fd[1]; + ret = fd[1]; goto errout_with_driver; } @@ -264,7 +261,7 @@ int pipe2(int fd[2], size_t bufsize) fd[0] = nx_open(devname, O_RDONLY); if (fd[0] < 0) { - errcode = -fd[0]; + ret = fd[0]; goto errout_with_wrfd; } @@ -286,8 +283,7 @@ errout_with_pipe: pipe_free(pipeno); errout: - set_errno(errcode); - return ERROR; + return ret; } #endif /* CONFIG_DEV_PIPE_SIZE > 0 */ diff --git a/drivers/serial/pty.c b/drivers/serial/pty.c index 3530b95cac0..429d5b3993a 100644 --- a/drivers/serial/pty.c +++ b/drivers/serial/pty.c @@ -292,7 +292,9 @@ static int pty_open(FAR struct file *filep) sched_lock(); while (devpair->pp_locked) { - /* Wait until unlocked. We will also most certainly suspend here. */ + /* Wait until unlocked. + * We will also most certainly suspend here. + */ ret = nxsem_wait(&devpair->pp_slavesem); if (ret < 0) @@ -966,7 +968,7 @@ static int pty_poll(FAR struct file *filep, FAR struct pollfd *fds, pollp = (FAR struct pty_poll_s *)fds->priv; } - /* POLLIN: Data other than high-priority data may be read without blocking. */ + /* POLLIN: Data may be read without blocking. */ if ((fds->events & POLLIN) != 0) { @@ -1070,8 +1072,8 @@ static int pty_unlink(FAR struct inode *inode) * minor - The number that qualifies the naming of the created devices. * * Returned Value: - * Zero (OK) is returned on success; a negated errno value is returned on - * any failure. + * 0 is returned on success; otherwise, the negative error code return + * appropriately. * ****************************************************************************/ @@ -1116,13 +1118,13 @@ int pty_register(int minor) * pipe_b: Master sink, slave source (RX, master-to-slave) */ - ret = pipe2(pipe_a, CONFIG_PSEUDOTERM_TXBUFSIZE); + ret = nx_pipe(pipe_a, CONFIG_PSEUDOTERM_TXBUFSIZE); if (ret < 0) { goto errout_with_devpair; } - ret = pipe2(pipe_b, CONFIG_PSEUDOTERM_RXBUFSIZE); + ret = nx_pipe(pipe_b, CONFIG_PSEUDOTERM_RXBUFSIZE); if (ret < 0) { goto errout_with_pipea; diff --git a/include/nuttx/drivers/drivers.h b/include/nuttx/drivers/drivers.h index 82ac9ff91a5..ad0813ee9d6 100644 --- a/include/nuttx/drivers/drivers.h +++ b/include/nuttx/drivers/drivers.h @@ -1,7 +1,8 @@ /**************************************************************************** * include/nuttx/fs/drivers.h * - * Copyright (C) 2007-2009, 2011-2013, 2015-2016 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009, 2011-2013, 2015-2016 Gregory Nutt. + * All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -165,8 +166,9 @@ int bchdev_register(FAR const char *blkdev, FAR const char *chardev, int bchdev_unregister(FAR const char *chardev); -/* Low level, direct access. NOTE: low-level access and character driver access - * are incompatible. One and only one access method should be implemented. +/* Low level, direct access. NOTE: low-level access and character driver + * access are incompatible. One and only one access method should be + * implemented. */ /**************************************************************************** @@ -216,14 +218,14 @@ ssize_t bchlib_write(FAR void *handle, FAR const char *buffer, size_t offset, size_t len); /**************************************************************************** - * Name: pipe2 + * Name: nx_pipe * * Description: - * pipe() creates a pair of file descriptors, pointing to a pipe inode, + * nx_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. * - * NOTE: pipe2 is a special, non-standard, NuttX-only interface. Since + * NOTE: nx_pipe is a special, non-standard, NuttX-only interface. Since * the NuttX FIFOs are based in in-memory, circular buffers, the ability * to control the size of those buffers is critical for system tuning. * @@ -233,25 +235,25 @@ ssize_t bchlib_write(FAR void *handle, FAR const char *buffer, size_t offset, * bufsize - The size of the in-memory, circular buffer in bytes. * * Returned Value: - * 0 is returned on success; otherwise, -1 is returned with errno set + * 0 is returned on success; otherwise, the negative error code return * appropriately. * ****************************************************************************/ #if defined(CONFIG_PIPES) && CONFIG_DEV_PIPE_SIZE > 0 -int pipe2(int fd[2], size_t bufsize); +int nx_pipe(int fd[2], size_t bufsize); #endif /**************************************************************************** - * Name: mkfifo2 + * Name: nx_mkfifo * * Description: - * mkfifo() makes a FIFO device driver file with name 'pathname.' Unlike + * nx_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 + * Once the FIFO has been created by nx_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 @@ -260,7 +262,7 @@ int pipe2(int fd[2], size_t bufsize); * If all threads that write to the FIFO have closed, subsequent calls to * read() on the FIFO will return 0 (end-of-file). * - * NOTE: mkfifo2 is a special, non-standard, NuttX-only interface. Since + * NOTE: nx_mkfifo is a special, non-standard, NuttX-only interface. Since * the NuttX FIFOs are based in in-memory, circular buffers, the ability * to control the size of those buffers is critical for system tuning. * @@ -271,13 +273,13 @@ int pipe2(int fd[2], size_t bufsize); * bufsize - The size of the in-memory, circular buffer in bytes. * * Returned Value: - * 0 is returned on success; otherwise, -1 is returned with errno set + * 0 is returned on success; otherwise, the negative error code return * appropriately. * ****************************************************************************/ #if defined(CONFIG_PIPES) && CONFIG_DEV_FIFO_SIZE > 0 -int mkfifo2(FAR const char *pathname, mode_t mode, size_t bufsize); +int nx_mkfifo(FAR const char *pathname, mode_t mode, size_t bufsize); #endif #undef EXTERN diff --git a/include/sys/syscall.h b/include/sys/syscall.h index 6fffa7c1423..6ee8655a839 100644 --- a/include/sys/syscall.h +++ b/include/sys/syscall.h @@ -371,17 +371,11 @@ #endif #if defined(CONFIG_PIPES) && CONFIG_DEV_PIPE_SIZE > 0 -# define SYS_pipe2 (__SYS_pipes + 0) -# define __SYS_mkfifo2 (__SYS_pipes + 1) +# define SYS_nx_pipe (__SYS_pipes + 0) +# define SYS_nx_mkfifo (__SYS_pipes + 1) +# define __SYS_fs_fdopen (__SYS_pipes + 2) #else -# define __SYS_mkfifo2 (__SYS_pipes + 0) -#endif - -#if defined(CONFIG_PIPES) && CONFIG_DEV_FIFO_SIZE > 0 -# define SYS_mkfifo2 (__SYS_mkfifo2 + 0) -# define __SYS_fs_fdopen (__SYS_mkfifo2 + 1) -#else -# define __SYS_fs_fdopen (__SYS_mkfifo2 + 0) +# define __SYS_fs_fdopen (__SYS_pipes + 0) #endif #if CONFIG_NFILE_STREAMS > 0 diff --git a/libs/libc/misc/lib_mkfifo.c b/libs/libc/misc/lib_mkfifo.c index 42aff2b063e..ec2ab01aea6 100644 --- a/libs/libc/misc/lib_mkfifo.c +++ b/libs/libc/misc/lib_mkfifo.c @@ -39,6 +39,7 @@ #include +#include #include #include @@ -81,7 +82,16 @@ int mkfifo(FAR const char *pathname, mode_t mode) { - return mkfifo2(pathname, mode, CONFIG_DEV_FIFO_SIZE); + int ret; + + ret = nx_mkfifo(pathname, mode, CONFIG_DEV_FIFO_SIZE); + if (ret < 0) + { + set_errno(-ret); + ret = ERROR; + } + + return ret; } #endif /* CONFIG_PIPES && CONFIG_DEV_FIFO_SIZE > 0 */ diff --git a/libs/libc/unistd/lib_pipe.c b/libs/libc/unistd/lib_pipe.c index bd16b0f4103..c5cbba7eaa1 100644 --- a/libs/libc/unistd/lib_pipe.c +++ b/libs/libc/unistd/lib_pipe.c @@ -39,6 +39,7 @@ #include +#include #include #include @@ -69,7 +70,16 @@ int pipe(int fd[2]) { - return pipe2(fd, CONFIG_DEV_PIPE_SIZE); + int ret; + + ret = nx_pipe(fd, CONFIG_DEV_PIPE_SIZE); + if (ret < 0) + { + set_errno(-ret); + ret = ERROR; + } + + return ret; } #endif /* CONFIG_PIPES && CONFIG_DEV_PIPE_SIZE > 0 */ diff --git a/syscall/syscall.csv b/syscall/syscall.csv index 89bdfc41990..238b093ba00 100644 --- a/syscall/syscall.csv +++ b/syscall/syscall.csv @@ -48,7 +48,6 @@ "listen","sys/socket.h","defined(CONFIG_NET)","int","int","int" "lseek","unistd.h","","off_t","int","off_t","int" "mkdir","sys/stat.h","!defined(CONFIG_DISABLE_MOUNTPOINT)","int","FAR const char*","mode_t" -"mkfifo2","nuttx/drivers/drivers.h","defined(CONFIG_PIPES) && CONFIG_DEV_FIFO_SIZE > 0","int","FAR const char*","mode_t","size_t" "mmap","sys/mman.h","","FAR void*","FAR void*","size_t","int","int","int","off_t" "munmap","sys/mman.h","defined(CONFIG_FS_RAMMAP)","int","FAR void *","size_t" "modhandle","nuttx/module.h","defined(CONFIG_MODULE)","FAR void *","FAR const char *" @@ -63,13 +62,14 @@ "mq_timedreceive","mqueue.h","!defined(CONFIG_DISABLE_MQUEUE)","ssize_t","mqd_t","char*","size_t","FAR unsigned int*","const struct timespec*" "mq_timedsend","mqueue.h","!defined(CONFIG_DISABLE_MQUEUE)","int","mqd_t","const char*","size_t","unsigned int","const struct timespec*" "mq_unlink","mqueue.h","!defined(CONFIG_DISABLE_MQUEUE)","int","const char*" +"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]|int*","size_t" "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 *" "open","fcntl.h","","int","const char*","int","..." "opendir","dirent.h","","FAR DIR*","FAR const char*" "pgalloc", "nuttx/arch.h", "defined(CONFIG_BUILD_KERNEL)", "uintptr_t", "uintptr_t", "unsigned int" -"pipe2","nuttx/drivers/drivers.h","defined(CONFIG_PIPES) && CONFIG_DEV_PIPE_SIZE > 0","int","int [2]|int*","size_t" "poll","poll.h","","int","FAR struct pollfd*","nfds_t","int" "ppoll","poll.h","","int","FAR struct pollfd*","nfds_t","FAR const struct timespec *","FAR const sigset_t *" "prctl","sys/prctl.h", "CONFIG_TASK_NAME_SIZE > 0","int","int","..." diff --git a/syscall/syscall_lookup.h b/syscall/syscall_lookup.h index 37220ddce37..17e5e6a00c5 100644 --- a/syscall/syscall_lookup.h +++ b/syscall/syscall_lookup.h @@ -259,11 +259,8 @@ SYSCALL_LOOKUP(up_assert, 2, STUB_up_assert) #endif #if defined(CONFIG_PIPES) && CONFIG_DEV_PIPE_SIZE > 0 - SYSCALL_LOOKUP(pipe2, 2, STUB_pipe2) -#endif - -#if defined(CONFIG_PIPES) && CONFIG_DEV_FIFO_SIZE > 0 - SYSCALL_LOOKUP(mkfifo2, 3, STUB_mkfifo2) + SYSCALL_LOOKUP(nx_pipe, 2, STUB_nx_pipe) + SYSCALL_LOOKUP(nx_mkfifo, 3, STUB_nx_mkfifo) #endif #if CONFIG_NFILE_STREAMS > 0 diff --git a/syscall/syscall_stublookup.c b/syscall/syscall_stublookup.c index e63cf6df49e..493f8e6d52a 100644 --- a/syscall/syscall_stublookup.c +++ b/syscall/syscall_stublookup.c @@ -57,7 +57,8 @@ uintptr_t STUB_sched_setscheduler(int nbr, uintptr_t parm1, uintptr_t parm2, uintptr_t parm3); uintptr_t STUB_sched_unlock(int nbr); uintptr_t STUB_sched_yield(int nbr); -uintptr_t STUB_sched_get_stackinfo(int nbr, uintptr_t parm1, uintptr_t parm2); +uintptr_t STUB_sched_get_stackinfo(int nbr, uintptr_t parm1, + uintptr_t parm2); uintptr_t STUB_sched_getaffinity(int nbr, uintptr_t parm1, uintptr_t parm2, uintptr_t parm3); @@ -264,8 +265,8 @@ uintptr_t STUB_link(int nbr, uintptr_t parm1, uintptr_t parm2); uintptr_t STUB_readlink(int nbr, uintptr_t parm1, uintptr_t parm2, uintptr_t parm3); -uintptr_t STUB_pipe2(int nbr, uintptr_t parm1, uintptr_t parm2); -uintptr_t STUB_mkfifo2(int nbr, uintptr_t parm1, uintptr_t parm2, +uintptr_t STUB_nx_pipe(int nbr, uintptr_t parm1, uintptr_t parm2); +uintptr_t STUB_nx_mkfifo(int nbr, uintptr_t parm1, uintptr_t parm2, uintptr_t parm3); uintptr_t STUB_fs_fdopen(int nbr, uintptr_t parm1, uintptr_t parm2,