From 8ef1f35ca71e39d40bdae88243534eebc6fa6a26 Mon Sep 17 00:00:00 2001 From: David Zero Date: Fri, 6 Jan 2017 04:19:12 -0800 Subject: Revert "Revert "Portability fixes"" This reverts commit 59e2a844f04a8725e8079f854158aa86ef5988b2, and defines _DARWIN_C_SOURCE in toxcore/network.c --- .gitignore | 8 ++++++-- CMakeLists.txt | 15 +++++++-------- auto_tests/TCP_test.c | 2 ++ auto_tests/conference_test.c | 8 +++++--- auto_tests/dht_test.c | 2 ++ auto_tests/network_test.c | 4 ++-- auto_tests/onion_test.c | 2 ++ auto_tests/save_friend_test.c | 3 +++ auto_tests/tox_many_tcp_test.c | 2 ++ auto_tests/tox_many_test.c | 2 ++ auto_tests/tox_test.c | 2 ++ auto_tests/toxav_basic_test.c | 2 ++ auto_tests/toxav_many_test.c | 2 ++ other/DHT_bootstrap.c | 2 ++ other/bootstrap_daemon/src/log.c | 19 +++++++++++++++++-- other/bootstrap_daemon/src/tox-bootstrapd.c | 2 ++ testing/DHT_test.c | 2 ++ testing/Messenger_test.c | 2 ++ testing/av_test.c | 2 ++ testing/irc_syncbot.c | 9 +++++---- testing/misc_tools.c | 1 + testing/tox_shell.c | 2 ++ testing/tox_sync.c | 11 ++++++++++- toxcore/TCP_server.c | 4 ++-- toxcore/network.c | 3 +++ toxcore/tox.c | 2 ++ toxcore/util.c | 2 ++ 27 files changed, 93 insertions(+), 24 deletions(-) diff --git a/.gitignore b/.gitignore index 2a82d308..14dcced7 100644 --- a/.gitignore +++ b/.gitignore @@ -21,6 +21,9 @@ install_manifest.txt tags Makefile.in CMakeLists.txt.user +DartConfiguration.tcl +CTestTestfile.cmake +*.pc # Testing testing/data @@ -40,6 +43,9 @@ testing/data *.app *.la +# Libraries +*.so + # Misc (?) m4/* configure @@ -51,8 +57,6 @@ config.log config.status stamp-h1 autom4te.cache -libtoxcore.pc -libtoxav.pc libtool .deps .libs diff --git a/CMakeLists.txt b/CMakeLists.txt index 77d871af..591dadb3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -56,22 +56,21 @@ macro(add_flag flag) add_cflag(${flag}) add_cxxflag(${flag}) endmacro() + +# Set standard version for compiler. +add_cflag("-std=c99") +add_cxxflag("-std=c++11") + +# Error on non-ISO C. +add_cflag("-pedantic-errors") option(WARNINGS "Enable additional compiler warnings" ON) if(WARNINGS) - # Set standard version for compiler. - add_cflag("-std=gnu99") - add_cxxflag("-std=c++98") - # Add all warning flags we can. add_flag("-Wall") add_flag("-Wextra") add_flag("-Weverything") - # -pedantic only for C, because in C++ we want to allow the GNU/C99 extension - # of having a comma at the end of an enumerator list. - add_cflag("-pedantic") - # Disable specific warning flags for both C and C++. add_flag("-Wno-cast-align") add_flag("-Wno-conversion") diff --git a/auto_tests/TCP_test.c b/auto_tests/TCP_test.c index d9013378..6a439261 100644 --- a/auto_tests/TCP_test.c +++ b/auto_tests/TCP_test.c @@ -1,3 +1,5 @@ +#define _XOPEN_SOURCE 600 + #ifdef HAVE_CONFIG_H #include "config.h" #endif diff --git a/auto_tests/conference_test.c b/auto_tests/conference_test.c index aa2f8e13..36707e0f 100644 --- a/auto_tests/conference_test.c +++ b/auto_tests/conference_test.c @@ -1,6 +1,8 @@ /* Auto Tests: Conferences. */ +#define _XOPEN_SOURCE 600 + #ifdef HAVE_CONFIG_H #include "config.h" #endif @@ -175,7 +177,7 @@ group_test_restart: * Either way in this case it's fine */ if (peer_count != NUM_GROUP_TOX) { ++test_run; - printf("\tError starting up the first group (peer_count %"PRIu32" != %d, test_run = %d)\n", peer_count, NUM_GROUP_TOX, + printf("\tError starting up the first group (peer_count %" PRIu32 " != %d, test_run = %d)\n", peer_count, NUM_GROUP_TOX, test_run); for (j = 0; j < NUM_GROUP_TOX; ++j) { @@ -194,7 +196,7 @@ group_test_restart: * important again. */ ck_assert_msg(peer_count == NUM_GROUP_TOX, "\n\tBad number of group peers (pre check)." - "\n\t\t\tExpected: %u but tox_instance(%u) only has: %"PRIu32"\n\n", + "\n\t\t\tExpected: %u but tox_instance(%u) only has: %" PRIu32 "\n\n", NUM_GROUP_TOX, i, peer_count); uint8_t title[2048]; @@ -241,7 +243,7 @@ group_test_restart: for (i = 0; i < (k - 1); ++i) { uint32_t peer_count = tox_conference_peer_count(toxes[i], 0, NULL); ck_assert_msg(peer_count == (k - 1), "\n\tBad number of group peers (post check)." - "\n\t\t\tExpected: %u but tox_instance(%u) only has: %"PRIu32"\n\n", + "\n\t\t\tExpected: %u but tox_instance(%u) only has: %" PRIu32 "\n\n", (k - 1), i, peer_count); } } diff --git a/auto_tests/dht_test.c b/auto_tests/dht_test.c index 9cec1643..633e7002 100644 --- a/auto_tests/dht_test.c +++ b/auto_tests/dht_test.c @@ -1,3 +1,5 @@ +#define _XOPEN_SOURCE 600 + #ifdef HAVE_CONFIG_H #include "config.h" #endif diff --git a/auto_tests/network_test.c b/auto_tests/network_test.c index 783f3f7b..ca918778 100644 --- a/auto_tests/network_test.c +++ b/auto_tests/network_test.c @@ -114,8 +114,8 @@ START_TEST(test_ip_equal) ip2.ip6.uint32[2] = htonl(0xFFFF); ip2.ip6.uint32[3] = htonl(0x7F000001); - ck_assert_msg(IN6_IS_ADDR_V4MAPPED(&ip2.ip6.in6_addr) != 0, - "IN6_IS_ADDR_V4MAPPED(::ffff:127.0.0.1): expected != 0, got 0."); + ck_assert_msg(IPV6_IPV4_IN_V6(ip2.ip6) != 0, + "IPV6_IPV4_IN_V6(::ffff:127.0.0.1): expected != 0, got 0."); res = ip_equal(&ip1, &ip2); ck_assert_msg(res != 0, "ip_equal( {AF_INET, 127.0.0.1}, {AF_INET6, ::ffff:127.0.0.1} ): expected result != 0, got 0."); diff --git a/auto_tests/onion_test.c b/auto_tests/onion_test.c index 44ea9c7d..05264927 100644 --- a/auto_tests/onion_test.c +++ b/auto_tests/onion_test.c @@ -1,3 +1,5 @@ +#define _XOPEN_SOURCE 600 + #ifdef HAVE_CONFIG_H #include "config.h" #endif diff --git a/auto_tests/save_friend_test.c b/auto_tests/save_friend_test.c index 9d36ff2d..448160c0 100644 --- a/auto_tests/save_friend_test.c +++ b/auto_tests/save_friend_test.c @@ -1,7 +1,10 @@ /* Auto Tests: Save and load friends. */ +#define _XOPEN_SOURCE 600 + #include "helpers.h" +#include "../toxcore/tox.h" #include #include diff --git a/auto_tests/tox_many_tcp_test.c b/auto_tests/tox_many_tcp_test.c index 197c6e47..48f5671c 100644 --- a/auto_tests/tox_many_tcp_test.c +++ b/auto_tests/tox_many_tcp_test.c @@ -1,6 +1,8 @@ /* Auto Tests: Many TCP. */ +#define _XOPEN_SOURCE 600 + #ifdef HAVE_CONFIG_H #include "config.h" #endif diff --git a/auto_tests/tox_many_test.c b/auto_tests/tox_many_test.c index 0c4c8c7d..b44bbb0c 100644 --- a/auto_tests/tox_many_test.c +++ b/auto_tests/tox_many_test.c @@ -1,6 +1,8 @@ /* Auto Tests: Many clients. */ +#define _XOPEN_SOURCE 600 + #ifdef HAVE_CONFIG_H #include "config.h" #endif diff --git a/auto_tests/tox_test.c b/auto_tests/tox_test.c index dfd1d80a..ab2202d1 100644 --- a/auto_tests/tox_test.c +++ b/auto_tests/tox_test.c @@ -10,6 +10,8 @@ * */ +#define _XOPEN_SOURCE 600 + #ifdef HAVE_CONFIG_H #include "config.h" #endif diff --git a/auto_tests/toxav_basic_test.c b/auto_tests/toxav_basic_test.c index 767fca87..79f552de 100644 --- a/auto_tests/toxav_basic_test.c +++ b/auto_tests/toxav_basic_test.c @@ -1,3 +1,5 @@ +#define _XOPEN_SOURCE 600 + #ifdef HAVE_CONFIG_H #include "config.h" #endif diff --git a/auto_tests/toxav_many_test.c b/auto_tests/toxav_many_test.c index b33b93c8..1a10db44 100644 --- a/auto_tests/toxav_many_test.c +++ b/auto_tests/toxav_many_test.c @@ -1,3 +1,5 @@ +#define _XOPEN_SOURCE 600 + #ifdef HAVE_CONFIG_H #include "config.h" #endif diff --git a/other/DHT_bootstrap.c b/other/DHT_bootstrap.c index e056de41..fa71d920 100644 --- a/other/DHT_bootstrap.c +++ b/other/DHT_bootstrap.c @@ -22,6 +22,8 @@ * */ +#define _XOPEN_SOURCE 600 + #ifdef HAVE_CONFIG_H #include "config.h" #endif diff --git a/other/bootstrap_daemon/src/log.c b/other/bootstrap_daemon/src/log.c index 7632d739..ae418f93 100644 --- a/other/bootstrap_daemon/src/log.c +++ b/other/bootstrap_daemon/src/log.c @@ -26,8 +26,8 @@ #include "global.h" +#include #include - #include #include @@ -82,7 +82,22 @@ static int level_syslog(LOG_LEVEL level) static void log_syslog(LOG_LEVEL level, const char *format, va_list args) { - vsyslog(level_syslog(level), format, args); + va_list args2; + + va_copy(args2, args); + int size = vsnprintf(NULL, 0, format, args2); + va_end(args2); + + assert(size >= 0); + + if (size < 0) { + return; + } + + char buf[size + 1]; + vsnprintf(buf, size + 1, format, args); + + syslog(level_syslog(level), "%s", buf); } static FILE *level_stdout(LOG_LEVEL level) diff --git a/other/bootstrap_daemon/src/tox-bootstrapd.c b/other/bootstrap_daemon/src/tox-bootstrapd.c index 4495f88e..a0504eee 100644 --- a/other/bootstrap_daemon/src/tox-bootstrapd.c +++ b/other/bootstrap_daemon/src/tox-bootstrapd.c @@ -22,6 +22,8 @@ * */ +#define _XOPEN_SOURCE 600 + // system provided #include #include diff --git a/testing/DHT_test.c b/testing/DHT_test.c index c994f543..6d20d550 100644 --- a/testing/DHT_test.c +++ b/testing/DHT_test.c @@ -27,6 +27,8 @@ * */ +#define _XOPEN_SOURCE 600 + #ifdef HAVE_CONFIG_H #include "config.h" #endif diff --git a/testing/Messenger_test.c b/testing/Messenger_test.c index 4fd81649..695c50ae 100644 --- a/testing/Messenger_test.c +++ b/testing/Messenger_test.c @@ -37,6 +37,8 @@ * */ +#define _XOPEN_SOURCE 600 + #ifdef HAVE_CONFIG_H #include "config.h" #endif diff --git a/testing/av_test.c b/testing/av_test.c index 7418a15a..aeb661be 100644 --- a/testing/av_test.c +++ b/testing/av_test.c @@ -22,6 +22,8 @@ * -lopencv_highgui -lopencv_imgproc -lsndfile -pthread -lvpx -lopus -lsodium -lportaudio */ +#define _XOPEN_SOURCE 600 + #ifdef __cplusplus extern "C" { #endif diff --git a/testing/irc_syncbot.c b/testing/irc_syncbot.c index affc0296..b63b6151 100644 --- a/testing/irc_syncbot.c +++ b/testing/irc_syncbot.c @@ -1,3 +1,4 @@ +#define _XOPEN_SOURCE 600 #include #include @@ -34,8 +35,8 @@ static uint16_t port = 6667; static int sock; -#define SERVER_CONNECT "NICK "IRC_NAME"\nUSER "IRC_NAME" 8 * :"IRC_NAME"\n" -#define CHANNEL_JOIN "JOIN "IRC_CHANNEL"\n" +#define SERVER_CONNECT "NICK " IRC_NAME "\nUSER " IRC_NAME " 8 * :" IRC_NAME "\n" +#define CHANNEL_JOIN "JOIN " IRC_CHANNEL "\n" /* In toxcore/network.c */ uint64_t current_time_monotonic(void); @@ -131,8 +132,8 @@ static void copy_groupmessage(Tox *tox, uint32_t groupnumber, uint32_t friendgro uint8_t sendbuf[2048]; uint16_t send_len = 0; - memcpy(sendbuf, "PRIVMSG "IRC_CHANNEL" :", sizeof("PRIVMSG "IRC_CHANNEL" :")); - send_len += sizeof("PRIVMSG "IRC_CHANNEL" :") - 1; + memcpy(sendbuf, "PRIVMSG " IRC_CHANNEL " :", sizeof("PRIVMSG " IRC_CHANNEL " :")); + send_len += sizeof("PRIVMSG " IRC_CHANNEL " :") - 1; memcpy(sendbuf + send_len, name, namelen); send_len += namelen; sendbuf[send_len] = ':'; diff --git a/testing/misc_tools.c b/testing/misc_tools.c index c1292ed8..30c813ca 100644 --- a/testing/misc_tools.c +++ b/testing/misc_tools.c @@ -29,6 +29,7 @@ #include #include #include +#include #ifdef TOX_DEBUG #include diff --git a/testing/tox_shell.c b/testing/tox_shell.c index 18aad9c7..d5de3e67 100644 --- a/testing/tox_shell.c +++ b/testing/tox_shell.c @@ -26,6 +26,8 @@ * */ +#define _XOPEN_SOURCE 600 + #ifdef HAVE_CONFIG_H #include "config.h" #endif diff --git a/testing/tox_sync.c b/testing/tox_sync.c index 0c91abfd..6ac3dcf0 100644 --- a/testing/tox_sync.c +++ b/testing/tox_sync.c @@ -28,6 +28,8 @@ * */ +#define _XOPEN_SOURCE 600 + #ifdef HAVE_CONFIG_H #include "config.h" #endif @@ -42,6 +44,7 @@ #include #include #include +#include #define NUM_FILE_SENDERS 256 typedef struct { @@ -297,6 +300,7 @@ int main(int argc, char *argv[]) memcpy(path, argv[argvoffset + 4], strlen(argv[argvoffset + 4])); DIR *d; struct dirent *dir; + struct stat statbuf; uint8_t notconnected = 1; while (1) { @@ -310,7 +314,12 @@ int main(int argc, char *argv[]) if (d) { while ((dir = readdir(d)) != NULL) { - if (dir->d_type == DT_REG) { + char filepath[strlen(path) + strlen(dir->d_name) + 1]; + memcpy(filepath, path, strlen(path)); + memcpy(filepath + strlen(path), dir->d_name, strlen(dir->d_name) + 1); + stat(filepath, &statbuf); + + if (S_ISREG(statbuf.st_mode)) { char fullpath[1024]; if (path[strlen(path) - 1] == '/') { diff --git a/toxcore/TCP_server.c b/toxcore/TCP_server.c index 0e2d0085..d9ace28a 100644 --- a/toxcore/TCP_server.c +++ b/toxcore/TCP_server.c @@ -619,7 +619,7 @@ static int send_routing_response(TCP_Secure_Connection *con, uint8_t rpid, const */ static int send_connect_notification(TCP_Secure_Connection *con, uint8_t id) { - uint8_t data[2] = {TCP_PACKET_CONNECTION_NOTIFICATION, id + NUM_RESERVED_PORTS}; + uint8_t data[2] = {TCP_PACKET_CONNECTION_NOTIFICATION, (uint8_t)(id + NUM_RESERVED_PORTS)}; return write_packet_TCP_secure_connection(con, data, sizeof(data), 1); } @@ -629,7 +629,7 @@ static int send_connect_notification(TCP_Secure_Connection *con, uint8_t id) */ static int send_disconnect_notification(TCP_Secure_Connection *con, uint8_t id) { - uint8_t data[2] = {TCP_PACKET_DISCONNECT_NOTIFICATION, id + NUM_RESERVED_PORTS}; + uint8_t data[2] = {TCP_PACKET_DISCONNECT_NOTIFICATION, (uint8_t)(id + NUM_RESERVED_PORTS)}; return write_packet_TCP_secure_connection(con, data, sizeof(data), 1); } diff --git a/toxcore/network.c b/toxcore/network.c index 31e8fd8b..f58cde77 100644 --- a/toxcore/network.c +++ b/toxcore/network.c @@ -21,6 +21,9 @@ * */ +#define _DARWIN_C_SOURCE +#define _XOPEN_SOURCE 600 + #if defined(_WIN32) && _WIN32_WINNT >= _WIN32_WINNT_WINXP #define _WIN32_WINNT 0x501 #endif diff --git a/toxcore/tox.c b/toxcore/tox.c index 37298ce2..3276d2d5 100644 --- a/toxcore/tox.c +++ b/toxcore/tox.c @@ -21,6 +21,8 @@ * */ +#define _XOPEN_SOURCE 600 + #ifdef HAVE_CONFIG_H #include "config.h" #endif diff --git a/toxcore/util.c b/toxcore/util.c index 7a390ea9..1d2a85dc 100644 --- a/toxcore/util.c +++ b/toxcore/util.c @@ -22,6 +22,8 @@ * along with Tox. If not, see . */ +#define _XOPEN_SOURCE 600 + #ifdef HAVE_CONFIG_H #include "config.h" #endif -- cgit v1.2.3