summaryrefslogtreecommitdiff
path: root/nuttx
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2008-08-01 02:17:32 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2008-08-01 02:17:32 +0000
commit658313bd4f7676ac9a1386f311390af716984bb6 (patch)
tree72e2add575b3089b18f3f4325fd1e07d2a18791f /nuttx
parentd70a972659915d79d44b95b8e01f7d641a583958 (diff)
downloadpx4-nuttx-658313bd4f7676ac9a1386f311390af716984bb6.tar.gz
px4-nuttx-658313bd4f7676ac9a1386f311390af716984bb6.tar.bz2
px4-nuttx-658313bd4f7676ac9a1386f311390af716984bb6.zip
Simplication
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@794 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx')
-rw-r--r--nuttx/fs/fs_close.c18
-rw-r--r--nuttx/fs/fs_files.c27
2 files changed, 19 insertions, 26 deletions
diff --git a/nuttx/fs/fs_close.c b/nuttx/fs/fs_close.c
index 03c0769e4..4970c459d 100644
--- a/nuttx/fs/fs_close.c
+++ b/nuttx/fs/fs_close.c
@@ -81,7 +81,6 @@ int close(int fd)
{
int err;
#if CONFIG_NFILE_DESCRIPTORS > 0
- FAR struct filelist *list;
int ret;
/* Did we get a valid file descriptor? */
@@ -105,23 +104,6 @@ int close(int fd)
}
#if CONFIG_NFILE_DESCRIPTORS > 0
- /* Get the thread-specific file list */
-
- list = sched_getfiles();
- if (!list)
- {
- err = EMFILE;
- goto errout;
- }
-
- /* If the file was properly opened, there should be an inode assigned */
-
- if (!list->fl_files[fd].f_inode)
- {
- err = EBADF;
- goto errout;
- }
-
/* Close the driver or mountpoint. NOTES: (1) there is no
* exclusion mechanism here , the driver or mountpoint must be
* able to handle concurrent operations internally, (2) The driver
diff --git a/nuttx/fs/fs_files.c b/nuttx/fs/fs_files.c
index fd8351fa5..245ff99a0 100644
--- a/nuttx/fs/fs_files.c
+++ b/nuttx/fs/fs_files.c
@@ -399,18 +399,29 @@ int files_allocate(FAR struct inode *inode, int oflags, off_t pos)
int files_close(int filedes)
{
FAR struct filelist *list;
- int ret = -EBADF;
+ int ret;
+
+ /* Get the thread-specific file list */
list = sched_getfiles();
- if (list)
+ if (!list)
{
- if (filedes >=0 && filedes < CONFIG_NFILE_DESCRIPTORS)
- {
- _files_semtake(list);
- ret = _files_close(&list->fl_files[filedes]);
- _files_semgive(list);
- }
+ return -EMFILE;
}
+
+ /* If the file was properly opened, there should be an inode assigned */
+
+ if (filedes < 0 || filedes >= CONFIG_NFILE_DESCRIPTORS || !list->fl_files[filedes].f_inode)
+ {
+ return -EBADF;
+ }
+
+ /* Perform the protected close operation */
+
+ _files_semtake(list);
+ ret = _files_close(&list->fl_files[filedes]);
+ _files_semgive(list);
+ return ret;
}
/****************************************************************************