diff options
author | Lorenz Meier <lm@inf.ethz.ch> | 2013-02-17 09:14:12 -0800 |
---|---|---|
committer | Lorenz Meier <lm@inf.ethz.ch> | 2013-02-17 09:14:12 -0800 |
commit | 520a2b417410bed7db6f08a3a69f3bcccc55910b (patch) | |
tree | 2365774545ed145c307630b63cb5f075fca71c21 /apps/system/readline/readline.c | |
parent | 2745c3276f5c2377a9713555c5941b17912b6ce7 (diff) | |
parent | caa11f0bbb7f30679c5c01a64e1d0f6d8627db9d (diff) | |
download | px4-firmware-520a2b417410bed7db6f08a3a69f3bcccc55910b.tar.gz px4-firmware-520a2b417410bed7db6f08a3a69f3bcccc55910b.tar.bz2 px4-firmware-520a2b417410bed7db6f08a3a69f3bcccc55910b.zip |
Merge pull request #198 from PX4/nuttx-merge-5596
Nuttx merge 5596
Diffstat (limited to 'apps/system/readline/readline.c')
-rw-r--r-- | apps/system/readline/readline.c | 52 |
1 files changed, 36 insertions, 16 deletions
diff --git a/apps/system/readline/readline.c b/apps/system/readline/readline.c index f64049ed7..bac7eee8c 100644 --- a/apps/system/readline/readline.c +++ b/apps/system/readline/readline.c @@ -132,23 +132,33 @@ 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 +285,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 +396,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 */ |