summaryrefslogtreecommitdiff
path: root/nuttx/fs/fs_dup.c
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2009-07-19 00:14:46 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2009-07-19 00:14:46 +0000
commit17553d10657c2a395a2ab1f7d6629453fc5ed342 (patch)
treea32ae4f4d40e07e38093273770ff0989b50935db /nuttx/fs/fs_dup.c
parent3f09faeeeb7c23c496df9e3790fd3425429adddc (diff)
downloadpx4-nuttx-17553d10657c2a395a2ab1f7d6629453fc5ed342.tar.gz
px4-nuttx-17553d10657c2a395a2ab1f7d6629453fc5ed342.tar.bz2
px4-nuttx-17553d10657c2a395a2ab1f7d6629453fc5ed342.zip
Add fcntl(F_DUPFD)
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@1995 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/fs/fs_dup.c')
-rw-r--r--nuttx/fs/fs_dup.c37
1 files changed, 18 insertions, 19 deletions
diff --git a/nuttx/fs/fs_dup.c b/nuttx/fs/fs_dup.c
index 20b7fbf27..c041aa4ca 100644
--- a/nuttx/fs/fs_dup.c
+++ b/nuttx/fs/fs_dup.c
@@ -47,15 +47,8 @@
#include <nuttx/fs.h>
#include "fs_internal.h"
-/* This logic in this applies only when both socket and file descriptors are
- * in that case, this function descriminates which type of dup is being
- * performed.
- */
-
-#if CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_NET) && CONFIG_NSOCKET_DESCRIPTORS > 0
-
/****************************************************************************
- * Definitions
+ * Pre-processor Definitions
****************************************************************************/
/****************************************************************************
@@ -76,34 +69,40 @@
int dup(int fildes)
{
+ int ret = OK;
+
/* Check the range of the descriptor to see if we got a file or a socket
* descriptor. */
- if ((unsigned int)fildes >= CONFIG_NFILE_DESCRIPTORS)
+#if CONFIG_NFILE_DESCRIPTORS > 0
+ if ((unsigned int)fildes < CONFIG_NFILE_DESCRIPTORS)
+ {
+ /* Its a valid file descriptor.. dup the file descriptor using any
+ * other file descriptor*/
+
+ ret = file_dup(fildes, 0);
+ }
+ else
+#endif
{
/* Not a vailid file descriptor. Did we get a valid socket descriptor? */
+#if defined(CONFIG_NET) && CONFIG_NSOCKET_DESCRIPTORS > 0
if ((unsigned int)fildes < (CONFIG_NFILE_DESCRIPTORS+CONFIG_NSOCKET_DESCRIPTORS))
{
/* Yes.. dup the socket descriptor */
- return net_dup(fildes);
+ ret = net_dup(fildes, CONFIG_NFILE_DESCRIPTORS);
}
else
+#endif
{
/* No.. then it is a bad descriptor number */
errno = EBADF;
- return ERROR;
+ ret = ERROR;
}
}
- else
- {
- /* Its a valid file descriptor.. dup the file descriptor */
-
- return file_dup(fildes);
- }
+ return ret;
}
-#endif /* CONFIG_NFILE_DESCRIPTORS > 0 ... */
-