summaryrefslogtreecommitdiff
path: root/nuttx/lib
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2010-11-06 01:57:50 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2010-11-06 01:57:50 +0000
commitdafb91b46c651eba17a63457a81917b53217c2b7 (patch)
tree5b8eca34e83e4986092cdb774324281ee61ace8c /nuttx/lib
parentc8b97025f82ef4850e25c70a13b5ccba22d7475d (diff)
downloadpx4-nuttx-dafb91b46c651eba17a63457a81917b53217c2b7.tar.gz
px4-nuttx-dafb91b46c651eba17a63457a81917b53217c2b7.tar.bz2
px4-nuttx-dafb91b46c651eba17a63457a81917b53217c2b7.zip
Fix errors when there is no console device
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3077 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/lib')
-rw-r--r--nuttx/lib/lib_fopen.c19
1 files changed, 17 insertions, 2 deletions
diff --git a/nuttx/lib/lib_fopen.c b/nuttx/lib/lib_fopen.c
index 672fb5bbe..0bfb275b8 100644
--- a/nuttx/lib/lib_fopen.c
+++ b/nuttx/lib/lib_fopen.c
@@ -1,7 +1,7 @@
/****************************************************************************
* lib/lib_fopen.c
*
- * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved.
+ * Copyright (C) 2007-2010 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
*
* Redistribution and use in source and binary forms, with or without
@@ -137,18 +137,33 @@ FAR struct file_struct *lib_fdopen(int fd, FAR const char *mode,
FAR struct filelist *flist,
FAR struct streamlist *slist)
{
- FAR struct inode *inode = flist->fl_files[fd].f_inode;
+ FAR struct inode *inode = flist;
FAR FILE *stream;
int oflags = lib_mode2oflags(mode);
int err = OK;
int i;
+ /* Check input parameters */
+
if (fd < 0 || !flist || !slist)
{
err = EBADF;
goto errout;
}
+ /* Get the inode associated with the file descriptor. This should
+ * normally be the case if fd >= 0. But not in the case where the
+ * called attempts to explictly stdin with fdopen(0) but stdin has
+ * been closed.
+ */
+
+ inode = flist->fl_files[fd].f_inode;
+ if (!inode)
+ {
+ err = ENOENT;
+ goto errout;
+ }
+
/* Make sure that the inode supports the requested access. In
* the case of fdopen, we are not actually creating the file -- in
* particular w and w+ do not truncate the file and any files have