diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2013-01-31 16:52:20 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2013-01-31 16:52:20 +0000 |
commit | d1aae41beb05cc207f99d50c93dc9dd1bbd7e774 (patch) | |
tree | eb4a282cdc3ac29157390d29001c6236fc11b7ec /apps/system/readline/readline.c | |
parent | 6e9b63f15eacf1dc42a628b06550f672444abc0c (diff) | |
download | nuttx-d1aae41beb05cc207f99d50c93dc9dd1bbd7e774.tar.gz nuttx-d1aae41beb05cc207f99d50c93dc9dd1bbd7e774.tar.bz2 nuttx-d1aae41beb05cc207f99d50c93dc9dd1bbd7e774.zip |
Fix readline return value; Add support for removable serial devices
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@5589 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'apps/system/readline/readline.c')
-rw-r--r-- | apps/system/readline/readline.c | 53 |
1 files changed, 37 insertions, 16 deletions
diff --git a/apps/system/readline/readline.c b/apps/system/readline/readline.c index f64049ed7..11c53cb50 100644 --- a/apps/system/readline/readline.c +++ b/apps/system/readline/readline.c @@ -132,23 +132,34 @@ static inline int readline_rawgetc(int infd) nread = read(infd, &buffer, 1); - /* Return EOF if the end of file (0) or error (-1) occurs. */ + /* Check for end-of-file. */ - if (nread < 1) + if (nread == 0) + { + /* Return zero on end-of-file */ + + return 0; + } + + /* Check if an error occurred */ + + else if (nread < 0) { /* EINTR is not really an error; it simply means that a signal we * received while watiing for intput. */ - if (nread == 0 || errno != EINTR) + int errcode = errno; + if (errcode != EINTR) + { - return EOF; + return -errcode; } } } while (nread < 1); - /* On success, returnt he character that was read */ + /* On success, return the character that was read */ return (int)buffer; } @@ -275,9 +286,29 @@ ssize_t readline(FAR char *buf, int buflen, FILE *instream, FILE *outstream) int ch = readline_rawgetc(infd); + /* Check for end-of-file or read error */ + + if (ch <= 0) + { + /* Did we already received some data? */ + + if (nch > 0) + { + /* Yes.. Terminate the line (which might be zero length) + * and return the data that was received. The end-of-file + * or error condition will be reported next time. + */ + + buf[nch] = '\0'; + return nch; + } + + return ch; + } + /* Are we processing a VT100 escape sequence */ - if (escape) + else if (escape) { /* Yes, is it an <esc>[, 3 byte sequence */ @@ -366,16 +397,6 @@ ssize_t readline(FAR char *buf, int buflen, FILE *instream, FILE *outstream) return nch; } - /* Check for end-of-file */ - - else if (ch == EOF) - { - /* Terminate the line (which might be zero length) */ - - buf[nch] = '\0'; - return nch; - } - /* Otherwise, check if the character is printable and, if so, put the * character in the line buffer */ |