diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2011-03-13 15:12:31 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2011-03-13 15:12:31 +0000 |
commit | 08a603c77b99ade6a63938a62e1cd785e9fabd25 (patch) | |
tree | e73122d7e6073b1386302e2b5a477c72eb80c171 /nuttx/lib/lib_fopen.c | |
parent | d4f43430da40993103b774b5f07a9da3ef3aedf0 (diff) | |
download | px4-nuttx-08a603c77b99ade6a63938a62e1cd785e9fabd25.tar.gz px4-nuttx-08a603c77b99ade6a63938a62e1cd785e9fabd25.tar.bz2 px4-nuttx-08a603c77b99ade6a63938a62e1cd785e9fabd25.zip |
SLIP corrections
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3376 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/lib/lib_fopen.c')
-rw-r--r-- | nuttx/lib/lib_fopen.c | 35 |
1 files changed, 27 insertions, 8 deletions
diff --git a/nuttx/lib/lib_fopen.c b/nuttx/lib/lib_fopen.c index 6502f0ee4..e198ce888 100644 --- a/nuttx/lib/lib_fopen.c +++ b/nuttx/lib/lib_fopen.c @@ -1,7 +1,7 @@ /**************************************************************************** * lib/lib_fopen.c * - * Copyright (C) 2007-2010 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2011 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <spudmonkey@racsa.co.cr> * * Redistribution and use in source and binary forms, with or without @@ -251,15 +251,34 @@ FAR FILE *fdopen(int fd, FAR const char *mode) FAR FILE *fopen(FAR const char *path, FAR const char *mode) { - FAR struct filelist *flist = sched_getfiles(); - FAR struct streamlist *slist = sched_getstreams(); - int oflags = lib_mode2oflags(mode); - int fd = open(path, oflags, 0666); + FAR FILE *ret = NULL;; + int oflags; + int fd; + + /* Open the file */ + + oflags = lib_mode2oflags(mode); + fd = open(path, oflags, 0666); + + /* If the open was successful, then fdopen() the fil using the file + * desciptor returned by open. If open failed, then just return the + * NULL stream -- open() has already set the errno. + */ - FAR FILE *ret = lib_fdopen(fd, mode, flist, slist); - if (!ret) + if (fd >= 0) { - (void)close(fd); + FAR struct filelist *flist = sched_getfiles(); + FAR struct streamlist *slist = sched_getstreams(); + + ret = lib_fdopen(fd, mode, flist, slist); + if (!ret) + { + /* Don't forget to close the file descriptor if any other + * failures are reported by fdopen(). + */ + + (void)close(fd); + } } return ret; } |