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

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

commit e5b0627504d78261c3c65f762888cdda970ca08a
Author: ganjing <[email protected]>
AuthorDate: Mon Nov 23 14:26:54 2026 +0800

    libc/unistd: Return EINVAL for a zero length in fallocate().
    
    fallocate() and posix_fallocate() accepted a zero len and returned success.
    POSIX and Linux fallocate(2) require EINVAL when len is zero or less than
    zero, so reject len <= 0 together with a negative offset.
    
    Signed-off-by: ganjing <[email protected]>
---
 libs/libc/unistd/lib_fallocate.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libs/libc/unistd/lib_fallocate.c b/libs/libc/unistd/lib_fallocate.c
index 3f328e77de9..2e04ec5b206 100644
--- a/libs/libc/unistd/lib_fallocate.c
+++ b/libs/libc/unistd/lib_fallocate.c
@@ -68,7 +68,7 @@
  *   Upon successful completion, fallocate() returns zero; otherwise -1
  *   is returned and errno is set to indicate the error.
  *
- *   EINVAL      - offset or len was less than 0.
+ *   EINVAL      - offset was less than 0, or len was 0 or less.
  *   EFBIG       - offset+len exceeds the maximum file size.
  *   EOPNOTSUPP  - mode contains flags other than FALLOC_FL_KEEP_SIZE.
  *   EBADF       - fd is not a valid file descriptor (via fstat()).
@@ -80,7 +80,7 @@ int fallocate(int fd, int mode, off_t offset, off_t len)
 {
   struct stat st;
 
-  if (offset < 0 || len < 0)
+  if (offset < 0 || len <= 0)
     {
       set_errno(EINVAL);
       return ERROR;

Reply via email to