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-apps.git

commit c56e79394c2998ca2369e0737925ab77c504da83
Author: Marco Casaroli <[email protected]>
AuthorDate: Mon Oct 12 08:42:56 2026 +0200

    apps: Include the headers that are used.
    
    These files use declarations from stdlib.h, unistd.h, pthread.h and
    other headers without including them.  They got the declarations only
    because stdio.h included nuttx/lib/lib.h, and through it stdlib.h,
    nuttx/sched.h and more.
    
    - stdlib.h: adjtime, ads7046, audio_rttl, baromonitor, bmp280, hx711,
      netpkt_ethercat, nimble_blecent (main, peer), nimble_bleprph (main,
      gatt_svr), shv-test, stepper, tmp112, dhcpd, netlib_iptables,
      netlib_ip6tables, adcscope, iptables, ip6tables, nxdiag, sensorscope,
      nxboot boot.c, nand_sim, pcitest, cachetest, ymodem rb and sb.
    - unistd.h: nxboot boot.c and flash.c, fbcon, netpkt_ethercat,
      nimble_blecent, nimble_bleprph, shv-test, stepper, watched,
      lapi_other, ofloader, nand_sim, ser, setest, drivertest_block,
      drivertest_i2c_spi, drivertest_relay, epoll, fdsantest_simple,
      memfd_test, i8sak_acceptassoc, passwd_delete, plcatool.  NXDoom: in
      i_timer.h, which every file that calls usleep() includes.
    - pthread.h: camera_bkgd, mqttc_pub, nxterm, pty_test, pwfb_events,
      pwlines_events, ofloader, epoll, memfd_test, ostest
      sched_thread_local.c and i8sak.h.
    - sched.h: ble_main, calib_udelay, drivertest_pm_smp.
      nuttx/atomic.h: the atomic test.  nuttx/kmalloc.h: nand_sim,
      drivertest_block.
    - testing/cmocka: the downloaded cmocka.c uses ftruncate(); include
      unistd.h in cmocka_platform.h, which cmocka.c includes.
    - system/zlib: the downloaded gzlib.c, gzread.c and gzwrite.c use
      lseek(), read() and write(); make zconf.h include unistd.h, as
      zlib's configure does on Unix.
    - interpreters/wamr: the NuttX platform of older WAMR versions (sim:wamr
      pins one) uses the pthread types without including pthread.h; build
      WAMR with -include pthread.h.
    
    Assisted-by: Claude Code:claude-opus-5-5
    Signed-off-by: Marco Casaroli <[email protected]>
---
 boot/nxboot/loader/boot.c                       | 2 ++
 boot/nxboot/loader/flash.c                      | 1 +
 examples/adjtime/adjtime_main.c                 | 1 +
 examples/ads7046/ads7046_main.c                 | 1 +
 examples/audio_rttl/audio_rttl_main.c           | 1 +
 examples/baromonitor/baromonitor_main.c         | 1 +
 examples/ble/ble_main.c                         | 1 +
 examples/bmp280/bmp280_main.c                   | 1 +
 examples/calib_udelay/calib_udelay_main.c       | 1 +
 examples/camera/camera_bkgd.c                   | 1 +
 examples/fbcon/fbcon_main.c                     | 1 +
 examples/hx711/hx711_main.c                     | 1 +
 examples/mqttc/mqttc_pub.c                      | 1 +
 examples/netpkt/netpkt_ethercat.c               | 2 ++
 examples/nimble_blecent/nimble_blecent_main.c   | 2 ++
 examples/nimble_blecent/peer.c                  | 1 +
 examples/nimble_bleprph/gatt_svr.c              | 1 +
 examples/nimble_bleprph/nimble_bleprph_main.c   | 2 ++
 examples/nxterm/nxterm_main.c                   | 1 +
 examples/pty_test/pty_test.c                    | 1 +
 examples/pwfb/pwfb_events.c                     | 1 +
 examples/pwlines/pwlines_events.c               | 1 +
 examples/shv-test/shv_test.c                    | 2 ++
 examples/stepper/stepper.c                      | 2 ++
 examples/tmp112/tmp112_main.c                   | 1 +
 examples/watched/watched.c                      | 1 +
 fsutils/passwd/passwd_delete.c                  | 1 +
 games/NXDoom/src/i_timer.h                      | 6 ++++++
 interpreters/wamr/CMakeLists.txt                | 5 +++++
 interpreters/wamr/Makefile                      | 5 +++++
 lte/lapi/src/lapi_other.c                       | 1 +
 netutils/dhcpd/dhcpd.c                          | 1 +
 netutils/netlib/netlib_ip6tables.c              | 1 +
 netutils/netlib/netlib_iptables.c               | 1 +
 netutils/plcatool/plcatool.c                    | 1 +
 system/adcscope/adcscope_main.c                 | 1 +
 system/iptables/ip6tables.c                     | 1 +
 system/iptables/iptables.c                      | 1 +
 system/nxdiag/nxdiag.c                          | 1 +
 system/ofloader/ofloader.c                      | 2 ++
 system/sensorscope/sensorscope_main.c           | 1 +
 system/ymodem/rb_main.c                         | 1 +
 system/ymodem/sb_main.c                         | 1 +
 system/zlib/CMakeLists.txt                      | 8 ++++++++
 system/zlib/Makefile                            | 5 +++++
 testing/cmocka/cmocka_platform.h                | 1 +
 testing/drivers/drivertest/drivertest_block.c   | 2 ++
 testing/drivers/drivertest/drivertest_i2c_spi.c | 1 +
 testing/drivers/drivertest/drivertest_pm_smp.c  | 1 +
 testing/drivers/drivertest/drivertest_relay.c   | 1 +
 testing/drivers/nand_sim/nand_sim_main.c        | 3 +++
 testing/drivers/pcitest/pcitest.c               | 1 +
 testing/drivers/ser/ser.c                       | 1 +
 testing/drivers/setest/setest.c                 | 1 +
 testing/fs/epoll/epoll.c                        | 2 ++
 testing/fs/fdsantest/fdsantest_simple.c         | 1 +
 testing/fs/memfd/memfd_test.c                   | 2 ++
 testing/libc/atomic/atomic_main.c               | 1 +
 testing/mm/cachetest/cachetest_main.c           | 1 +
 testing/ostest/sched_thread_local.c             | 1 +
 wireless/ieee802154/i8sak/i8sak.h               | 1 +
 wireless/ieee802154/i8sak/i8sak_acceptassoc.c   | 1 +
 62 files changed, 98 insertions(+)

diff --git a/boot/nxboot/loader/boot.c b/boot/nxboot/loader/boot.c
index 54ac92678..b2b350e42 100644
--- a/boot/nxboot/loader/boot.c
+++ b/boot/nxboot/loader/boot.c
@@ -34,6 +34,8 @@
 
 #include <nuttx/crc32.h>
 #include <nxboot.h>
+#include <stdlib.h>
+#include <unistd.h>
 
 #include "flash.h"
 
diff --git a/boot/nxboot/loader/flash.c b/boot/nxboot/loader/flash.c
index ab6a24320..50ef92930 100644
--- a/boot/nxboot/loader/flash.c
+++ b/boot/nxboot/loader/flash.c
@@ -33,6 +33,7 @@
 #include <stddef.h>
 #include <fcntl.h>
 #include <syslog.h>
+#include <unistd.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <sys/ioctl.h>
diff --git a/examples/adjtime/adjtime_main.c b/examples/adjtime/adjtime_main.c
index fefe80567..1ec96e6ff 100644
--- a/examples/adjtime/adjtime_main.c
+++ b/examples/adjtime/adjtime_main.c
@@ -27,6 +27,7 @@
 #include <nuttx/config.h>
 #include <stdint.h>
 #include <stdio.h>
+#include <stdlib.h>
 #include <sys/time.h>
 
 /****************************************************************************
diff --git a/examples/ads7046/ads7046_main.c b/examples/ads7046/ads7046_main.c
index 1b0ca7253..8fd61a53a 100644
--- a/examples/ads7046/ads7046_main.c
+++ b/examples/ads7046/ads7046_main.c
@@ -28,6 +28,7 @@
 #include <stdio.h>
 #include <fcntl.h>
 #include <unistd.h>
+#include <stdlib.h>
 #include <sys/ioctl.h>
 #include <nuttx/analog/ioctl.h>
 #include <nuttx/analog/ads7046.h>
diff --git a/examples/audio_rttl/audio_rttl_main.c 
b/examples/audio_rttl/audio_rttl_main.c
index 4c0389bd7..6d1e29326 100644
--- a/examples/audio_rttl/audio_rttl_main.c
+++ b/examples/audio_rttl/audio_rttl_main.c
@@ -29,6 +29,7 @@
 #include <math.h>
 #include <stdio.h>
 #include <string.h>
+#include <stdlib.h>
 
 #include <sys/ioctl.h>
 
diff --git a/examples/baromonitor/baromonitor_main.c 
b/examples/baromonitor/baromonitor_main.c
index c3a93d6b9..3f6044f61 100644
--- a/examples/baromonitor/baromonitor_main.c
+++ b/examples/baromonitor/baromonitor_main.c
@@ -29,6 +29,7 @@
 #include <fcntl.h>
 #include <stdio.h>
 #include <unistd.h>
+#include <stdlib.h>
 
 #include <uORB/uORB.h>
 
diff --git a/examples/ble/ble_main.c b/examples/ble/ble_main.c
index 7afb2eedd..966b4318a 100644
--- a/examples/ble/ble_main.c
+++ b/examples/ble/ble_main.c
@@ -26,6 +26,7 @@
 
 #include <nuttx/config.h>
 #include <pthread.h>
+#include <sched.h>
 #include "sensors.h"
 
 extern void setup_ble(void);
diff --git a/examples/bmp280/bmp280_main.c b/examples/bmp280/bmp280_main.c
index 1b8fdde88..97279074c 100644
--- a/examples/bmp280/bmp280_main.c
+++ b/examples/bmp280/bmp280_main.c
@@ -28,6 +28,7 @@
 #include <stdio.h>
 #include <fcntl.h>
 #include <unistd.h>
+#include <stdlib.h>
 #include <nuttx/sensors/sensor.h>
 
 /****************************************************************************
diff --git a/examples/calib_udelay/calib_udelay_main.c 
b/examples/calib_udelay/calib_udelay_main.c
index 1c9a822f9..509434aa1 100644
--- a/examples/calib_udelay/calib_udelay_main.c
+++ b/examples/calib_udelay/calib_udelay_main.c
@@ -32,6 +32,7 @@
 #include <string.h>
 #include <math.h>
 #include <unistd.h>
+#include <sched.h>
 
 /****************************************************************************
  * Pre-processor Definitions
diff --git a/examples/camera/camera_bkgd.c b/examples/camera/camera_bkgd.c
index a0c0bd2fa..78ff81dc6 100644
--- a/examples/camera/camera_bkgd.c
+++ b/examples/camera/camera_bkgd.c
@@ -32,6 +32,7 @@
 #include <stdlib.h>
 #include <semaphore.h>
 #include <errno.h>
+#include <pthread.h>
 #include <nuttx/debug.h>
 #include <sys/boardctl.h>
 
diff --git a/examples/fbcon/fbcon_main.c b/examples/fbcon/fbcon_main.c
index 40edc91f8..9a16f7723 100644
--- a/examples/fbcon/fbcon_main.c
+++ b/examples/fbcon/fbcon_main.c
@@ -44,6 +44,7 @@
 #include <spawn.h>
 #include <nuttx/debug.h>
 #include <poll.h>
+#include <unistd.h>
 #include <nuttx/ascii.h>
 #include <nuttx/lib/builtin.h>
 
diff --git a/examples/hx711/hx711_main.c b/examples/hx711/hx711_main.c
index 28258dc5d..e3b847713 100644
--- a/examples/hx711/hx711_main.c
+++ b/examples/hx711/hx711_main.c
@@ -32,6 +32,7 @@
 #include <errno.h>
 #include <string.h>
 #include <stdio.h>
+#include <stdlib.h>
 #include <sys/ioctl.h>
 
 /****************************************************************************
diff --git a/examples/mqttc/mqttc_pub.c b/examples/mqttc/mqttc_pub.c
index 0e5999599..195e988a1 100644
--- a/examples/mqttc/mqttc_pub.c
+++ b/examples/mqttc/mqttc_pub.c
@@ -33,6 +33,7 @@
 #include <netdb.h>
 #include <errno.h>
 #include <mqtt.h>
+#include <pthread.h>
 
 #ifdef MQTT_USE_MBEDTLS
 #  include <inttypes.h>
diff --git a/examples/netpkt/netpkt_ethercat.c 
b/examples/netpkt/netpkt_ethercat.c
index ea24791a7..683a2f579 100644
--- a/examples/netpkt/netpkt_ethercat.c
+++ b/examples/netpkt/netpkt_ethercat.c
@@ -29,6 +29,8 @@
 #include <stdint.h>
 #include <stdio.h>
 #include <time.h>
+#include <stdlib.h>
+#include <unistd.h>
 
 #include <net/if.h>
 #include <netinet/if_ether.h>
diff --git a/examples/nimble_blecent/nimble_blecent_main.c 
b/examples/nimble_blecent/nimble_blecent_main.c
index 1d78e6d11..faec78daf 100644
--- a/examples/nimble_blecent/nimble_blecent_main.c
+++ b/examples/nimble_blecent/nimble_blecent_main.c
@@ -26,6 +26,8 @@
 
 #include <assert.h>
 #include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
 
 /* BLE */
 
diff --git a/examples/nimble_blecent/peer.c b/examples/nimble_blecent/peer.c
index 16ebd7872..b0e889ce4 100644
--- a/examples/nimble_blecent/peer.c
+++ b/examples/nimble_blecent/peer.c
@@ -26,6 +26,7 @@
 
 #include <assert.h>
 #include <string.h>
+#include <stdlib.h>
 #include "host/ble_hs.h"
 #include "blecent.h"
 
diff --git a/examples/nimble_bleprph/gatt_svr.c 
b/examples/nimble_bleprph/gatt_svr.c
index 38efeefd1..aff7940d7 100644
--- a/examples/nimble_bleprph/gatt_svr.c
+++ b/examples/nimble_bleprph/gatt_svr.c
@@ -27,6 +27,7 @@
 #include <assert.h>
 #include <stdio.h>
 #include <string.h>
+#include <stdlib.h>
 #include "host/ble_hs.h"
 #include "host/ble_uuid.h"
 #include "services/ans/ble_svc_ans.h"
diff --git a/examples/nimble_bleprph/nimble_bleprph_main.c 
b/examples/nimble_bleprph/nimble_bleprph_main.c
index 9c41f72b2..4d1cd4463 100644
--- a/examples/nimble_bleprph/nimble_bleprph_main.c
+++ b/examples/nimble_bleprph/nimble_bleprph_main.c
@@ -28,6 +28,8 @@
 #include <string.h>
 #include <stdio.h>
 #include <errno.h>
+#include <stdlib.h>
+#include <unistd.h>
 
 /* BLE */
 
diff --git a/examples/nxterm/nxterm_main.c b/examples/nxterm/nxterm_main.c
index afe6f34ba..a544934e8 100644
--- a/examples/nxterm/nxterm_main.c
+++ b/examples/nxterm/nxterm_main.c
@@ -39,6 +39,7 @@
 #include <string.h>
 #include <assert.h>
 #include <errno.h>
+#include <pthread.h>
 #include <nuttx/debug.h>
 
 #ifdef CONFIG_NX_LCDDRIVER
diff --git a/examples/pty_test/pty_test.c b/examples/pty_test/pty_test.c
index 25c4c9fe0..15b519f1d 100644
--- a/examples/pty_test/pty_test.c
+++ b/examples/pty_test/pty_test.c
@@ -35,6 +35,7 @@
 #include <poll.h>
 #include <fcntl.h>
 #include <errno.h>
+#include <pthread.h>
 #include <sys/ioctl.h>
 
 #include <nuttx/serial/pty.h>
diff --git a/examples/pwfb/pwfb_events.c b/examples/pwfb/pwfb_events.c
index bec7a845a..741279aea 100644
--- a/examples/pwfb/pwfb_events.c
+++ b/examples/pwfb/pwfb_events.c
@@ -33,6 +33,7 @@
 #include <semaphore.h>
 #include <nuttx/debug.h>
 #include <errno.h>
+#include <pthread.h>
 
 #include <nuttx/nx/nx.h>
 #include <nuttx/nx/nxtk.h>
diff --git a/examples/pwlines/pwlines_events.c 
b/examples/pwlines/pwlines_events.c
index 3dcd0504c..c7da7d096 100644
--- a/examples/pwlines/pwlines_events.c
+++ b/examples/pwlines/pwlines_events.c
@@ -33,6 +33,7 @@
 #include <semaphore.h>
 #include <nuttx/debug.h>
 #include <errno.h>
+#include <pthread.h>
 
 #include <nuttx/nx/nx.h>
 #include <nuttx/nx/nxtk.h>
diff --git a/examples/shv-test/shv_test.c b/examples/shv-test/shv_test.c
index 1d2d1acf9..1b69bb24d 100644
--- a/examples/shv-test/shv_test.c
+++ b/examples/shv-test/shv_test.c
@@ -37,6 +37,8 @@
 #include <signal.h>
 #include <semaphore.h>
 #include <stdbool.h>
+#include <stdlib.h>
+#include <unistd.h>
 
 /****************************************************************************
  * Private Function Prototypes
diff --git a/examples/stepper/stepper.c b/examples/stepper/stepper.c
index 2d9acdaff..c2f7e6180 100644
--- a/examples/stepper/stepper.c
+++ b/examples/stepper/stepper.c
@@ -28,6 +28,8 @@
 #include <fcntl.h>
 #include <stdio.h>
 #include <stdbool.h>
+#include <stdlib.h>
+#include <unistd.h>
 
 #include <nuttx/motor/stepper.h>
 
diff --git a/examples/tmp112/tmp112_main.c b/examples/tmp112/tmp112_main.c
index 0fbf6f0f9..9af75a208 100644
--- a/examples/tmp112/tmp112_main.c
+++ b/examples/tmp112/tmp112_main.c
@@ -28,6 +28,7 @@
 #include <stdio.h>
 #include <fcntl.h>
 #include <unistd.h>
+#include <stdlib.h>
 
 /****************************************************************************
  * Public Functions
diff --git a/examples/watched/watched.c b/examples/watched/watched.c
index 9013590a0..07ab6be28 100644
--- a/examples/watched/watched.c
+++ b/examples/watched/watched.c
@@ -32,6 +32,7 @@
 #include <errno.h>
 #include "watched.h"
 #include <signal.h>
+#include <unistd.h>
 
 /****************************************************************************
  * Private Definitions
diff --git a/fsutils/passwd/passwd_delete.c b/fsutils/passwd/passwd_delete.c
index 3dbc49fdd..fe620af93 100644
--- a/fsutils/passwd/passwd_delete.c
+++ b/fsutils/passwd/passwd_delete.c
@@ -29,6 +29,7 @@
 #include <sys/types.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <unistd.h>
 #include <assert.h>
 #include <errno.h>
 
diff --git a/games/NXDoom/src/i_timer.h b/games/NXDoom/src/i_timer.h
index eb9d7756c..e731beca4 100644
--- a/games/NXDoom/src/i_timer.h
+++ b/games/NXDoom/src/i_timer.h
@@ -24,6 +24,12 @@
 #ifndef __I_TIMER__
 #define __I_TIMER__
 
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <unistd.h>
+
 /****************************************************************************
  * Preprocessor Definitions
  ****************************************************************************/
diff --git a/interpreters/wamr/CMakeLists.txt b/interpreters/wamr/CMakeLists.txt
index 0803dc98e..c948bdc5b 100644
--- a/interpreters/wamr/CMakeLists.txt
+++ b/interpreters/wamr/CMakeLists.txt
@@ -58,6 +58,11 @@ if(CONFIG_INTERPRETERS_WAMR)
   include(${WAMR_DIR}/product-mini/platforms/nuttx/CMakeLists.txt)
   target_sources(wamr PRIVATE ${WAMR_SOURCES})
   target_compile_options(wamr PRIVATE ${WAMR_CFLAGS})
+
+  # The NuttX platform of older WAMR versions uses the pthread types without
+  # including pthread.h.
+
+  target_compile_options(wamr PRIVATE -include pthread.h)
   # the WAMR_INCDIRS and WAMR_DEFINITIONS already exist in the directory domain
   nuttx_add_application(
     MODULE
diff --git a/interpreters/wamr/Makefile b/interpreters/wamr/Makefile
index 4e78fa7bd..d7149952c 100644
--- a/interpreters/wamr/Makefile
+++ b/interpreters/wamr/Makefile
@@ -31,6 +31,11 @@ WAMR_URL      = $(WAMR_URL_BASE)/$(WAMR_TARBALL)
 
 -include $(WAMR_UNPACK)/product-mini/platforms/nuttx/wamr.mk
 
+# The NuttX platform of older WAMR versions uses the pthread types without
+# including pthread.h.
+
+CFLAGS += -include pthread.h
+
 VPATH += $(WAMR_UNPACK)/product-mini/platforms/nuttx
 DEPPATH += --dep-path $(WAMR_UNPACK)/product-mini/platforms/nuttx
 
diff --git a/lte/lapi/src/lapi_other.c b/lte/lapi/src/lapi_other.c
index 14a0734ec..1936a40dc 100644
--- a/lte/lapi/src/lapi_other.c
+++ b/lte/lapi/src/lapi_other.c
@@ -29,6 +29,7 @@
 #include <stdio.h>
 #include <stdint.h>
 #include <errno.h>
+#include <unistd.h>
 
 #include <sys/types.h>
 #include <sys/ioctl.h>
diff --git a/netutils/dhcpd/dhcpd.c b/netutils/dhcpd/dhcpd.c
index 61842ce26..e6b469bc8 100644
--- a/netutils/dhcpd/dhcpd.c
+++ b/netutils/dhcpd/dhcpd.c
@@ -57,6 +57,7 @@
 #include <unistd.h>
 #include <time.h>
 #include <errno.h>
+#include <stdlib.h>
 
 #include <net/if.h>
 #include <netinet/in.h>
diff --git a/netutils/netlib/netlib_ip6tables.c 
b/netutils/netlib/netlib_ip6tables.c
index 564de741b..cfc88335d 100644
--- a/netutils/netlib/netlib_ip6tables.c
+++ b/netutils/netlib/netlib_ip6tables.c
@@ -25,6 +25,7 @@
  ****************************************************************************/
 
 #include <nuttx/config.h>
+#include <stdlib.h>
 
 #include <sys/socket.h>
 
diff --git a/netutils/netlib/netlib_iptables.c 
b/netutils/netlib/netlib_iptables.c
index 887c45f36..5bf2aab41 100644
--- a/netutils/netlib/netlib_iptables.c
+++ b/netutils/netlib/netlib_iptables.c
@@ -25,6 +25,7 @@
  ****************************************************************************/
 
 #include <nuttx/config.h>
+#include <stdlib.h>
 
 #include <sys/socket.h>
 
diff --git a/netutils/plcatool/plcatool.c b/netutils/plcatool/plcatool.c
index 90edf2b57..75a768b45 100644
--- a/netutils/plcatool/plcatool.c
+++ b/netutils/plcatool/plcatool.c
@@ -30,6 +30,7 @@
 #include <stdlib.h>
 #include <stdint.h>
 #include <string.h>
+#include <unistd.h>
 #include <errno.h>
 
 #include <net/if.h>
diff --git a/system/adcscope/adcscope_main.c b/system/adcscope/adcscope_main.c
index 991a756ca..aada30324 100644
--- a/system/adcscope/adcscope_main.c
+++ b/system/adcscope/adcscope_main.c
@@ -32,6 +32,7 @@
 #include <stdio.h>
 #include <unistd.h>
 #include <fcntl.h>
+#include <stdlib.h>
 
 #include <nuttx/analog/adc.h>
 #include <nuttx/analog/ioctl.h>
diff --git a/system/iptables/ip6tables.c b/system/iptables/ip6tables.c
index e15e26685..7702985b2 100644
--- a/system/iptables/ip6tables.c
+++ b/system/iptables/ip6tables.c
@@ -25,6 +25,7 @@
  ****************************************************************************/
 
 #include <nuttx/config.h>
+#include <stdlib.h>
 
 #include <arpa/inet.h>
 
diff --git a/system/iptables/iptables.c b/system/iptables/iptables.c
index ad0eec099..8ec7feb86 100644
--- a/system/iptables/iptables.c
+++ b/system/iptables/iptables.c
@@ -27,6 +27,7 @@
 #include <nuttx/config.h>
 
 #include <fcntl.h>
+#include <stdlib.h>
 #include <arpa/inet.h>
 
 #include <nuttx/net/netfilter/ip_tables.h>
diff --git a/system/nxdiag/nxdiag.c b/system/nxdiag/nxdiag.c
index 062cc8f56..dbdd476f5 100644
--- a/system/nxdiag/nxdiag.c
+++ b/system/nxdiag/nxdiag.c
@@ -36,6 +36,7 @@
 #include "sysinfo.h"
 #ifdef CONFIG_SYSTEM_NXDIAG_ESPRESSIF_CHIP_WO_TOOL
 #include <fcntl.h>
+#include <stdlib.h>
 #endif
 
 /****************************************************************************
diff --git a/system/ofloader/ofloader.c b/system/ofloader/ofloader.c
index fe6ca12e3..dbe942d74 100644
--- a/system/ofloader/ofloader.c
+++ b/system/ofloader/ofloader.c
@@ -29,6 +29,8 @@
 #include <fcntl.h>
 #include <stdio.h>
 #include <mqueue.h>
+#include <pthread.h>
+#include <unistd.h>
 #include <sys/ioctl.h>
 #include <sys/boardctl.h>
 
diff --git a/system/sensorscope/sensorscope_main.c 
b/system/sensorscope/sensorscope_main.c
index ddccf1d87..77a25caa0 100644
--- a/system/sensorscope/sensorscope_main.c
+++ b/system/sensorscope/sensorscope_main.c
@@ -37,6 +37,7 @@
 #include <fcntl.h>
 #include <dirent.h>
 #include <libgen.h>
+#include <stdlib.h>
 
 #include <nuttx/sensors/sensor.h>
 
diff --git a/system/ymodem/rb_main.c b/system/ymodem/rb_main.c
index b282aa341..342b6d6ff 100644
--- a/system/ymodem/rb_main.c
+++ b/system/ymodem/rb_main.c
@@ -26,6 +26,7 @@
 
 #include <fcntl.h>
 #include <stdio.h>
+#include <stdlib.h>
 #include <getopt.h>
 #include <pthread.h>
 
diff --git a/system/ymodem/sb_main.c b/system/ymodem/sb_main.c
index 971dac4ac..c6ba3914a 100644
--- a/system/ymodem/sb_main.c
+++ b/system/ymodem/sb_main.c
@@ -26,6 +26,7 @@
 
 #include <fcntl.h>
 #include <stdio.h>
+#include <stdlib.h>
 #include <getopt.h>
 #include <libgen.h>
 #include <pthread.h>
diff --git a/system/zlib/CMakeLists.txt b/system/zlib/CMakeLists.txt
index 072134047..1a7bb24ae 100644
--- a/system/zlib/CMakeLists.txt
+++ b/system/zlib/CMakeLists.txt
@@ -43,6 +43,14 @@ if(CONFIG_LIB_ZLIB)
     if(NOT zlib_fetch_POPULATED)
       FetchContent_Populate(zlib_fetch)
     endif()
+
+    # Make zconf.h include unistd.h, as zlib's configure does on Unix: gzlib.c,
+    # gzread.c and gzwrite.c use lseek(), read() and write().
+
+    file(READ ${ZLIB_DIR}/zconf.h ZCONF)
+    string(REPLACE "#ifdef HAVE_UNISTD_H    /* may be set to #if 1 by"
+                   "#if 1    /* was set to #if 1 by" ZCONF "${ZCONF}")
+    file(WRITE ${ZLIB_DIR}/zconf.h "${ZCONF}")
   endif()
 
   # 
############################################################################
diff --git a/system/zlib/Makefile b/system/zlib/Makefile
index 43a09bb50..711f3bd2e 100644
--- a/system/zlib/Makefile
+++ b/system/zlib/Makefile
@@ -41,9 +41,14 @@ $(ZLIB_ZIP):
        @echo "Downloading: $(ZLIB_ZIP)"
        $(Q) curl -O -L 
https://github.com/madler/zlib/releases/download/v1.3/zlib13.zip
 
+# Make zconf.h include unistd.h, as zlib's configure does on Unix:
+# gzlib.c, gzread.c and gzwrite.c use lseek(), read() and write().
+
 $(ZLIB_SRC) : $(ZLIB_ZIP)
        unzip -o $(ZLIB_ZIP)
        mv zlib-1.3 $(ZLIB_SRC)
+       sed -i.orig "/^#ifdef HAVE_UNISTD_H.* may be/s/def HAVE_UNISTD_H\(.*\) 
may be/ 1\1 was/" $(ZLIB_SRC)/zconf.h
+       $(call DELFILE, $(ZLIB_SRC)/zconf.h.orig)
 
 context:: $(ZLIB_SRC)
 
diff --git a/testing/cmocka/cmocka_platform.h b/testing/cmocka/cmocka_platform.h
index 70d262500..d9ac969ea 100644
--- a/testing/cmocka/cmocka_platform.h
+++ b/testing/cmocka/cmocka_platform.h
@@ -28,6 +28,7 @@
  ****************************************************************************/
 
 #include <syslog.h>
+#include <unistd.h>
 
 /****************************************************************************
  * Pre-processor Definitions
diff --git a/testing/drivers/drivertest/drivertest_block.c 
b/testing/drivers/drivertest/drivertest_block.c
index 2a111ce93..86420c023 100644
--- a/testing/drivers/drivertest/drivertest_block.c
+++ b/testing/drivers/drivertest/drivertest_block.c
@@ -44,6 +44,8 @@
 #include <string.h>
 #include <fcntl.h>
 #include <cmocka.h>
+#include <unistd.h>
+#include <nuttx/kmalloc.h>
 
 #include "inode/inode.h"
 #include "driver/driver.h"
diff --git a/testing/drivers/drivertest/drivertest_i2c_spi.c 
b/testing/drivers/drivertest/drivertest_i2c_spi.c
index 7fc8a63d8..1049a79cc 100644
--- a/testing/drivers/drivertest/drivertest_i2c_spi.c
+++ b/testing/drivers/drivertest/drivertest_i2c_spi.c
@@ -38,6 +38,7 @@
 #include <nuttx/sensors/bmi160.h>
 
 #include <cmocka.h>
+#include <unistd.h>
 
 /****************************************************************************
  * Pre-processor Definitions
diff --git a/testing/drivers/drivertest/drivertest_pm_smp.c 
b/testing/drivers/drivertest/drivertest_pm_smp.c
index 0373301ca..3fd72d099 100644
--- a/testing/drivers/drivertest/drivertest_pm_smp.c
+++ b/testing/drivers/drivertest/drivertest_pm_smp.c
@@ -39,6 +39,7 @@
 #include <sys/param.h>
 #include <unistd.h>
 #include <pthread.h>
+#include <sched.h>
 
 /****************************************************************************
  * Pre-processor Definitions
diff --git a/testing/drivers/drivertest/drivertest_relay.c 
b/testing/drivers/drivertest/drivertest_relay.c
index adca1bb59..7257cbd4a 100644
--- a/testing/drivers/drivertest/drivertest_relay.c
+++ b/testing/drivers/drivertest/drivertest_relay.c
@@ -38,6 +38,7 @@
 #include <setjmp.h>
 #include <stdint.h>
 #include <cmocka.h>
+#include <unistd.h>
 
 /****************************************************************************
  * Private Types
diff --git a/testing/drivers/nand_sim/nand_sim_main.c 
b/testing/drivers/nand_sim/nand_sim_main.c
index 48ee969e5..0bc3ca133 100644
--- a/testing/drivers/nand_sim/nand_sim_main.c
+++ b/testing/drivers/nand_sim/nand_sim_main.c
@@ -27,12 +27,15 @@
 #include <nuttx/debug.h>
 #include <sched.h>
 #include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
 
 #include <nuttx/drivers/drivers.h>
 #include <nuttx/mtd/nand.h>
 #include <nuttx/mtd/nand_scheme.h>
 #include <nuttx/mtd/nand_ram.h>
 #include <nuttx/mtd/nand_wrapper.h>
+#include <nuttx/kmalloc.h>
 
 /****************************************************************************
  * Pre-processor Definitions
diff --git a/testing/drivers/pcitest/pcitest.c 
b/testing/drivers/pcitest/pcitest.c
index 79261b56f..3ba9f2e12 100644
--- a/testing/drivers/pcitest/pcitest.c
+++ b/testing/drivers/pcitest/pcitest.c
@@ -28,6 +28,7 @@
 #include <stdio.h>
 #include <unistd.h>
 #include <fcntl.h>
+#include <stdlib.h>
 #include <sys/ioctl.h>
 
 #include <nuttx/pci/pci_ep_test.h>
diff --git a/testing/drivers/ser/ser.c b/testing/drivers/ser/ser.c
index 00ed25bd0..20cac3d75 100644
--- a/testing/drivers/ser/ser.c
+++ b/testing/drivers/ser/ser.c
@@ -29,6 +29,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <unistd.h>
 #include <sys/ioctl.h>
 #include <nuttx/serial/serial.h>
 
diff --git a/testing/drivers/setest/setest.c b/testing/drivers/setest/setest.c
index 3fd66ff1a..ed2cb2b7f 100644
--- a/testing/drivers/setest/setest.c
+++ b/testing/drivers/setest/setest.c
@@ -32,6 +32,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <unistd.h>
 #include <sys/ioctl.h>
 
 /****************************************************************************
diff --git a/testing/fs/epoll/epoll.c b/testing/fs/epoll/epoll.c
index 8422c5fe7..206453f6b 100644
--- a/testing/fs/epoll/epoll.c
+++ b/testing/fs/epoll/epoll.c
@@ -40,6 +40,8 @@
 #include <setjmp.h>
 #include <stdint.h>
 #include <cmocka.h>
+#include <pthread.h>
+#include <unistd.h>
 
 /****************************************************************************
  * Pre-processor Definitions
diff --git a/testing/fs/fdsantest/fdsantest_simple.c 
b/testing/fs/fdsantest/fdsantest_simple.c
index a045fe7ff..4a9c7c133 100644
--- a/testing/fs/fdsantest/fdsantest_simple.c
+++ b/testing/fs/fdsantest/fdsantest_simple.c
@@ -28,6 +28,7 @@
 #include <fcntl.h>
 #include <stdio.h>
 #include <cmocka.h>
+#include <unistd.h>
 
 /****************************************************************************
  * Private Data
diff --git a/testing/fs/memfd/memfd_test.c b/testing/fs/memfd/memfd_test.c
index 1e72915bf..fdab7f26c 100644
--- a/testing/fs/memfd/memfd_test.c
+++ b/testing/fs/memfd/memfd_test.c
@@ -26,6 +26,8 @@
 #include <sys/mman.h>
 #include <fcntl.h>
 #include <stdio.h>
+#include <pthread.h>
+#include <unistd.h>
 
 /****************************************************************************
  * Pre-processor Definitions
diff --git a/testing/libc/atomic/atomic_main.c 
b/testing/libc/atomic/atomic_main.c
index a9348071b..5a2e45d88 100644
--- a/testing/libc/atomic/atomic_main.c
+++ b/testing/libc/atomic/atomic_main.c
@@ -27,6 +27,7 @@
 #include <nuttx/config.h>
 #include <stdio.h>
 #include <stdatomic.h>
+#include <nuttx/atomic.h>
 
 /****************************************************************************
  * Pre-processor Definitions
diff --git a/testing/mm/cachetest/cachetest_main.c 
b/testing/mm/cachetest/cachetest_main.c
index ddbf7951b..3f0db444e 100644
--- a/testing/mm/cachetest/cachetest_main.c
+++ b/testing/mm/cachetest/cachetest_main.c
@@ -29,6 +29,7 @@
 #include <stdio.h>
 #include <unistd.h>
 #include <syslog.h>
+#include <stdlib.h>
 
 /****************************************************************************
  * Pre-processor Definitions
diff --git a/testing/ostest/sched_thread_local.c 
b/testing/ostest/sched_thread_local.c
index f36d119da..9ab8bf169 100644
--- a/testing/ostest/sched_thread_local.c
+++ b/testing/ostest/sched_thread_local.c
@@ -32,6 +32,7 @@
 #include <stdint.h>
 #include <stdio.h>
 #include <string.h>
+#include <pthread.h>
 
 #include "ostest.h"
 
diff --git a/wireless/ieee802154/i8sak/i8sak.h 
b/wireless/ieee802154/i8sak/i8sak.h
index 385d2c1b9..b5f826e09 100644
--- a/wireless/ieee802154/i8sak/i8sak.h
+++ b/wireless/ieee802154/i8sak/i8sak.h
@@ -28,6 +28,7 @@
  ****************************************************************************/
 
 #include <nuttx/config.h>
+#include <pthread.h>
 
 #include <arpa/inet.h>
 #include <netinet/in.h>
diff --git a/wireless/ieee802154/i8sak/i8sak_acceptassoc.c 
b/wireless/ieee802154/i8sak/i8sak_acceptassoc.c
index beffea18f..69298d268 100644
--- a/wireless/ieee802154/i8sak/i8sak_acceptassoc.c
+++ b/wireless/ieee802154/i8sak/i8sak_acceptassoc.c
@@ -33,6 +33,7 @@
 #include <fcntl.h>
 #include <assert.h>
 #include <errno.h>
+#include <unistd.h>
 
 #include <nuttx/fs/ioctl.h>
 

Reply via email to