Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Portability fixes
Browse files Browse the repository at this point in the history
- CFLAG gnu99 was changed to c99
- CFLAG/CXXFLAG -pedantic-errors was added so that non-ISO C/C++ now
  throws errors
- _XOPEN_SOURCE feature test macro added and set to 600 to expose SUSv3
  and c99 definitions
- Fixed tests (and bootstrap daemon logging) that were failing due to
  the altered build flags
- Misc. additions to .gitignore to make sure build artifacts don't wind
  up in version control
David Zero committed Dec 6, 2016
1 parent f0f53db commit 80fa66f
Showing 6 changed files with 42 additions and 27 deletions.
8 changes: 6 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -20,6 +20,9 @@ cmake_install.cmake
install_manifest.txt
tags
Makefile.in
DartConfiguration.tcl
CTestTestfile.cmake
*.pc

# Testing
testing/data
@@ -39,6 +42,9 @@ testing/data
*.app
*.la

# Libraries
*.so

# Misc (?)
m4/*
configure
@@ -50,8 +56,6 @@ config.log
config.status
stamp-h1
autom4te.cache
libtoxcore.pc
libtoxav.pc
libtool
.deps
.libs
20 changes: 11 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -56,23 +56,25 @@ macro(add_flag flag)
add_cflag(${flag})
add_cxxflag(${flag})
endmacro()

# Set standard version for compiler
add_cflag("-std=c99")
add_cxxflag("-std=c++98")

# Error on non-ISO C/C++
add_flag("-pedantic-errors")

# Expose SUSv3 and C99 definitions
add_definitions(-D_XOPEN_SOURCE=600)

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++.
# Disable specific warning flags for both C and C++.
add_flag("-Wno-cast-align")
add_flag("-Wno-conversion")
add_flag("-Wno-covered-switch-default")
4 changes: 2 additions & 2 deletions auto_tests/network_test.c
Original file line number Diff line number Diff line change
@@ -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.");
27 changes: 14 additions & 13 deletions other/bootstrap_daemon/src/log.c
Original file line number Diff line number Diff line change
@@ -80,11 +80,6 @@ static int level_syslog(LOG_LEVEL level)
return LOG_INFO;
}

static void log_syslog(LOG_LEVEL level, const char *format, va_list args)
{
vsyslog(level_syslog(level), format, args);
}

static FILE *level_stdout(LOG_LEVEL level)
{
switch (level) {
@@ -99,24 +94,30 @@ static FILE *level_stdout(LOG_LEVEL level)
return stdout;
}

static void log_stdout(LOG_LEVEL level, const char *format, va_list args)
{
vfprintf(level_stdout(level), format, args);
fflush(level_stdout(level));
}

bool write_log(LOG_LEVEL level, const char *format, ...)
{
va_list args;
va_start(args, format);

int size = vsnprintf(NULL, 0, format, args) + 1;

va_end(args);

va_start(args, format);

char buf[size];
vsnprintf(buf, size, format, args);

va_end(args);

switch (current_backend) {
case LOG_BACKEND_SYSLOG:
log_syslog(level, format, args);
syslog(level_syslog(level), buf);
break;

case LOG_BACKEND_STDOUT:
log_stdout(level, format, args);
fprintf(level_stdout(level), buf);
fflush(level_stdout(level));
break;
}

1 change: 1 addition & 0 deletions testing/misc_tools.c
Original file line number Diff line number Diff line change
@@ -29,6 +29,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>

#ifdef TOX_DEBUG
#include <assert.h>
9 changes: 8 additions & 1 deletion testing/tox_sync.c
Original file line number Diff line number Diff line change
@@ -42,6 +42,7 @@
#include <dirent.h>
#include <netinet/in.h>
#include <stdio.h>
#include <sys/stat.h>

#define NUM_FILE_SENDERS 256
typedef struct {
@@ -297,6 +298,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 +312,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)];
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] == '/') {

0 comments on commit 80fa66f

Please sign in to comment.