diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2009-07-19 00:14:46 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2009-07-19 00:14:46 +0000 |
commit | 17553d10657c2a395a2ab1f7d6629453fc5ed342 (patch) | |
tree | a32ae4f4d40e07e38093273770ff0989b50935db /nuttx/fs | |
parent | 3f09faeeeb7c23c496df9e3790fd3425429adddc (diff) | |
download | px4-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')
-rw-r--r-- | nuttx/fs/fs_dup.c | 37 | ||||
-rw-r--r-- | nuttx/fs/fs_fcntl.c | 5 | ||||
-rw-r--r-- | nuttx/fs/fs_filedup.c | 10 | ||||
-rw-r--r-- | nuttx/fs/fs_files.c | 7 | ||||
-rw-r--r-- | nuttx/fs/fs_internal.h | 2 | ||||
-rw-r--r-- | nuttx/fs/fs_open.c | 2 |
6 files changed, 32 insertions, 31 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 ... */ - diff --git a/nuttx/fs/fs_fcntl.c b/nuttx/fs/fs_fcntl.c index 524bd22b0..d8afd51a2 100644 --- a/nuttx/fs/fs_fcntl.c +++ b/nuttx/fs/fs_fcntl.c @@ -94,6 +94,11 @@ static inline int file_vfcntl(int fildes, int cmd, va_list ap) * exec functions. */ + { + ret = file_dup(fildes, va_arg(ap, int)); + } + break; + case F_GETFD: /* Get the file descriptor flags defined in <fcntl.h> that are associated * with the file descriptor fildes. File descriptor flags are associated diff --git a/nuttx/fs/fs_filedup.c b/nuttx/fs/fs_filedup.c index 71f625877..10c2eba04 100644 --- a/nuttx/fs/fs_filedup.c +++ b/nuttx/fs/fs_filedup.c @@ -40,7 +40,6 @@ #include <nuttx/config.h> #include <sys/types.h> -#include <unistd.h> #include <sched.h> #include <errno.h> @@ -76,11 +75,7 @@ * ****************************************************************************/ -#if defined(CONFIG_NET) && CONFIG_NSOCKET_DESCRIPTORS > 0 -int file_dup(int fildes) -#else -int dup(int fildes) -#endif +int file_dup(int fildes, int minfd) { FAR struct filelist *list; int fildes2; @@ -110,7 +105,8 @@ int dup(int fildes) fildes2 = files_allocate(list->fl_files[fildes].f_inode, list->fl_files[fildes].f_oflags, - list->fl_files[fildes].f_pos); + list->fl_files[fildes].f_pos, + minfd); if (fildes2 < 0) { errno = EMFILE; diff --git a/nuttx/fs/fs_files.c b/nuttx/fs/fs_files.c index d0c3fff52..e872d1558 100644 --- a/nuttx/fs/fs_files.c +++ b/nuttx/fs/fs_files.c @@ -1,7 +1,7 @@ /**************************************************************************** * fs/fs_files.c * - * Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <spudmonkey@racsa.co.cr> * * Redistribution and use in source and binary forms, with or without @@ -361,7 +361,8 @@ errout: * Returns the file descriptor == index into the files array. * ****************************************************************************/ -int files_allocate(FAR struct inode *inode, int oflags, off_t pos) + +int files_allocate(FAR struct inode *inode, int oflags, off_t pos, int minfd) { FAR struct filelist *list; int i; @@ -370,7 +371,7 @@ int files_allocate(FAR struct inode *inode, int oflags, off_t pos) if (list) { _files_semtake(list); - for (i = 0; i < CONFIG_NFILE_DESCRIPTORS; i++) + for (i = minfd; i < CONFIG_NFILE_DESCRIPTORS; i++) { if (!list->fl_files[i].f_inode) { diff --git a/nuttx/fs/fs_internal.h b/nuttx/fs/fs_internal.h index e34c45134..34b722e98 100644 --- a/nuttx/fs/fs_internal.h +++ b/nuttx/fs/fs_internal.h @@ -225,7 +225,7 @@ EXTERN void inode_release(FAR struct inode *inode); /* fs_files.c ****************************************************************/ EXTERN void weak_function files_initialize(void); -EXTERN int files_allocate(FAR struct inode *inode, int oflags, off_t pos); +EXTERN int files_allocate(FAR struct inode *inode, int oflags, off_t pos, int minfd); EXTERN int files_close(int filedes); EXTERN void files_release(int filedes); diff --git a/nuttx/fs/fs_open.c b/nuttx/fs/fs_open.c index 8ab650376..76b941f95 100644 --- a/nuttx/fs/fs_open.c +++ b/nuttx/fs/fs_open.c @@ -140,7 +140,7 @@ int open(const char *path, int oflags, ...) /* Associate the inode with a file structure */ - fd = files_allocate(inode, oflags, 0); + fd = files_allocate(inode, oflags, 0, 0); if (fd < 0) { ret = EMFILE; |