feat(nsh): add console read
This allows programs such as `cat` to read from the console (that could be redirected).
This commit is contained in:
parent
96100b30f2
commit
4104019e1c
@ -139,6 +139,34 @@ static ssize_t nsh_consolewrite(FAR struct nsh_vtbl_s *vtbl,
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nsh_consoleread
|
||||
*
|
||||
* Description:
|
||||
* read a buffer to the remote shell window.
|
||||
*
|
||||
* Currently only used by cat.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static ssize_t nsh_consoleread(FAR struct nsh_vtbl_s *vtbl,
|
||||
FAR void *buffer, size_t nbytes)
|
||||
{
|
||||
FAR struct console_stdio_s *pstate = (FAR struct console_stdio_s *)vtbl;
|
||||
ssize_t ret;
|
||||
|
||||
/* Read the data to the output stream */
|
||||
|
||||
ret = read(INFD(pstate), buffer, nbytes);
|
||||
if (ret < 0)
|
||||
{
|
||||
_err("ERROR: [%d] Failed to read buffer: %d\n",
|
||||
INFD(pstate), errno);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nsh_consolewrite
|
||||
*
|
||||
@ -380,6 +408,7 @@ FAR struct console_stdio_s *nsh_newconsole(bool isctty)
|
||||
#endif
|
||||
pstate->cn_vtbl.release = nsh_consolerelease;
|
||||
pstate->cn_vtbl.write = nsh_consolewrite;
|
||||
pstate->cn_vtbl.read = nsh_consoleread;
|
||||
pstate->cn_vtbl.ioctl = nsh_consoleioctl;
|
||||
pstate->cn_vtbl.output = nsh_consoleoutput;
|
||||
#ifndef CONFIG_NSH_DISABLE_ERROR_PRINT
|
||||
|
@ -44,6 +44,7 @@
|
||||
#define nsh_clone(v) (v)->clone(v)
|
||||
#define nsh_release(v) (v)->release(v)
|
||||
#define nsh_write(v,b,n) (v)->write(v,b,n)
|
||||
#define nsh_read(v,b,n) (v)->read(v,b,n)
|
||||
#define nsh_ioctl(v,c,a) (v)->ioctl(v,c,a)
|
||||
#define nsh_linebuffer(v) (v)->linebuffer(v)
|
||||
#define nsh_redirect(v,fi,fo,s) (v)->redirect(v,fi,fo,s)
|
||||
@ -113,6 +114,8 @@ struct nsh_vtbl_s
|
||||
void (*release)(FAR struct nsh_vtbl_s *vtbl);
|
||||
ssize_t (*write)(FAR struct nsh_vtbl_s *vtbl, FAR const void *buffer,
|
||||
size_t nbytes);
|
||||
ssize_t (*read)(FAR struct nsh_vtbl_s *vtbl, FAR void *buffer,
|
||||
size_t nbytes);
|
||||
int (*ioctl)(FAR struct nsh_vtbl_s *vtbl, int cmd, unsigned long arg);
|
||||
#ifndef CONFIG_NSH_DISABLE_ERROR_PRINT
|
||||
int (*error)(FAR struct nsh_vtbl_s *vtbl, FAR const char *fmt, ...)
|
||||
|
Loading…
Reference in New Issue
Block a user