From 094a225363304dcbfcf920e069c8a8c4f6aaba47 Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Fri, 2 Dec 2022 19:46:31 +0100 Subject: [PATCH] Detect the posix unistd.h header file The getopt function is defined in the unistd.h header file. This header file is only available on posix compatible systems. For example, on Windows it's not available when building without mingw. --- configure.ac | 2 +- examples/dctool.c | 4 +++- examples/dctool_download.c | 4 +++- examples/dctool_dump.c | 4 +++- examples/dctool_fwupdate.c | 4 +++- examples/dctool_help.c | 4 +++- examples/dctool_list.c | 4 +++- examples/dctool_parse.c | 4 +++- examples/dctool_read.c | 4 +++- examples/dctool_scan.c | 4 +++- examples/dctool_timesync.c | 4 +++- examples/dctool_version.c | 4 +++- examples/dctool_write.c | 4 +++- 13 files changed, 37 insertions(+), 13 deletions(-) diff --git a/configure.ac b/configure.ac index 5dc1c63..32496f6 100644 --- a/configure.ac +++ b/configure.ac @@ -157,7 +157,7 @@ AC_CHECK_HEADERS([sys/socket.h linux/types.h linux/irda.h], , , [ # Checks for header files. AC_CHECK_HEADERS([linux/serial.h]) AC_CHECK_HEADERS([IOKit/serial/ioss.h]) -AC_CHECK_HEADERS([getopt.h]) +AC_CHECK_HEADERS([unistd.h getopt.h]) AC_CHECK_HEADERS([sys/param.h]) AC_CHECK_HEADERS([pthread.h]) AC_CHECK_HEADERS([mach/mach_time.h]) diff --git a/examples/dctool.c b/examples/dctool.c index 3104bc4..9d3f74b 100644 --- a/examples/dctool.c +++ b/examples/dctool.c @@ -24,10 +24,12 @@ #endif #include -#include #include #include #include +#ifdef HAVE_UNISTD_H +#include +#endif #ifdef HAVE_GETOPT_H #include #endif diff --git a/examples/dctool_download.c b/examples/dctool_download.c index 2a39f5f..04aedcf 100644 --- a/examples/dctool_download.c +++ b/examples/dctool_download.c @@ -24,9 +24,11 @@ #endif #include -#include #include #include +#ifdef HAVE_UNISTD_H +#include +#endif #ifdef HAVE_GETOPT_H #include #endif diff --git a/examples/dctool_dump.c b/examples/dctool_dump.c index 6aa2e4a..966edbc 100644 --- a/examples/dctool_dump.c +++ b/examples/dctool_dump.c @@ -24,9 +24,11 @@ #endif #include -#include #include #include +#ifdef HAVE_UNISTD_H +#include +#endif #ifdef HAVE_GETOPT_H #include #endif diff --git a/examples/dctool_fwupdate.c b/examples/dctool_fwupdate.c index 596ccb1..4395c39 100644 --- a/examples/dctool_fwupdate.c +++ b/examples/dctool_fwupdate.c @@ -24,8 +24,10 @@ #endif #include -#include #include +#ifdef HAVE_UNISTD_H +#include +#endif #ifdef HAVE_GETOPT_H #include #endif diff --git a/examples/dctool_help.c b/examples/dctool_help.c index 2848c24..33ea0a5 100644 --- a/examples/dctool_help.c +++ b/examples/dctool_help.c @@ -24,8 +24,10 @@ #endif #include -#include #include +#ifdef HAVE_UNISTD_H +#include +#endif #ifdef HAVE_GETOPT_H #include #endif diff --git a/examples/dctool_list.c b/examples/dctool_list.c index 89e5386..bc70d13 100644 --- a/examples/dctool_list.c +++ b/examples/dctool_list.c @@ -24,8 +24,10 @@ #endif #include -#include #include +#ifdef HAVE_UNISTD_H +#include +#endif #ifdef HAVE_GETOPT_H #include #endif diff --git a/examples/dctool_parse.c b/examples/dctool_parse.c index 6b7da08..b898b5c 100644 --- a/examples/dctool_parse.c +++ b/examples/dctool_parse.c @@ -24,9 +24,11 @@ #endif #include -#include #include #include +#ifdef HAVE_UNISTD_H +#include +#endif #ifdef HAVE_GETOPT_H #include #endif diff --git a/examples/dctool_read.c b/examples/dctool_read.c index 2a9bf18..31ffc8d 100644 --- a/examples/dctool_read.c +++ b/examples/dctool_read.c @@ -24,8 +24,10 @@ #endif #include -#include #include +#ifdef HAVE_UNISTD_H +#include +#endif #ifdef HAVE_GETOPT_H #include #endif diff --git a/examples/dctool_scan.c b/examples/dctool_scan.c index 868a9a7..378a8f8 100644 --- a/examples/dctool_scan.c +++ b/examples/dctool_scan.c @@ -24,8 +24,10 @@ #endif #include -#include #include +#ifdef HAVE_UNISTD_H +#include +#endif #ifdef HAVE_GETOPT_H #include #endif diff --git a/examples/dctool_timesync.c b/examples/dctool_timesync.c index 35647b1..eeff0bb 100644 --- a/examples/dctool_timesync.c +++ b/examples/dctool_timesync.c @@ -24,8 +24,10 @@ #endif #include -#include #include +#ifdef HAVE_UNISTD_H +#include +#endif #ifdef HAVE_GETOPT_H #include #endif diff --git a/examples/dctool_version.c b/examples/dctool_version.c index deb0702..dbb7a40 100644 --- a/examples/dctool_version.c +++ b/examples/dctool_version.c @@ -24,8 +24,10 @@ #endif #include -#include #include +#ifdef HAVE_UNISTD_H +#include +#endif #ifdef HAVE_GETOPT_H #include #endif diff --git a/examples/dctool_write.c b/examples/dctool_write.c index fc76c78..04db198 100644 --- a/examples/dctool_write.c +++ b/examples/dctool_write.c @@ -24,8 +24,10 @@ #endif #include -#include #include +#ifdef HAVE_UNISTD_H +#include +#endif #ifdef HAVE_GETOPT_H #include #endif