This is an automated email from the ASF dual-hosted git repository.

jiuzhudong pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit c560db04a6a046db673ca5c7baaef4c7198cee3f
Author: yangao1 <yang...@xiaomi.com>
AuthorDate: Tue Apr 15 20:39:42 2025 +0800

    stream/fileoutstream: Add open interface for coredump
    
    Signed-off-by: yangao1 <yang...@xiaomi.com>
---
 include/nuttx/streams.h              |  2 +-
 libs/libc/stream/lib_fileoutstream.c | 53 ++++++++++++++++++++++++++++++------
 2 files changed, 46 insertions(+), 9 deletions(-)

diff --git a/include/nuttx/streams.h b/include/nuttx/streams.h
index dc0d6447c4..c0bd6d5331 100644
--- a/include/nuttx/streams.h
+++ b/include/nuttx/streams.h
@@ -220,7 +220,7 @@ struct lib_fileinstream_s
 struct lib_fileoutstream_s
 {
   struct lib_outstream_s common;
-  FAR struct file       *file;
+  struct file            file;
 };
 
 struct lib_rawsistream_s
diff --git a/libs/libc/stream/lib_fileoutstream.c 
b/libs/libc/stream/lib_fileoutstream.c
index 21ffe4e460..020e6b8a36 100644
--- a/libs/libc/stream/lib_fileoutstream.c
+++ b/libs/libc/stream/lib_fileoutstream.c
@@ -51,7 +51,7 @@ static ssize_t fileoutstream_puts(FAR struct lib_outstream_s 
*self,
 
   do
     {
-      nwritten = file_write(stream->file, buf, len);
+      nwritten = file_write(&stream->file, buf, len);
       if (nwritten >= 0)
         {
           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:
  *   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.
- *   file   - User provided FILE instance (must have been opened for
- *            write access).
+ *   path   - Path to file to open.
+ *   oflag  - Open flags.
+ *   mode   - Mode flags.
  *
  * Returned Value:
- *   None (User allocated instance initialized).
+ *   0 on success, negative error code in failuer.
  *
  ****************************************************************************/
 
-void lib_fileoutstream(FAR struct lib_fileoutstream_s *stream,
-                       FAR struct file *file)
+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;
-  stream->file         = file;
+
+  return 0;
+}
+
+/****************************************************************************
+ * Name: lib_fileoutstream_close
+ *
+ * Description:
+ *   Closes the file associated with the stream.
+ *
+ * Input Parameters:
+ *   stream - User allocated, uninitialized instance of struct
+ *            lib_rawoutstream_s to be initialized.
+ *
+ * Returned Value:
+ *   None (User allocated instance initialized).
+ *
+ ****************************************************************************/
+
+void lib_fileoutstream_close(FAR struct lib_fileoutstream_s *stream)
+{
+  if (stream != NULL)
+    {
+      file_close(&stream->file);
+      stream->common.nput = 0;
+    }
 }

Reply via email to