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 607488920ef5b39a7f48b91596b6d06a594f8d09
Author: anpeiyun <[email protected]>
AuthorDate: Fri Oct 10 17:13:47 2025 +0800

    libc/unistd: Support the _PC_xxx names in pathconf() and fpathconf().
    
    Add support for the following _PC_xxx constants in fpathconf/pathconf:
    _PC_CHOWN_RESTRICTED, _PC_ALLOC_SIZE_MIN, _PC_REC_INCR_XFER_SIZE, 
_PC_REC_MAX_XFER_SIZE, _PC_REC_MIN_XFER_SIZE, _PC_REC_XFER_ALIGN and 
_PC_2_SYMLINKS.
    And fix error handling according to POSIX specification: return -1 and set 
errno to EINVAL when provided with an invalid 'name' parameter.
    
https://pubs.opengroup.org/onlinepubs/9699919799/functions/fpathconf.html#tag_16_157
    
    Signed-off-by: anpeiyun <[email protected]>
    Signed-off-by: ganjing <[email protected]>
---
 include/unistd.h                |  3 ++-
 libs/libc/unistd/lib_pathconf.c | 34 ++++++++++++++++++++++++++++++++--
 2 files changed, 34 insertions(+), 3 deletions(-)

diff --git a/include/unistd.h b/include/unistd.h
index f50ca0d7bde..e57569b400d 100644
--- a/include/unistd.h
+++ b/include/unistd.h
@@ -181,7 +181,7 @@
 
 /* Execution time constants (not supported) */
 
-#undef  _POSIX_CHOWN_RESTRICTED
+#define _POSIX_CHOWN_RESTRICTED 1
 #undef  _POSIX_NO_TRUNC
 
 /* The value of a c_cc entry of struct termios that disables the special
@@ -220,6 +220,7 @@
 #define _PC_SYMLINK_MAX                  0x0011
 #define _PC_SYNC_IO                      0x0012
 #define _PC_VDISABLE                     0x0013
+#define _PC_REC_MAX_XFER_SIZE            0x0014
 
 /* Constants used with POSIX sysconf().  sysconf() returns -1 for the
  * options and limits that NuttX does not have.
diff --git a/libs/libc/unistd/lib_pathconf.c b/libs/libc/unistd/lib_pathconf.c
index 70078f1969c..93eab5cb945 100644
--- a/libs/libc/unistd/lib_pathconf.c
+++ b/libs/libc/unistd/lib_pathconf.c
@@ -142,11 +142,41 @@ long fpathconf(int fildes, int name)
       case _PC_VDISABLE:
         return _POSIX_VDISABLE;
 
+      case _PC_CHOWN_RESTRICTED:
+        return _POSIX_CHOWN_RESTRICTED;
+
+      case _PC_ALLOC_SIZE_MIN:
+        return -1;
+
+      case _PC_REC_INCR_XFER_SIZE:
+        return -1;
+
+      case _PC_REC_MAX_XFER_SIZE:
+        return -1;
+
+      case _PC_REC_MIN_XFER_SIZE:
+        return -1;
+
+      case _PC_REC_XFER_ALIGN:
+        return -1;
+
+      case _PC_2_SYMLINKS:
+        return -1;
+
       default:
+        if (name >= 0)
+          {
+            /* Valid but not implemented for the time being */
+
+            set_errno(ENOSYS);
+          }
+        else
+          {
+            /* Invalid value */
 
-        /* Assume valid but not implemented for the time being */
+            set_errno(EINVAL);
+          }
 
-        set_errno(ENOSYS);
         return ERROR;
     }
 }

Reply via email to