Code portability cleanup.
authorJon A. Cruz <jonc@osg.samsung.com>
Mon, 23 Mar 2015 07:13:15 +0000 (00:13 -0700)
committerErich Keane <erich.keane@intel.com>
Thu, 26 Mar 2015 16:56:32 +0000 (16:56 +0000)
Added required #includes and #defines to allow the code to be compiled without
errors in more situations.

Fixed platform and compiler assumptions that would prevent the code from
compiling successfully under different compilers and platforms. This helps
with building with different compilers or even later versions of current ones.

Added comments documenting resons for the #defines and portability info.

Change-Id: Ia4a943af1d2d06509e46669f952b5e7ca80efaf4
Signed-off-by: Jon A. Cruz <jonc@osg.samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/532
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Joseph Morrow <joseph.l.morrow@intel.com>
Reviewed-by: Erich Keane <erich.keane@intel.com>
19 files changed:
build_common/android/SConscript
build_common/linux/SConscript
resource/csdk/connectivity/src/caprotocolmessage.c
resource/csdk/connectivity/src/caretransmission.c
resource/csdk/connectivity/src/ethernet_adapter/linux/caethernetclient.c
resource/csdk/connectivity/src/ethernet_adapter/linux/caethernetnwmonitor.c
resource/csdk/connectivity/src/ethernet_adapter/linux/caethernetserver.c
resource/csdk/connectivity/src/wifi_adapter/linux/cawificlient.c
resource/csdk/connectivity/src/wifi_adapter/linux/cawifinwmonitor.c
resource/csdk/connectivity/src/wifi_adapter/linux/cawifiserver.c
service/protocol-plugin/lib/cpluff/libcpluff/pcontrol.c
service/protocol-plugin/lib/cpluff/libcpluff/ploader.c
service/protocol-plugin/lib/cpluff/libcpluff/pscan.c
service/protocol-plugin/lib/cpluff/libcpluff/psymbol.c
service/protocol-plugin/plugins/mqtt-fan/lib/memory_mosq.c
service/protocol-plugin/plugins/mqtt-fan/lib/mosquitto.c
service/protocol-plugin/plugins/mqtt-fan/lib/net_mosq.c
service/protocol-plugin/plugins/mqtt-fan/lib/time_mosq.c
service/protocol-plugin/plugins/mqtt-fan/lib/tls_mosq.c

index be49aee..5cc203d 100644 (file)
@@ -45,6 +45,7 @@ elif platform.system().lower() == 'darwin':
 
 # Android build system default cofig
 env.AppendUnique(CPPDEFINES = ['ANDROID'])
+env.AppendUnique(CFLAGS = ['-std=c99'])
 env.AppendUnique(SHCFLAGS = ['-Wa,--noexecstack'])
 env.AppendUnique(LINKFLAGS = ['-Wl,--gc-sections', '-Wl,-z,nocopyreloc'])
 
index 57d93bd..c980107 100644 (file)
@@ -15,6 +15,7 @@ else:
        env.AppendUnique(CPPDEFINES = ['-DTB_LOG'])
 
 env.AppendUnique(CPPDEFINES = ['WITH_POSIX', '__linux__'])
+env.AppendUnique(CFLAGS = ['-std=c99'])
 env.AppendUnique(CCFLAGS = ['-Wall', '-fPIC'])
 env.AppendUnique(LINKFLAGS = ['-ldl', '-lpthread'])
 
index 1520979..1a35c33 100644 (file)
  *
  ******************************************************************/
 
+// Defining _BSD_SOURCE or _DEFAULT_SOURCE causes header files to expose
+// definitions that may otherwise be skipped. Skipping can cause implicit
+// declaration warnings and/or bugs and subtle problems in code execution.
+// For glibc information on feature test macros,
+// Refer http://www.gnu.org/software/libc/manual/html_node/Feature-Test-Macros.html
+//
+// This file requires #define use due to random() and srandom()
+// For details on compatibility and glibc support,
+// Refer http://www.gnu.org/software/libc/manual/html_node/BSD-Random.html
+#define _DEFAULT_SOURCE
+#define _BSD_SOURCE
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
index 48b2cfa..e222d08 100644 (file)
  *
  ******************************************************************/
 
+// Defining _BSD_SOURCE or _DEFAULT_SOURCE causes header files to expose
+// definitions that may otherwise be skipped. Skipping can cause implicit
+// declaration warnings and/or bugs and subtle problems in code execution.
+// For glibc information on feature test macros,
+// Refer http://www.gnu.org/software/libc/manual/html_node/Feature-Test-Macros.html
+//
+// This file requires #define use due to random()
+// For details on compatibility and glibc support,
+// Refer http://www.gnu.org/software/libc/manual/html_node/BSD-Random.html
+#define _DEFAULT_SOURCE
+#define _BSD_SOURCE
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
index 2c32028..c34437d 100644 (file)
 * limitations under the License.
 *
 ******************************************************************/
+
+// Defining _BSD_SOURCE or _DEFAULT_SOURCE causes header files to expose
+// definitions that may otherwise be skipped. Skipping can cause implicit
+// declaration warnings and/or bugs and subtle problems in code execution.
+// For glibc information on feature test macros,
+// Refer http://www.gnu.org/software/libc/manual/html_node/Feature-Test-Macros.html
+//
+// This file requires #define use due to inet_aton
+// For details on compatibility support,
+// Refer http://man7.org/linux/man-pages/man3/inet.3.html
+#define _DEFAULT_SOURCE
+#define _BSD_SOURCE
+
 #include "caethernetinterface.h"
 
 #include <sys/types.h>
index 2127de9..ca6d556 100644 (file)
 *
 ******************************************************************/
 
+// Defining _POSIX_C_SOURCE macro with 200809L (or greater) as value
+// causes header files to expose definitions
+// corresponding to the POSIX.1-2008 base
+// specification (excluding the XSI extension).
+// For POSIX.1-2008 base specification,
+// Refer http://pubs.opengroup.org/stage7tc1/
+//
+// For this specific file, see use of strndup,
+// Refer http://man7.org/linux/man-pages/man3/strdup.3.html
+#ifndef _POSIX_C_SOURCE
+#define _POSIX_C_SOURCE 200809L
+#endif
+
+// Defining _BSD_SOURCE or _DEFAULT_SOURCE causes header files to expose
+// definitions that may otherwise be skipped. Skipping can cause implicit
+// declaration warnings and/or bugs and subtle problems in code execution.
+// For glibc information on feature test macros,
+// Refer http://www.gnu.org/software/libc/manual/html_node/Feature-Test-Macros.html
+//
+// This file requires #define use due to IFF_LOOPBACK
+#define _DEFAULT_SOURCE
+#define _BSD_SOURCE
+#include <net/if.h>
+
 #include "caethernetinterface.h"
 
 #include <sys/types.h>
 #include <ifaddrs.h>
-#include <net/if.h>
 #include <sys/socket.h>
 #include <netdb.h>
 #include <string.h>
+#include <strings.h>
 #include <errno.h>
 
 #include "caadapterutils.h"
index cd5fcc8..0b248f2 100644 (file)
 * limitations under the License.
 *
 ******************************************************************/
+
+// Defining _POSIX_C_SOURCE macro with 200809L (or greater) as value
+// causes header files to expose definitions
+// corresponding to the POSIX.1-2008 base
+// specification (excluding the XSI extension).
+// For POSIX.1-2008 base specification,
+// Refer http://pubs.opengroup.org/stage7tc1/
+//
+// For this specific file, see use of strndup,
+// Refer http://man7.org/linux/man-pages/man3/strdup.3.html
+#ifndef _POSIX_C_SOURCE
+#define _POSIX_C_SOURCE 200809L
+#endif
+
+// Defining _BSD_SOURCE or _DEFAULT_SOURCE causes header files to expose
+// definitions that may otherwise be skipped. Skipping can cause implicit
+// declaration warnings and/or bugs and subtle problems in code execution.
+// For glibc information on feature test macros,
+// Refer http://www.gnu.org/software/libc/manual/html_node/Feature-Test-Macros.html
+//
+// This file requires #define use due to struct ip_mreq
+#define _DEFAULT_SOURCE
+#define _BSD_SOURCE
+#include <netinet/in.h>
+
 #include "caethernetinterface.h"
 
 #include <sys/types.h>
@@ -25,7 +50,8 @@
 #include <fcntl.h>
 #include <sys/select.h>
 #include <arpa/inet.h>
-#include <netinet/in.h>
+#include <string.h>
+
 #include <errno.h>
 
 #include "pdu.h"
index 891036e..ac115fb 100644 (file)
 * limitations under the License.
 *
 ******************************************************************/
+
+// Defining _BSD_SOURCE or _DEFAULT_SOURCE causes header files to expose
+// definitions that may otherwise be skipped. Skipping can cause implicit
+// declaration warnings and/or bugs and subtle problems in code execution.
+// For glibc information on feature test macros,
+// Refer http://www.gnu.org/software/libc/manual/html_node/Feature-Test-Macros.html
+//
+// This file requires #define use due to random() and inet_aton()
+// For details on compatibility and glibc support,
+// Refer http://man7.org/linux/man-pages/man3/inet.3.html
+// Refer http://man7.org/linux/man-pages/man3/random.3.html
+#define _DEFAULT_SOURCE
+#define _BSD_SOURCE
+
 #include "cawifiinterface.h"
 
 #include <sys/types.h>
index 8f76ac9..9d14ce2 100644 (file)
 *
 ******************************************************************/
 
+// Defining _POSIX_C_SOURCE macro with 200809L (or greater) as value
+// causes header files to expose definitions
+// corresponding to the POSIX.1-2008 base
+// specification (excluding the XSI extension).
+// For POSIX.1-2008 base specification,
+// Refer http://pubs.opengroup.org/stage7tc1/
+//
+// For this specific file, see use of strndup,
+// Refer http://man7.org/linux/man-pages/man3/strdup.3.html
+#ifndef _POSIX_C_SOURCE
+#define _POSIX_C_SOURCE 200809L
+#endif
+
+// Defining _BSD_SOURCE or _DEFAULT_SOURCE causes header files to expose
+// definitions that may otherwise be skipped. Skipping can cause implicit
+// declaration warnings and/or bugs and subtle problems in code execution.
+// For glibc information on feature test macros,
+// Refer http://www.gnu.org/software/libc/manual/html_node/Feature-Test-Macros.html
+//
+// This file requires #define use due to IFF_LOOPBACK
+#define _DEFAULT_SOURCE
+#define _BSD_SOURCE
+#include <net/if.h>
+
 #include "cawifiinterface.h"
 
 #include <sys/types.h>
index 11d648c..af86401 100644 (file)
  * limitations under the License.
  *
  ******************************************************************/
+
+// Defining _POSIX_C_SOURCE macro with 200809L (or greater) as value
+// causes header files to expose definitions
+// corresponding to the POSIX.1-2008 base
+// specification (excluding the XSI extension).
+// For POSIX.1-2008 base specification,
+// Refer http://pubs.opengroup.org/stage7tc1/
+//
+// For this specific file, see use of strndup,
+// Refer http://man7.org/linux/man-pages/man3/strdup.3.html
+#ifndef _POSIX_C_SOURCE
+#define _POSIX_C_SOURCE 200809L
+#endif
+
+// Defining _BSD_SOURCE or _DEFAULT_SOURCE causes header files to expose
+// definitions that may otherwise be skipped. Skipping can cause implicit
+// declaration warnings and/or bugs and subtle problems in code execution.
+// For glibc information on feature test macros,
+// Refer http://www.gnu.org/software/libc/manual/html_node/Feature-Test-Macros.html
+//
+// This file requires #define use due to struct ip_mreq
+#define _DEFAULT_SOURCE
+#define _BSD_SOURCE
+#include <netinet/in.h>
+
 #include "cawifiinterface.h"
 
 #include <sys/types.h>
index 83a24cb..e3ac85b 100644 (file)
 #include "config.h"
 #endif
 
+#ifdef __linux__
+// Defining _POSIX_C_SOURCE macro with 200809L (or greater) as value
+// causes header files to expose definitions
+// corresponding to the POSIX.1-2008 base
+// specification (excluding the XSI extension).
+// For POSIX.1-2008 base specification,
+// Refer http://pubs.opengroup.org/stage7tc1/
+//
+// For this specific file, see use of strndup,
+// Refer http://man7.org/linux/man-pages/man3/strdup.3.html
+#ifndef _POSIX_C_SOURCE
+#define _POSIX_C_SOURCE 200809L
+#endif
+#endif
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <assert.h>
index b700569..b12df64 100644 (file)
  * Plug-in descriptor loader
  */
 
+#ifdef __linux__
+#ifndef _POSIX_C_SOURCE
+// Defining _POSIX_C_SOURCE macro with 200809L (or greater) as value
+// causes header files to expose definitions
+// corresponding to the POSIX.1-2008 base
+// specification (excluding the XSI extension).
+// For POSIX.1-2008 base specification,
+// Refer http://pubs.opengroup.org/stage7tc1/
+//
+// For this specific file, see use of strndup,
+// Refer http://man7.org/linux/man-pages/man3/strdup.3.html
+#define _POSIX_C_SOURCE 200809L
+#endif
+#endif
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
index 38b3297..b7d5a6f 100644 (file)
  * Plug-in scanning functionality
  */
 
+#ifdef __linux__
+#ifndef _POSIX_C_SOURCE
+// Defining _POSIX_C_SOURCE macro with 200809L (or greater) as value
+// causes header files to expose definitions
+// corresponding to the POSIX.1-2008 base
+// specification (excluding the XSI extension).
+// For POSIX.1-2008 base specification,
+// Refer http://pubs.opengroup.org/stage7tc1/
+//
+// For this specific file, see use of strndup,
+// Refer http://man7.org/linux/man-pages/man3/strdup.3.html
+#define _POSIX_C_SOURCE 200809L
+#endif
+#endif
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
index a2bca4a..6338d0d 100644 (file)
  * Dynamic plug-in symbols
  */
 
+#ifdef __linux__
+#ifndef _POSIX_C_SOURCE
+// Defining _POSIX_C_SOURCE macro with 200809L (or greater) as value
+// causes header files to expose definitions
+// corresponding to the POSIX.1-2008 base
+// specification (excluding the XSI extension).
+// For POSIX.1-2008 base specification,
+// Refer http://pubs.opengroup.org/stage7tc1/
+//
+// For this specific file, see use of strndup,
+// Refer http://man7.org/linux/man-pages/man3/strdup.3.html
+#define _POSIX_C_SOURCE 200809L
+#endif
+#endif
+
 #include <stdlib.h>
 #include <string.h>
 #include <assert.h>
index 199455e..3e3de97 100644 (file)
@@ -27,6 +27,19 @@ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 POSSIBILITY OF SUCH DAMAGE.
 */
 
+#ifndef _POSIX_C_SOURCE
+// Defining _POSIX_C_SOURCE macro with 200809L (or greater) as value
+// causes header files to expose definitions
+// corresponding to the POSIX.1-2008 base
+// specification (excluding the XSI extension).
+// For POSIX.1-2008 base specification,
+// Refer http://pubs.opengroup.org/stage7tc1/
+//
+// For this specific file, see use of strndup,
+// Refer http://man7.org/linux/man-pages/man3/strdup.3.html
+#define _POSIX_C_SOURCE 200809L
+#endif
+
 #include "config.h"
 
 #include <stdlib.h>
index 7f94dea..a25c777 100644 (file)
@@ -27,11 +27,25 @@ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 POSSIBILITY OF SUCH DAMAGE.
 */
 
+#ifndef _POSIX_C_SOURCE
+// Defining _POSIX_C_SOURCE macro with 200112L (or greater) as value
+// causes header files to expose definitions
+// corresponding to the POSIX.1-2001 base
+// specification (excluding the XSI extension).
+// For POSIX.1-2001 base specification,
+// Refer http://pubs.opengroup.org/onlinepubs/009695399/
+//
+// For this specific file, see use of pselect,
+// Refer http://man7.org/linux/man-pages/man2/select.2.html
+#define _POSIX_C_SOURCE 200112L // Needed for pselect
+#endif
+
 #include <assert.h>
 #include <errno.h>
 #include <signal.h>
 #include <stdio.h>
 #include <string.h>
+#include <strings.h>
 #ifndef WIN32
 #include <sys/select.h>
 #include <sys/time.h>
index 517a485..4329e3c 100644 (file)
@@ -27,6 +27,19 @@ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 POSSIBILITY OF SUCH DAMAGE.
 */
 
+#ifndef _POSIX_C_SOURCE
+// Defining _POSIX_C_SOURCE macro with 200112L (or greater) as value
+// causes header files to expose definitions
+// corresponding to the POSIX.1-2001 base
+// specification (excluding the XSI extension).
+// For POSIX.1-2001 base specification,
+// Refer http://pubs.opengroup.org/onlinepubs/009695399/
+//
+// For this specific file, see use of getaddrinfo & structs,
+// Refer http://man7.org/linux/man-pages/man3/getaddrinfo.3.html
+#define _POSIX_C_SOURCE 200112L // needed for getaddrinfo & structs
+#endif
+
 #include <assert.h>
 #include <errno.h>
 #include <fcntl.h>
index 9d2e499..91c9602 100644 (file)
@@ -27,6 +27,17 @@ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 POSSIBILITY OF SUCH DAMAGE.
 */
 
+#ifndef _POSIX_C_SOURCE
+// Defining _POSIX_C_SOURCE macro with 199309L (or greater) as value
+// causes header files to expose definitions
+// corresponding to the POSIX.1b, Real-time extensions
+// (IEEE Std 1003.1b-1993) specification
+//
+// For this specific file, see use of clock_gettime,
+// Refer http://man7.org/linux/man-pages/man2/clock_gettime.2.html
+#define _POSIX_C_SOURCE 199309L // needed for clock_gettime
+#endif
+
 #ifdef __APPLE__
 #include <mach/mach.h>
 #include <mach/mach_time.h>
index 362c015..2959e4c 100644 (file)
@@ -37,6 +37,7 @@ POSSIBILITY OF SUCH DAMAGE.
 #endif
 
 #include <string.h>
+#include <strings.h>
 #include <openssl/conf.h>
 #include <openssl/x509v3.h>
 #include <openssl/ssl.h>