Skip to content

Commit

Permalink
Revert "Revert "Portability fixes""
Browse files Browse the repository at this point in the history
This reverts commit 59e2a84, and
defines _DARWIN_C_SOURCE in toxcore/network.c
  • Loading branch information
David Zero committed Jan 6, 2017
1 parent 08cd613 commit 8ef1f35
Show file tree
Hide file tree
Showing 27 changed files with 93 additions and 24 deletions.
8 changes: 6 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ install_manifest.txt
tags
Makefile.in
CMakeLists.txt.user
DartConfiguration.tcl
CTestTestfile.cmake
*.pc

# Testing
testing/data
Expand All @@ -40,6 +43,9 @@ testing/data
*.app
*.la

# Libraries
*.so

# Misc (?)
m4/*
configure
Expand All @@ -51,8 +57,6 @@ config.log
config.status
stamp-h1
autom4te.cache
libtoxcore.pc
libtoxav.pc
libtool
.deps
.libs
Expand Down
15 changes: 7 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 2 additions & 0 deletions auto_tests/TCP_test.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#define _XOPEN_SOURCE 600

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
Expand Down
8 changes: 5 additions & 3 deletions auto_tests/conference_test.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/* Auto Tests: Conferences.
*/

#define _XOPEN_SOURCE 600

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
Expand Down Expand Up @@ -175,7 +177,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) {
Expand All @@ -194,7 +196,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];
Expand Down Expand Up @@ -241,7 +243,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);
}
}
Expand Down
2 changes: 2 additions & 0 deletions auto_tests/dht_test.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#define _XOPEN_SOURCE 600

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
Expand Down
4 changes: 2 additions & 2 deletions auto_tests/network_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand Down
2 changes: 2 additions & 0 deletions auto_tests/onion_test.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#define _XOPEN_SOURCE 600

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
Expand Down
3 changes: 3 additions & 0 deletions auto_tests/save_friend_test.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
/* Auto Tests: Save and load friends.
*/

#define _XOPEN_SOURCE 600

#include "helpers.h"
#include "../toxcore/tox.h"

#include <assert.h>
#include <stdio.h>
Expand Down
2 changes: 2 additions & 0 deletions auto_tests/tox_many_tcp_test.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/* Auto Tests: Many TCP.
*/

#define _XOPEN_SOURCE 600

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
Expand Down
2 changes: 2 additions & 0 deletions auto_tests/tox_many_test.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/* Auto Tests: Many clients.
*/

#define _XOPEN_SOURCE 600

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
Expand Down
2 changes: 2 additions & 0 deletions auto_tests/tox_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
*
*/

#define _XOPEN_SOURCE 600

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
Expand Down
2 changes: 2 additions & 0 deletions auto_tests/toxav_basic_test.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#define _XOPEN_SOURCE 600

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
Expand Down
2 changes: 2 additions & 0 deletions auto_tests/toxav_many_test.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#define _XOPEN_SOURCE 600

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
Expand Down
2 changes: 2 additions & 0 deletions other/DHT_bootstrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
*
*/

#define _XOPEN_SOURCE 600

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
Expand Down
19 changes: 17 additions & 2 deletions other/bootstrap_daemon/src/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@

#include "global.h"

#include <assert.h>
#include <syslog.h>

#include <stdarg.h>
#include <stdio.h>

Expand Down Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions other/bootstrap_daemon/src/tox-bootstrapd.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
*
*/

#define _XOPEN_SOURCE 600

// system provided
#include <sys/stat.h>
#include <unistd.h>
Expand Down
2 changes: 2 additions & 0 deletions testing/DHT_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
*
*/

#define _XOPEN_SOURCE 600

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
Expand Down
2 changes: 2 additions & 0 deletions testing/Messenger_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
*
*/

#define _XOPEN_SOURCE 600

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
Expand Down
2 changes: 2 additions & 0 deletions testing/av_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
* -lopencv_highgui -lopencv_imgproc -lsndfile -pthread -lvpx -lopus -lsodium -lportaudio
*/

#define _XOPEN_SOURCE 600

#ifdef __cplusplus
extern "C" {
#endif
Expand Down
9 changes: 5 additions & 4 deletions testing/irc_syncbot.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#define _XOPEN_SOURCE 600

#include <stdint.h>
#include <stdio.h>
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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] = ':';
Expand Down
1 change: 1 addition & 0 deletions testing/misc_tools.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>

#ifdef TOX_DEBUG
#include <assert.h>
Expand Down
2 changes: 2 additions & 0 deletions testing/tox_shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
*
*/

#define _XOPEN_SOURCE 600

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
Expand Down
11 changes: 10 additions & 1 deletion testing/tox_sync.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
*
*/

#define _XOPEN_SOURCE 600

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
Expand All @@ -42,6 +44,7 @@
#include <dirent.h>
#include <netinet/in.h>
#include <stdio.h>
#include <sys/stat.h>

#define NUM_FILE_SENDERS 256
typedef struct {
Expand Down Expand Up @@ -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) {
Expand All @@ -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] == '/') {
Expand Down
4 changes: 2 additions & 2 deletions toxcore/TCP_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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);
}

Expand Down
3 changes: 3 additions & 0 deletions toxcore/network.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions toxcore/tox.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
*
*/

#define _XOPEN_SOURCE 600

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
Expand Down
2 changes: 2 additions & 0 deletions toxcore/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
* along with Tox. If not, see <http://www.gnu.org/licenses/>.
*/

#define _XOPEN_SOURCE 600

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
Expand Down

0 comments on commit 8ef1f35

Please sign in to comment.