From 658313bd4f7676ac9a1386f311390af716984bb6 Mon Sep 17 00:00:00 2001 From: patacongo Date: Fri, 1 Aug 2008 02:17:32 +0000 Subject: Simplication git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@794 42af7a65-404d-4744-a932-0658087f49c3 --- nuttx/fs/fs_close.c | 18 ------------------ nuttx/fs/fs_files.c | 27 +++++++++++++++++++-------- 2 files changed, 19 insertions(+), 26 deletions(-) (limited to 'nuttx') 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; } /**************************************************************************** -- cgit v1.2.3