From 59e2a844f04a8725e8079f854158aa86ef5988b2 Mon Sep 17 00:00:00 2001 From: endoffile78 Date: Thu, 5 Jan 2017 15:16:56 -0600 Subject: [PATCH] Revert "Portability fixes" This reverts commit f3469070fe899e8e4fd88665386a55bad9f77cd8. --- .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 | 2 -- toxcore/tox.c | 2 -- toxcore/util.c | 2 -- 27 files changed, 24 insertions(+), 92 deletions(-) diff --git a/.gitignore b/.gitignore index 14dcced758..2a82d30841 100644 --- a/.gitignore +++ b/.gitignore @@ -21,9 +21,6 @@ install_manifest.txt tags Makefile.in CMakeLists.txt.user -DartConfiguration.tcl -CTestTestfile.cmake -*.pc # Testing testing/data @@ -43,9 +40,6 @@ testing/data *.app *.la -# Libraries -*.so - # Misc (?) m4/* configure @@ -57,6 +51,8 @@ config.log config.status stamp-h1 autom4te.cache +libtoxcore.pc +libtoxav.pc libtool .deps .libs diff --git a/CMakeLists.txt b/CMakeLists.txt index f0707a76b1..e0f5d12324 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -56,21 +56,22 @@ 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 6a43926120..d9013378cd 100644 --- a/auto_tests/TCP_test.c +++ b/auto_tests/TCP_test.c @@ -1,5 +1,3 @@ -#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 36707e0f93..aa2f8e13d4 100644 --- a/auto_tests/conference_test.c +++ b/auto_tests/conference_test.c @@ -1,8 +1,6 @@ /* Auto Tests: Conferences. */ -#define _XOPEN_SOURCE 600 - #ifdef HAVE_CONFIG_H #include "config.h" #endif @@ -177,7 +175,7 @@ START_TEST(test_many_group) * 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) { @@ -196,7 +194,7 @@ START_TEST(test_many_group) * 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]; @@ -243,7 +241,7 @@ START_TEST(test_many_group) 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 633e70021e..9cec16432e 100644 --- a/auto_tests/dht_test.c +++ b/auto_tests/dht_test.c @@ -1,5 +1,3 @@ -#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 ca918778a9..783f3f7b7a 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(IPV6_IPV4_IN_V6(ip2.ip6) != 0, - "IPV6_IPV4_IN_V6(::ffff:127.0.0.1): expected != 0, got 0."); + 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."); 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 0526492722..44ea9c7d1e 100644 --- a/auto_tests/onion_test.c +++ b/auto_tests/onion_test.c @@ -1,5 +1,3 @@ -#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 448160c04c..9d36ff2d18 100644 --- a/auto_tests/save_friend_test.c +++ b/auto_tests/save_friend_test.c @@ -1,10 +1,7 @@ /* 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 48f5671cbd..197c6e477e 100644 --- a/auto_tests/tox_many_tcp_test.c +++ b/auto_tests/tox_many_tcp_test.c @@ -1,8 +1,6 @@ /* 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 b44bbb0c54..0c4c8c7da7 100644 --- a/auto_tests/tox_many_test.c +++ b/auto_tests/tox_many_test.c @@ -1,8 +1,6 @@ /* 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 ab2202d1d7..dfd1d80a30 100644 --- a/auto_tests/tox_test.c +++ b/auto_tests/tox_test.c @@ -10,8 +10,6 @@ * */ -#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 79f552dea2..767fca8756 100644 --- a/auto_tests/toxav_basic_test.c +++ b/auto_tests/toxav_basic_test.c @@ -1,5 +1,3 @@ -#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 1a10db4430..b33b93c8c8 100644 --- a/auto_tests/toxav_many_test.c +++ b/auto_tests/toxav_many_test.c @@ -1,5 +1,3 @@ -#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 fa71d92035..e056de41de 100644 --- a/other/DHT_bootstrap.c +++ b/other/DHT_bootstrap.c @@ -22,8 +22,6 @@ * */ -#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 ae418f9342..7632d739d0 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,22 +82,7 @@ static int level_syslog(LOG_LEVEL level) static void log_syslog(LOG_LEVEL level, const char *format, va_list 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); + vsyslog(level_syslog(level), format, args); } 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 a0504eee78..4495f88e66 100644 --- a/other/bootstrap_daemon/src/tox-bootstrapd.c +++ b/other/bootstrap_daemon/src/tox-bootstrapd.c @@ -22,8 +22,6 @@ * */ -#define _XOPEN_SOURCE 600 - // system provided #include #include diff --git a/testing/DHT_test.c b/testing/DHT_test.c index 6d20d55024..c994f543bf 100644 --- a/testing/DHT_test.c +++ b/testing/DHT_test.c @@ -27,8 +27,6 @@ * */ -#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 695c50ae45..4fd81649f9 100644 --- a/testing/Messenger_test.c +++ b/testing/Messenger_test.c @@ -37,8 +37,6 @@ * */ -#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 aeb661bebc..7418a15a91 100644 --- a/testing/av_test.c +++ b/testing/av_test.c @@ -22,8 +22,6 @@ * -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 b63b6151cb..affc0296de 100644 --- a/testing/irc_syncbot.c +++ b/testing/irc_syncbot.c @@ -1,4 +1,3 @@ -#define _XOPEN_SOURCE 600 #include #include @@ -35,8 +34,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); @@ -132,8 +131,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 30c813cac6..c1292ed853 100644 --- a/testing/misc_tools.c +++ b/testing/misc_tools.c @@ -29,7 +29,6 @@ #include #include #include -#include #ifdef TOX_DEBUG #include diff --git a/testing/tox_shell.c b/testing/tox_shell.c index d5de3e67dc..18aad9c768 100644 --- a/testing/tox_shell.c +++ b/testing/tox_shell.c @@ -26,8 +26,6 @@ * */ -#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 6ac3dcf07e..0c91abfd71 100644 --- a/testing/tox_sync.c +++ b/testing/tox_sync.c @@ -28,8 +28,6 @@ * */ -#define _XOPEN_SOURCE 600 - #ifdef HAVE_CONFIG_H #include "config.h" #endif @@ -44,7 +42,6 @@ #include #include #include -#include #define NUM_FILE_SENDERS 256 typedef struct { @@ -300,7 +297,6 @@ 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) { @@ -314,12 +310,7 @@ int main(int argc, char *argv[]) if (d) { while ((dir = readdir(d)) != NULL) { - 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)) { + if (dir->d_type == DT_REG) { char fullpath[1024]; if (path[strlen(path) - 1] == '/') { diff --git a/toxcore/TCP_server.c b/toxcore/TCP_server.c index d9ace28afb..0e2d0085db 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, (uint8_t)(id + NUM_RESERVED_PORTS)}; + uint8_t data[2] = {TCP_PACKET_CONNECTION_NOTIFICATION, 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, (uint8_t)(id + NUM_RESERVED_PORTS)}; + uint8_t data[2] = {TCP_PACKET_DISCONNECT_NOTIFICATION, 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 250a304bce..31e8fd8bd3 100644 --- a/toxcore/network.c +++ b/toxcore/network.c @@ -21,8 +21,6 @@ * */ -#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 3276d2d595..37298ce23c 100644 --- a/toxcore/tox.c +++ b/toxcore/tox.c @@ -21,8 +21,6 @@ * */ -#define _XOPEN_SOURCE 600 - #ifdef HAVE_CONFIG_H #include "config.h" #endif diff --git a/toxcore/util.c b/toxcore/util.c index 1d2a85dc34..7a390ea93c 100644 --- a/toxcore/util.c +++ b/toxcore/util.c @@ -22,8 +22,6 @@ * along with Tox. If not, see . */ -#define _XOPEN_SOURCE 600 - #ifdef HAVE_CONFIG_H #include "config.h" #endif