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 b480ce84623a868392f31d51be4486ee80953434 Author: Marco Casaroli <[email protected]> AuthorDate: Fri Oct 9 08:41:44 2026 +0200 libs/libc/unistd: Make getdtablesize() and getpagesize() functions. getdtablesize() and getpagesize() were macros with a dummy parameter, so a program that declares them ("extern int getpagesize(void);") did not compile, and a program could not take their address. Make them ordinary functions that return sysconf(_SC_OPEN_MAX) and sysconf(_SC_PAGESIZE). Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli <[email protected]> --- include/unistd.h | 7 ++++-- libs/libc/unistd/CMakeLists.txt | 2 ++ libs/libc/unistd/Make.defs | 3 ++- libs/libc/unistd/lib_getdtablesize.c | 47 ++++++++++++++++++++++++++++++++++++ libs/libc/unistd/lib_getpagesize.c | 47 ++++++++++++++++++++++++++++++++++++ 5 files changed, 103 insertions(+), 3 deletions(-) diff --git a/include/unistd.h b/include/unistd.h index cc4576f35aa..510deba2293 100644 --- a/include/unistd.h +++ b/include/unistd.h @@ -286,8 +286,6 @@ /* Helpers and legacy compatibility definitions */ #define fdatasync(f) fsync(f) -#define getdtablesize(f) ((int)sysconf(_SC_OPEN_MAX)) -#define getpagesize(f) ((int)sysconf(_SC_PAGESIZE)) /* Accessor functions associated with getopt(). */ @@ -399,6 +397,11 @@ int isatty(int fd); FAR char *ttyname(int fd); int ttyname_r(int fd, FAR char *buf, size_t buflen); +/* Legacy BSD interfaces */ + +int getdtablesize(void); +int getpagesize(void); + /* The name of the user */ FAR char *getlogin(void); diff --git a/libs/libc/unistd/CMakeLists.txt b/libs/libc/unistd/CMakeLists.txt index 7d1b1461439..75bc4f69931 100644 --- a/libs/libc/unistd/CMakeLists.txt +++ b/libs/libc/unistd/CMakeLists.txt @@ -26,6 +26,8 @@ set(SRCS lib_swab.c lib_pathconf.c lib_sysconf.c + lib_getdtablesize.c + lib_getpagesize.c lib_getcwd.c lib_getentropy.c lib_getopt_common.c diff --git a/libs/libc/unistd/Make.defs b/libs/libc/unistd/Make.defs index c4a582292f4..207376a3bfb 100644 --- a/libs/libc/unistd/Make.defs +++ b/libs/libc/unistd/Make.defs @@ -27,7 +27,8 @@ CSRCS += lib_getcwd.c lib_getentropy.c lib_getopt_common.c lib_getopt.c CSRCS += lib_getopt_long.c lib_getopt_longonly.c lib_getoptvars.c lib_getoptargp.c CSRCS += lib_getopterrp.c lib_getoptindp.c lib_getoptoptp.c lib_times.c CSRCS += lib_alarm.c lib_fstatvfs.c lib_statvfs.c lib_sleep.c lib_nice.c -CSRCS += lib_getrusage.c lib_utime.c lib_utimes.c +CSRCS += lib_getrusage.c lib_utime.c lib_utimes.c lib_getdtablesize.c +CSRCS += lib_getpagesize.c CSRCS += lib_setrlimit.c lib_getrlimit.c lib_setpriority.c lib_getpriority.c CSRCS += lib_futimes.c lib_lutimes.c lib_gethostname.c lib_sethostname.c CSRCS += lib_fchownat.c lib_linkat.c lib_readlinkat.c lib_symlinkat.c diff --git a/libs/libc/unistd/lib_getdtablesize.c b/libs/libc/unistd/lib_getdtablesize.c new file mode 100644 index 00000000000..7719b6c13b8 --- /dev/null +++ b/libs/libc/unistd/lib_getdtablesize.c @@ -0,0 +1,47 @@ +/**************************************************************************** + * libs/libc/unistd/lib_getdtablesize.c + * + * SPDX-License-Identifier: Apache-2.0 + * + * 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 <unistd.h> + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: getdtablesize + * + * Description: + * Return the size of the file descriptor table of the process. + * + * Returned Value: + * sysconf(_SC_OPEN_MAX). + * + ****************************************************************************/ + +int getdtablesize(void) +{ + return sysconf(_SC_OPEN_MAX); +} diff --git a/libs/libc/unistd/lib_getpagesize.c b/libs/libc/unistd/lib_getpagesize.c new file mode 100644 index 00000000000..6f133c406df --- /dev/null +++ b/libs/libc/unistd/lib_getpagesize.c @@ -0,0 +1,47 @@ +/**************************************************************************** + * libs/libc/unistd/lib_getpagesize.c + * + * SPDX-License-Identifier: Apache-2.0 + * + * 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 <unistd.h> + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: getpagesize + * + * Description: + * Return the size of a memory page. + * + * Returned Value: + * sysconf(_SC_PAGESIZE). + * + ****************************************************************************/ + +int getpagesize(void) +{ + return sysconf(_SC_PAGESIZE); +}
