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
This commit is contained in:
patacongo 2013-01-31 16:52:20 +00:00
parent 978d3212ff
commit a9dee88a44
2 changed files with 40 additions and 16 deletions

View File

@ -502,3 +502,6 @@
once when NSH starts; the .nshrc script will be executed for each session:
Once for serial, once for each USB connection, once for each Telnet
session.
* apps/system/readline: Correct realine return value. Was not
any returning special values when end-of-file or read errors
occur (it would return an empty string which is not very useful).

View File

@ -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
*/