Simplication

git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@794 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
patacongo 2008-08-01 02:17:32 +00:00
parent 2d52cdfac7
commit ab815f91f9
2 changed files with 19 additions and 26 deletions

View File

@ -81,7 +81,6 @@ int close(int fd)
{ {
int err; int err;
#if CONFIG_NFILE_DESCRIPTORS > 0 #if CONFIG_NFILE_DESCRIPTORS > 0
FAR struct filelist *list;
int ret; int ret;
/* Did we get a valid file descriptor? */ /* Did we get a valid file descriptor? */
@ -105,23 +104,6 @@ int close(int fd)
} }
#if CONFIG_NFILE_DESCRIPTORS > 0 #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 /* Close the driver or mountpoint. NOTES: (1) there is no
* exclusion mechanism here , the driver or mountpoint must be * exclusion mechanism here , the driver or mountpoint must be
* able to handle concurrent operations internally, (2) The driver * able to handle concurrent operations internally, (2) The driver

View File

@ -399,18 +399,29 @@ int files_allocate(FAR struct inode *inode, int oflags, off_t pos)
int files_close(int filedes) int files_close(int filedes)
{ {
FAR struct filelist *list; FAR struct filelist *list;
int ret = -EBADF; int ret;
/* Get the thread-specific file list */
list = sched_getfiles(); list = sched_getfiles();
if (list) if (!list)
{ {
if (filedes >=0 && filedes < CONFIG_NFILE_DESCRIPTORS) return -EMFILE;
{
_files_semtake(list);
ret = _files_close(&list->fl_files[filedes]);
_files_semgive(list);
}
} }
/* 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;
} }
/**************************************************************************** /****************************************************************************