summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2012-03-31 15:13:12 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2012-03-31 15:13:12 +0000
commit421258dad4dee7bc7fadd7619749b1bda370c773 (patch)
tree98e0f474d93010b7655ad4b7528df65b3874537f
parentf85bf2b1e0fb595ad588c55ffd23dcb0c0837ce3 (diff)
downloadnuttx-421258dad4dee7bc7fadd7619749b1bda370c773.tar.gz
nuttx-421258dad4dee7bc7fadd7619749b1bda370c773.tar.bz2
nuttx-421258dad4dee7bc7fadd7619749b1bda370c773.zip
Fix read() return value for the case of permissions problem
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@4545 42af7a65-404d-4744-a932-0658087f49c3
-rw-r--r--apps/nshlib/nsh_consolemain.c3
-rw-r--r--apps/nshlib/nsh_telnetd.c3
-rw-r--r--apps/system/readline/readline.c2
-rw-r--r--nuttx/fs/fs_read.c44
-rw-r--r--nuttx/sched/sched_setupidlefiles.c2
5 files changed, 30 insertions, 24 deletions
diff --git a/apps/nshlib/nsh_consolemain.c b/apps/nshlib/nsh_consolemain.c
index 36ffdab8f..a6e28c051 100644
--- a/apps/nshlib/nsh_consolemain.c
+++ b/apps/nshlib/nsh_consolemain.c
@@ -149,7 +149,8 @@ int nsh_consolemain(int argc, char *argv[])
else
{
- fprintf(pstate->cn_outstream, g_fmtcmdfailed, "readline", NSH_ERRNO_OF(-ret));
+ fprintf(pstate->cn_outstream, g_fmtcmdfailed, "nsh_consolemain",
+ "readline", NSH_ERRNO_OF(-ret));
nsh_exit(&pstate->cn_vtbl, 1);
}
}
diff --git a/apps/nshlib/nsh_telnetd.c b/apps/nshlib/nsh_telnetd.c
index 66923deb2..0117aad04 100644
--- a/apps/nshlib/nsh_telnetd.c
+++ b/apps/nshlib/nsh_telnetd.c
@@ -121,7 +121,8 @@ int nsh_telnetmain(int argc, char *argv[])
}
else
{
- fprintf(pstate->cn_outstream, g_fmtcmdfailed, "fgets", NSH_ERRNO);
+ fprintf(pstate->cn_outstream, g_fmtcmdfailed, "nsh_telnetmain",
+ "fgets", NSH_ERRNO);
nsh_exit(&pstate->cn_vtbl, 1);
}
}
diff --git a/apps/system/readline/readline.c b/apps/system/readline/readline.c
index b2a87c870..f7fa6a635 100644
--- a/apps/system/readline/readline.c
+++ b/apps/system/readline/readline.c
@@ -164,7 +164,7 @@ static inline void readline_consolewrite(int outfd, FAR const char *buffer, size
*
* Returned values:
* On success, the (positive) number of bytes transferred is returned.
- * A length of zero would indicated an end of file condition. An failure,
+ * A length of zero would indicate an end of file condition. On failure,
* a negated errno value is returned.
*
**************************************************************************/
diff --git a/nuttx/fs/fs_read.c b/nuttx/fs/fs_read.c
index 8afa65637..045c81f59 100644
--- a/nuttx/fs/fs_read.c
+++ b/nuttx/fs/fs_read.c
@@ -1,8 +1,8 @@
/****************************************************************************
* fs_read.c
*
- * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved.
- * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
+ * Copyright (C) 2007-2009, 2012 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -63,35 +63,39 @@ static inline ssize_t file_read(int fd, FAR void *buf, size_t nbytes)
list = sched_getfiles();
if (!list)
{
- errno = EMFILE;
- return ERROR;
+ /* Failed to get the file list */
+
+ ret = -EMFILE;
}
/* Were we given a valid file descriptor? */
- if ((unsigned int)fd < CONFIG_NFILE_DESCRIPTORS)
+ else if ((unsigned int)fd < CONFIG_NFILE_DESCRIPTORS)
{
FAR struct file *this_file = &list->fl_files[fd];
+ FAR struct inode *inode = this_file->f_inode;
- /* Was this file opened for read access? */
+ /* Yes.. Was this file opened for read access? */
- if ((this_file->f_oflags & O_RDOK) != 0)
+ if ((this_file->f_oflags & O_RDOK) == 0)
{
- struct inode *inode = this_file->f_inode;
+ /* No.. File is not read-able */
- /* Is a driver or mountpoint registered? If so, does it support
- * the read method?
- */
+ ret = -EACCES;
+ }
- if (inode && inode->u.i_ops && inode->u.i_ops->read)
- {
- /* Yes, then let it perform the read. NOTE that for the case
- * of the mountpoint, we depend on the read methods bing
- * identical in signature and position in the operations vtable.
- */
+ /* Is a driver or mountpoint registered? If so, does it support
+ * the read method?
+ */
+
+ else if (inode && inode->u.i_ops && inode->u.i_ops->read)
+ {
+ /* Yes.. then let it perform the read. NOTE that for the case
+ * of the mountpoint, we depend on the read methods bing
+ * identical in signature and position in the operations vtable.
+ */
- ret = (int)inode->u.i_ops->read(this_file, (char*)buf, (size_t)nbytes);
- }
+ ret = (int)inode->u.i_ops->read(this_file, (char*)buf, (size_t)nbytes);
}
}
@@ -99,7 +103,7 @@ static inline ssize_t file_read(int fd, FAR void *buf, size_t nbytes)
if (ret < 0)
{
- errno = -ret;
+ set_errno(-ret);
return ERROR;
}
diff --git a/nuttx/sched/sched_setupidlefiles.c b/nuttx/sched/sched_setupidlefiles.c
index 7b2839685..f2bfb78d2 100644
--- a/nuttx/sched/sched_setupidlefiles.c
+++ b/nuttx/sched/sched_setupidlefiles.c
@@ -123,7 +123,7 @@ int sched_setupidlefiles(FAR _TCB *tcb)
* it and got some file descriptor other than 0.
*/
- if (fd >- 0)
+ if (fd > 0)
{
slldbg("Open /dev/console fd: %d\n", fd);
(void)close(fd);