stream/fileoutstream: Add open interface for coredump
Signed-off-by: yangao1 <yangao1@xiaomi.com>
This commit is contained in:
parent
47dd21c3c1
commit
c560db04a6
2 changed files with 49 additions and 12 deletions
|
|
@ -220,7 +220,7 @@ struct lib_fileinstream_s
|
||||||
struct lib_fileoutstream_s
|
struct lib_fileoutstream_s
|
||||||
{
|
{
|
||||||
struct lib_outstream_s common;
|
struct lib_outstream_s common;
|
||||||
FAR struct file *file;
|
struct file file;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct lib_rawsistream_s
|
struct lib_rawsistream_s
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,7 @@ static ssize_t fileoutstream_puts(FAR struct lib_outstream_s *self,
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
nwritten = file_write(stream->file, buf, len);
|
nwritten = file_write(&stream->file, buf, len);
|
||||||
if (nwritten >= 0)
|
if (nwritten >= 0)
|
||||||
{
|
{
|
||||||
self->nput += nwritten;
|
self->nput += nwritten;
|
||||||
|
|
@ -85,28 +85,65 @@ static void fileoutstream_putc(FAR struct lib_outstream_s *self, int ch)
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: lib_fileoutstream
|
* Name: lib_fileoutstream_open
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* Initializes a stream for use with a file descriptor.
|
* Initializes a stream for use with a file descriptor.
|
||||||
|
* This function sets up the stream structure to enable writing to a file
|
||||||
|
* specified by the provide path. It initializes the necessary function
|
||||||
|
* pointers for character and string output, as well as the flush behavior.
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* stream - User allocated, uninitialized instance of struct
|
||||||
|
* lib_rawoutstream_s to be initialized.
|
||||||
|
* path - Path to file to open.
|
||||||
|
* oflag - Open flags.
|
||||||
|
* mode - Mode flags.
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* 0 on success, negative error code in failuer.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int lib_fileoutstream_open(FAR struct lib_fileoutstream_s *stream,
|
||||||
|
FAR const char *path, int oflag, mode_t mode)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
ret = file_open(&stream->file, path, oflag, mode);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
stream->common.putc = fileoutstream_putc;
|
||||||
|
stream->common.puts = fileoutstream_puts;
|
||||||
|
stream->common.flush = lib_noflush;
|
||||||
|
stream->common.nput = 0;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: lib_fileoutstream_close
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Closes the file associated with the stream.
|
||||||
*
|
*
|
||||||
* Input Parameters:
|
* Input Parameters:
|
||||||
* stream - User allocated, uninitialized instance of struct
|
* stream - User allocated, uninitialized instance of struct
|
||||||
* lib_rawoutstream_s to be initialized.
|
* lib_rawoutstream_s to be initialized.
|
||||||
* file - User provided FILE instance (must have been opened for
|
|
||||||
* write access).
|
|
||||||
*
|
*
|
||||||
* Returned Value:
|
* Returned Value:
|
||||||
* None (User allocated instance initialized).
|
* None (User allocated instance initialized).
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
void lib_fileoutstream(FAR struct lib_fileoutstream_s *stream,
|
void lib_fileoutstream_close(FAR struct lib_fileoutstream_s *stream)
|
||||||
FAR struct file *file)
|
|
||||||
{
|
{
|
||||||
stream->common.putc = fileoutstream_putc;
|
if (stream != NULL)
|
||||||
stream->common.puts = fileoutstream_puts;
|
{
|
||||||
stream->common.flush = lib_noflush;
|
file_close(&stream->file);
|
||||||
stream->common.nput = 0;
|
stream->common.nput = 0;
|
||||||
stream->file = file;
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue