Re: [PR] libc: add support for memory buffer stream with fmemopen() [nuttx]

2023-10-26 Thread via GitHub


xiaoxiang781216 merged PR #11011:
URL: https://github.com/apache/nuttx/pull/11011


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [PR] libc: add support for memory buffer stream with fmemopen() [nuttx]

2023-10-26 Thread via GitHub


michallenc commented on PR #11011:
URL: https://github.com/apache/nuttx/pull/11011#issuecomment-1781589919

   Rebased and force pushed for CI fix.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [PR] libc: add support for memory buffer stream with fmemopen() [nuttx]

2023-10-26 Thread via GitHub


michallenc commented on code in PR #11011:
URL: https://github.com/apache/nuttx/pull/11011#discussion_r1373007980


##
libs/libc/stdio/lib_fmemopen.c:
##
@@ -0,0 +1,291 @@
+/
+ * libs/libc/stdio/lib_fmemopen.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ /
+
+/
+ * Included Files
+ /
+
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "libc.h"
+
+/
+ * Private Types
+ /
+
+struct fmemopen_cookie_s
+{
+  FAR char *buf;/* Memory buffer */
+  off_t pos;/* Current position in the buffer */
+  off_t end;/* End buffer position */
+  size_t size;  /* Buffer size */
+  bool custom;  /* True if custom buffer is used */
+};
+
+/
+ * Private Functions
+ /
+
+/
+ * Name: fmemopen_read
+ /
+
+static ssize_t fmemopen_read(FAR void *c, FAR char *buf, size_t size)
+{
+  FAR struct fmemopen_cookie_s *fmemopen_cookie =
+(FAR struct fmemopen_cookie_s *)c;
+  if (fmemopen_cookie->pos + size > fmemopen_cookie->end)
+{
+  size = fmemopen_cookie->end - fmemopen_cookie->pos;
+}
+
+  if (size < 0)
+{
+  size = 0;
+}
+
+  memcpy(buf, fmemopen_cookie->buf + fmemopen_cookie->pos, size);
+
+  fmemopen_cookie->pos += size;
+  return size;
+}
+
+/
+ * Name: fmemopen_write
+ /
+
+static ssize_t fmemopen_write(FAR void *c, FAR const char *buf, size_t size)
+{
+  FAR struct fmemopen_cookie_s *fmemopen_cookie =
+(FAR struct fmemopen_cookie_s *)c;
+  if (size + fmemopen_cookie->pos > fmemopen_cookie->size)
+{
+  return -ENOSPC;
+}
+
+  memcpy(fmemopen_cookie->buf + fmemopen_cookie->pos, buf, size);
+
+  fmemopen_cookie->pos += size;
+  if (fmemopen_cookie->pos > fmemopen_cookie->end)
+{
+  fmemopen_cookie->end = fmemopen_cookie->pos;
+}
+
+  /* POSIX states that NULL byte shall be written at the current position
+   * or end of the buffer.
+   */
+
+  if (fmemopen_cookie->pos < fmemopen_cookie->size &&
+  fmemopen_cookie->buf[fmemopen_cookie->pos - 1] != '\0')
+{
+  fmemopen_cookie->buf[fmemopen_cookie->pos] = '\0';
+}
+
+  return size;
+}
+
+/
+ * Name: fmemopen_seek
+ /
+
+static off_t fmemopen_seek(FAR void *c, FAR off_t *offset, int whence)
+{
+  FAR struct fmemopen_cookie_s *fmemopen_cookie =
+(FAR struct fmemopen_cookie_s *)c;
+  off_t new_offset;
+
+  switch (whence)
+{
+  case SEEK_SET:
+new_offset = *offset;
+break;
+  case SEEK_END:
+new_offset = fmemopen_cookie->end + *offset;
+break;
+  case SEEK_CUR:
+new_offset = fmemopen_cookie->pos + *offset;
+break;
+  default:
+return ENOTSUP;
+}
+
+  /* Seek to negative value or value larger than maximum size shall fail. */
+
+  if (new_offset < 0 || (new_offset > fmemopen_cookie->end))
+{
+  return EINVAL;
+}
+
+  fmemopen_cookie->pos = new_offset;
+  *offset = new_offset;
+  return new_offset;
+}
+
+/
+ * Name: fmemopen_close
+ /
+
+static int fmemopen_close(FAR void *c)
+{

Re: [PR] libc: add support for memory buffer stream with fmemopen() [nuttx]

2023-10-25 Thread via GitHub


xiaoxiang781216 commented on code in PR #11011:
URL: https://github.com/apache/nuttx/pull/11011#discussion_r1372140446


##
libs/libc/stdio/lib_fmemopen.c:
##
@@ -0,0 +1,291 @@
+/
+ * libs/libc/stdio/lib_fmemopen.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ /
+
+/
+ * Included Files
+ /
+
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "libc.h"
+
+/
+ * Private Types
+ /
+
+struct fmemopen_cookie_s
+{
+  FAR char *buf;/* Memory buffer */
+  off_t pos;/* Current position in the buffer */
+  off_t end;/* End buffer position */
+  size_t size;  /* Buffer size */
+  bool custom;  /* True if custom buffer is used */
+};
+
+/
+ * Private Functions
+ /
+
+/
+ * Name: fmemopen_read
+ /
+
+static ssize_t fmemopen_read(FAR void *c, FAR char *buf, size_t size)
+{
+  FAR struct fmemopen_cookie_s *fmemopen_cookie =
+(FAR struct fmemopen_cookie_s *)c;
+  if (fmemopen_cookie->pos + size > fmemopen_cookie->end)
+{
+  size = fmemopen_cookie->end - fmemopen_cookie->pos;
+}
+
+  if (size < 0)
+{
+  size = 0;
+}
+
+  memcpy(buf, fmemopen_cookie->buf + fmemopen_cookie->pos, size);
+
+  fmemopen_cookie->pos += size;
+  return size;
+}
+
+/
+ * Name: fmemopen_write
+ /
+
+static ssize_t fmemopen_write(FAR void *c, FAR const char *buf, size_t size)
+{
+  FAR struct fmemopen_cookie_s *fmemopen_cookie =
+(FAR struct fmemopen_cookie_s *)c;
+  if (size + fmemopen_cookie->pos > fmemopen_cookie->size)
+{
+  return -ENOSPC;
+}
+
+  memcpy(fmemopen_cookie->buf + fmemopen_cookie->pos, buf, size);
+
+  fmemopen_cookie->pos += size;
+  if (fmemopen_cookie->pos > fmemopen_cookie->end)
+{
+  fmemopen_cookie->end = fmemopen_cookie->pos;
+}
+
+  /* POSIX states that NULL byte shall be written at the current position
+   * or end of the buffer.
+   */
+
+  if (fmemopen_cookie->pos < fmemopen_cookie->size &&
+  fmemopen_cookie->buf[fmemopen_cookie->pos - 1] != '\0')
+{
+  fmemopen_cookie->buf[fmemopen_cookie->pos] = '\0';
+}
+
+  return size;
+}
+
+/
+ * Name: fmemopen_seek
+ /
+
+static off_t fmemopen_seek(FAR void *c, FAR off_t *offset, int whence)
+{
+  FAR struct fmemopen_cookie_s *fmemopen_cookie =
+(FAR struct fmemopen_cookie_s *)c;
+  off_t new_offset;
+
+  switch (whence)
+{
+  case SEEK_SET:
+new_offset = *offset;
+break;
+  case SEEK_END:
+new_offset = fmemopen_cookie->end + *offset;
+break;
+  case SEEK_CUR:
+new_offset = fmemopen_cookie->pos + *offset;
+break;
+  default:
+return ENOTSUP;
+}
+
+  /* Seek to negative value or value larger than maximum size shall fail. */
+
+  if (new_offset < 0 || (new_offset > fmemopen_cookie->end))
+{
+  return EINVAL;
+}
+
+  fmemopen_cookie->pos = new_offset;
+  *offset = new_offset;
+  return new_offset;
+}
+
+/
+ * Name: fmemopen_close
+ /
+
+static int fmemopen_close(FAR void 

Re: [PR] libc: add support for memory buffer stream with fmemopen() [nuttx]

2023-10-25 Thread via GitHub


michallenc commented on code in PR #11011:
URL: https://github.com/apache/nuttx/pull/11011#discussion_r1371671132


##
libs/libc/stdio/lib_fmemopen.c:
##
@@ -0,0 +1,291 @@
+/
+ * libs/libc/stdio/lib_fmemopen.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ /
+
+/
+ * Included Files
+ /
+
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "libc.h"
+
+/
+ * Private Types
+ /
+
+struct fmemopen_cookie_s
+{
+  FAR char *buf;/* Memory buffer */
+  off_t pos;/* Current position in the buffer */
+  off_t end;/* End buffer position */
+  size_t size;  /* Buffer size */
+  bool custom;  /* True if custom buffer is used */
+};
+
+/
+ * Private Functions
+ /
+
+/
+ * Name: fmemopen_read
+ /
+
+static ssize_t fmemopen_read(FAR void *c, FAR char *buf, size_t size)
+{
+  FAR struct fmemopen_cookie_s *fmemopen_cookie =
+(FAR struct fmemopen_cookie_s *)c;
+  if (fmemopen_cookie->pos + size > fmemopen_cookie->end)
+{
+  size = fmemopen_cookie->end - fmemopen_cookie->pos;
+}
+
+  if (size < 0)
+{
+  size = 0;
+}
+
+  memcpy(buf, fmemopen_cookie->buf + fmemopen_cookie->pos, size);
+
+  fmemopen_cookie->pos += size;
+  return size;
+}
+
+/
+ * Name: fmemopen_write
+ /
+
+static ssize_t fmemopen_write(FAR void *c, FAR const char *buf, size_t size)
+{
+  FAR struct fmemopen_cookie_s *fmemopen_cookie =
+(FAR struct fmemopen_cookie_s *)c;
+  if (size + fmemopen_cookie->pos > fmemopen_cookie->size)
+{
+  return -ENOSPC;
+}
+
+  memcpy(fmemopen_cookie->buf + fmemopen_cookie->pos, buf, size);
+
+  fmemopen_cookie->pos += size;
+  if (fmemopen_cookie->pos > fmemopen_cookie->end)
+{
+  fmemopen_cookie->end = fmemopen_cookie->pos;
+}
+
+  /* POSIX states that NULL byte shall be written at the current position
+   * or end of the buffer.
+   */
+
+  if (fmemopen_cookie->pos < fmemopen_cookie->size &&
+  fmemopen_cookie->buf[fmemopen_cookie->pos - 1] != '\0')
+{
+  fmemopen_cookie->buf[fmemopen_cookie->pos] = '\0';
+}
+
+  return size;
+}
+
+/
+ * Name: fmemopen_seek
+ /
+
+static off_t fmemopen_seek(FAR void *c, FAR off_t *offset, int whence)
+{
+  FAR struct fmemopen_cookie_s *fmemopen_cookie =
+(FAR struct fmemopen_cookie_s *)c;
+  off_t new_offset;
+
+  switch (whence)
+{
+  case SEEK_SET:
+new_offset = *offset;
+break;
+  case SEEK_END:
+new_offset = fmemopen_cookie->end + *offset;
+break;
+  case SEEK_CUR:
+new_offset = fmemopen_cookie->pos + *offset;
+break;
+  default:
+return ENOTSUP;
+}
+
+  /* Seek to negative value or value larger than maximum size shall fail. */
+
+  if (new_offset < 0 || (new_offset > fmemopen_cookie->end))
+{
+  return EINVAL;
+}
+
+  fmemopen_cookie->pos = new_offset;
+  *offset = new_offset;
+  return new_offset;
+}
+
+/
+ * Name: fmemopen_close
+ /
+
+static int fmemopen_close(FAR void *c)
+{

Re: [PR] libc: add support for memory buffer stream with fmemopen() [nuttx]

2023-10-25 Thread via GitHub


xiaoxiang781216 commented on code in PR #11011:
URL: https://github.com/apache/nuttx/pull/11011#discussion_r1371620147


##
libs/libc/stdio/lib_fmemopen.c:
##
@@ -0,0 +1,291 @@
+/
+ * libs/libc/stdio/lib_fmemopen.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ /
+
+/
+ * Included Files
+ /
+
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "libc.h"
+
+/
+ * Private Types
+ /
+
+struct fmemopen_cookie_s
+{
+  FAR char *buf;/* Memory buffer */
+  off_t pos;/* Current position in the buffer */
+  off_t end;/* End buffer position */
+  size_t size;  /* Buffer size */
+  bool custom;  /* True if custom buffer is used */
+};
+
+/
+ * Private Functions
+ /
+
+/
+ * Name: fmemopen_read
+ /
+
+static ssize_t fmemopen_read(FAR void *c, FAR char *buf, size_t size)
+{
+  FAR struct fmemopen_cookie_s *fmemopen_cookie =
+(FAR struct fmemopen_cookie_s *)c;
+  if (fmemopen_cookie->pos + size > fmemopen_cookie->end)
+{
+  size = fmemopen_cookie->end - fmemopen_cookie->pos;
+}
+
+  if (size < 0)
+{
+  size = 0;
+}
+
+  memcpy(buf, fmemopen_cookie->buf + fmemopen_cookie->pos, size);
+
+  fmemopen_cookie->pos += size;
+  return size;
+}
+
+/
+ * Name: fmemopen_write
+ /
+
+static ssize_t fmemopen_write(FAR void *c, FAR const char *buf, size_t size)
+{
+  FAR struct fmemopen_cookie_s *fmemopen_cookie =
+(FAR struct fmemopen_cookie_s *)c;
+  if (size + fmemopen_cookie->pos > fmemopen_cookie->size)
+{
+  return -ENOSPC;
+}
+
+  memcpy(fmemopen_cookie->buf + fmemopen_cookie->pos, buf, size);
+
+  fmemopen_cookie->pos += size;
+  if (fmemopen_cookie->pos > fmemopen_cookie->end)
+{
+  fmemopen_cookie->end = fmemopen_cookie->pos;
+}
+
+  /* POSIX states that NULL byte shall be written at the current position
+   * or end of the buffer.
+   */
+
+  if (fmemopen_cookie->pos < fmemopen_cookie->size &&
+  fmemopen_cookie->buf[fmemopen_cookie->pos - 1] != '\0')
+{
+  fmemopen_cookie->buf[fmemopen_cookie->pos] = '\0';
+}
+
+  return size;
+}
+
+/
+ * Name: fmemopen_seek
+ /
+
+static off_t fmemopen_seek(FAR void *c, FAR off_t *offset, int whence)
+{
+  FAR struct fmemopen_cookie_s *fmemopen_cookie =
+(FAR struct fmemopen_cookie_s *)c;
+  off_t new_offset;
+
+  switch (whence)
+{
+  case SEEK_SET:
+new_offset = *offset;
+break;
+  case SEEK_END:
+new_offset = fmemopen_cookie->end + *offset;
+break;
+  case SEEK_CUR:
+new_offset = fmemopen_cookie->pos + *offset;
+break;
+  default:
+return ENOTSUP;
+}
+
+  /* Seek to negative value or value larger than maximum size shall fail. */
+
+  if (new_offset < 0 || (new_offset > fmemopen_cookie->end))
+{
+  return EINVAL;
+}
+
+  fmemopen_cookie->pos = new_offset;
+  *offset = new_offset;
+  return new_offset;
+}
+
+/
+ * Name: fmemopen_close
+ /
+
+static int fmemopen_close(FAR void 

Re: [PR] libc: add support for memory buffer stream with fmemopen() [nuttx]

2023-10-25 Thread via GitHub


michallenc commented on code in PR #11011:
URL: https://github.com/apache/nuttx/pull/11011#discussion_r1371575443


##
libs/libc/stdio/lib_fmemopen.c:
##
@@ -0,0 +1,291 @@
+/
+ * libs/libc/stdio/lib_fmemopen.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ /
+
+/
+ * Included Files
+ /
+
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "libc.h"
+
+/
+ * Private Types
+ /
+
+struct fmemopen_cookie_s
+{
+  FAR char *buf;/* Memory buffer */
+  off_t pos;/* Current position in the buffer */
+  off_t end;/* End buffer position */
+  size_t size;  /* Buffer size */
+  bool custom;  /* True if custom buffer is used */
+};
+
+/
+ * Private Functions
+ /
+
+/
+ * Name: fmemopen_read
+ /
+
+static ssize_t fmemopen_read(FAR void *c, FAR char *buf, size_t size)
+{
+  FAR struct fmemopen_cookie_s *fmemopen_cookie =
+(FAR struct fmemopen_cookie_s *)c;
+  if (fmemopen_cookie->pos + size > fmemopen_cookie->end)
+{
+  size = fmemopen_cookie->end - fmemopen_cookie->pos;
+}
+
+  if (size < 0)
+{
+  size = 0;
+}
+
+  memcpy(buf, fmemopen_cookie->buf + fmemopen_cookie->pos, size);
+
+  fmemopen_cookie->pos += size;
+  return size;
+}
+
+/
+ * Name: fmemopen_write
+ /
+
+static ssize_t fmemopen_write(FAR void *c, FAR const char *buf, size_t size)
+{
+  FAR struct fmemopen_cookie_s *fmemopen_cookie =
+(FAR struct fmemopen_cookie_s *)c;
+  if (size + fmemopen_cookie->pos > fmemopen_cookie->size)
+{
+  return -ENOSPC;
+}
+
+  memcpy(fmemopen_cookie->buf + fmemopen_cookie->pos, buf, size);
+
+  fmemopen_cookie->pos += size;
+  if (fmemopen_cookie->pos > fmemopen_cookie->end)
+{
+  fmemopen_cookie->end = fmemopen_cookie->pos;
+}
+
+  /* POSIX states that NULL byte shall be written at the current position
+   * or end of the buffer.
+   */
+
+  if (fmemopen_cookie->pos < fmemopen_cookie->size &&
+  fmemopen_cookie->buf[fmemopen_cookie->pos - 1] != '\0')
+{
+  fmemopen_cookie->buf[fmemopen_cookie->pos] = '\0';
+}
+
+  return size;
+}
+
+/
+ * Name: fmemopen_seek
+ /
+
+static off_t fmemopen_seek(FAR void *c, FAR off_t *offset, int whence)
+{
+  FAR struct fmemopen_cookie_s *fmemopen_cookie =
+(FAR struct fmemopen_cookie_s *)c;
+  off_t new_offset;
+
+  switch (whence)
+{
+  case SEEK_SET:
+new_offset = *offset;
+break;
+  case SEEK_END:
+new_offset = fmemopen_cookie->end + *offset;
+break;
+  case SEEK_CUR:
+new_offset = fmemopen_cookie->pos + *offset;
+break;
+  default:
+return ENOTSUP;
+}
+
+  /* Seek to negative value or value larger than maximum size shall fail. */
+
+  if (new_offset < 0 || (new_offset > fmemopen_cookie->end))
+{
+  return EINVAL;
+}
+
+  fmemopen_cookie->pos = new_offset;
+  *offset = new_offset;
+  return new_offset;
+}
+
+/
+ * Name: fmemopen_close
+ /
+
+static int fmemopen_close(FAR void *c)
+{

Re: [PR] libc: add support for memory buffer stream with fmemopen() [nuttx]

2023-10-25 Thread via GitHub


michallenc commented on code in PR #11011:
URL: https://github.com/apache/nuttx/pull/11011#discussion_r1371575230


##
libs/libc/stdio/lib_fmemopen.c:
##
@@ -0,0 +1,291 @@
+/
+ * libs/libc/stdio/lib_fmemopen.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ /
+
+/
+ * Included Files
+ /
+
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "libc.h"
+
+/
+ * Private Types
+ /
+
+struct fmemopen_cookie_s
+{
+  FAR char *buf;/* Memory buffer */
+  off_t pos;/* Current position in the buffer */
+  off_t end;/* End buffer position */
+  size_t size;  /* Buffer size */
+  bool custom;  /* True if custom buffer is used */
+};
+
+/
+ * Private Functions
+ /
+
+/
+ * Name: fmemopen_read
+ /
+
+static ssize_t fmemopen_read(FAR void *c, FAR char *buf, size_t size)
+{
+  FAR struct fmemopen_cookie_s *fmemopen_cookie =
+(FAR struct fmemopen_cookie_s *)c;
+  if (fmemopen_cookie->pos + size > fmemopen_cookie->end)
+{
+  size = fmemopen_cookie->end - fmemopen_cookie->pos;
+}
+
+  if (size < 0)

Review Comment:
   Removed.



##
libs/libc/stdio/lib_fmemopen.c:
##
@@ -0,0 +1,291 @@
+/
+ * libs/libc/stdio/lib_fmemopen.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ /
+
+/
+ * Included Files
+ /
+
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "libc.h"
+
+/
+ * Private Types
+ /
+
+struct fmemopen_cookie_s
+{
+  FAR char *buf;/* Memory buffer */
+  off_t pos;/* Current position in the buffer */
+  off_t end;/* End buffer position */
+  size_t size;  /* Buffer size */
+  bool custom;  /* True if custom buffer is used */
+};
+
+/
+ * Private Functions
+ /
+
+/
+ * Name: fmemopen_read
+ /
+
+static ssize_t fmemopen_read(FAR void *c, FAR char *buf, size_t size)
+{
+  FAR struct fmemopen_cookie_s *fmemopen_cookie =
+   

Re: [PR] libc: add support for memory buffer stream with fmemopen() [nuttx]

2023-10-24 Thread via GitHub


xiaoxiang781216 commented on code in PR #11011:
URL: https://github.com/apache/nuttx/pull/11011#discussion_r1370496054


##
libs/libc/stdio/lib_fmemopen.c:
##
@@ -0,0 +1,291 @@
+/
+ * libs/libc/stdio/lib_fmemopen.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ /
+
+/
+ * Included Files
+ /
+
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "libc.h"
+
+/
+ * Private Types
+ /
+
+struct fmemopen_cookie_s
+{
+  FAR char *buf;/* Memory buffer */
+  off_t pos;/* Current position in the buffer */
+  off_t end;/* End buffer position */
+  size_t size;  /* Buffer size */
+  bool custom;  /* True if custom buffer is used */
+};
+
+/
+ * Private Functions
+ /
+
+/
+ * Name: fmemopen_read
+ /
+
+static ssize_t fmemopen_read(FAR void *c, FAR char *buf, size_t size)
+{
+  FAR struct fmemopen_cookie_s *fmemopen_cookie =
+(FAR struct fmemopen_cookie_s *)c;
+  if (fmemopen_cookie->pos + size > fmemopen_cookie->end)
+{
+  size = fmemopen_cookie->end - fmemopen_cookie->pos;
+}
+
+  if (size < 0)

Review Comment:
   impossible



##
libs/libc/stdio/lib_fmemopen.c:
##
@@ -0,0 +1,291 @@
+/
+ * libs/libc/stdio/lib_fmemopen.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ /
+
+/
+ * Included Files
+ /
+
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "libc.h"
+
+/
+ * Private Types
+ /
+
+struct fmemopen_cookie_s
+{
+  FAR char *buf;/* Memory buffer */
+  off_t pos;/* Current position in the buffer */
+  off_t end;/* End buffer position */
+  size_t size;  /* Buffer size */
+  bool custom;  /* True if custom buffer is used */
+};
+
+/
+ * Private Functions
+ /
+
+/
+ * Name: fmemopen_read
+ /
+
+static ssize_t fmemopen_read(FAR void *c, FAR char *buf, size_t size)
+{
+  FAR struct fmemopen_cookie_s 

Re: [PR] libc: add support for memory buffer stream with fmemopen() [nuttx]

2023-10-24 Thread via GitHub


michallenc commented on PR #11011:
URL: https://github.com/apache/nuttx/pull/11011#issuecomment-1777213698

   > @michallenc any idea why it is failing to pass in CI ?
   
   @acassis I have added new test specially for `fmemopen`, it has to be merged 
first to `nuttx-apps` (https://github.com/apache/nuttx-apps/pull/2155). CI does 
not see the application and thus fails.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [PR] libc: add support for memory buffer stream with fmemopen() [nuttx]

2023-10-24 Thread via GitHub


acassis commented on PR #11011:
URL: https://github.com/apache/nuttx/pull/11011#issuecomment-1777210292

   @michallenc any idea why it is failing to pass in CI ?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



[PR] libc: add support for memory buffer stream with fmemopen() [nuttx]

2023-10-24 Thread via GitHub


michallenc opened a new pull request, #11011:
URL: https://github.com/apache/nuttx/pull/11011

   ## Summary
   
   Add support for POSIX interface `fmemopen()`. This interface open a memory 
buffer as a stream and permits access to this buffer specified by mode. This 
allows I/O operations to be performed on the memory buffer.
   
   The implementation uses `fopencookie()` for custom stream operations and 
callbacks.
   
   CI test for `fmemopen()` function was added. The test was merged with 
`fopencookie` interface test and merged into single test_stdio.
   
   ## Impact
   New POSIX interface.
   
   ## Testing
   Tested with test application on simulator and real hardware (SAMv7). CI test 
added.
   
   Note that this has to be merged after [testing: add fmemopen function test 
tool ](https://github.com/apache/nuttx-apps/pull/2155) pull request to 
`nuttx-apps`.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org