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

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


The following commit(s) were added to refs/heads/master by this push:
     new dc69b108b8 libs/libc/aio: fix aio_write compatible bug
dc69b108b8 is described below

commit dc69b108b8e0547ecf6990207526c27aceaf1e2e
Author: guoshichao <[email protected]>
AuthorDate: Fri Jun 9 16:04:29 2023 +0800

    libs/libc/aio: fix aio_write compatible bug
    
    1. make the aio_write implementation can pass the
    lpt/open_posix_testsuite/aio_write testcases
    2. the modification are referred to 
https://pubs.opengroup.org/onlinepubs/9699919799/functions/aio_write.html
    
    Signed-off-by: guoshichao <[email protected]>
---
 fs/aio/aio_write.c | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/fs/aio/aio_write.c b/fs/aio/aio_write.c
index 580b2ea3a6..803bbdfa1c 100644
--- a/fs/aio/aio_write.c
+++ b/fs/aio/aio_write.c
@@ -249,6 +249,40 @@ int aio_write(FAR struct aiocb *aiocbp)
 
   DEBUGASSERT(aiocbp);
 
+  if (aiocbp->aio_reqprio < 0)
+    {
+      set_errno(EINVAL);
+      return ERROR;
+    }
+
+  if (aiocbp->aio_offset < 0)
+    {
+      aiocbp->aio_result = -EINVAL;
+      return OK;
+    }
+
+  if (aiocbp->aio_fildes < 0)
+    {
+      /* for EBADF, the aio_write do not return error directly, but using
+       * aio_error to return this error code
+       */
+
+      aiocbp->aio_result = -EBADF;
+      return OK;
+    }
+
+  /* the aio_fildes that transferred in may be opened with O_RDONLY, for this
+   * case, we need to return OK directly, and using the aio_error to collect
+   * the EBADF error code
+   */
+
+  int flags = fcntl(aiocbp->aio_fildes, F_GETFL);
+  if (!(flags & O_WRONLY))
+    {
+      aiocbp->aio_result = -EBADF;
+      return OK;
+    }
+
   /* The result -EINPROGRESS means that the transfer has not yet completed */
 
   sigwork_init(&aiocbp->aio_sigwork);

Reply via email to