WANproxy on Linux and/or with gcc...

Alain-Pierre Perrin apperrin at wanadoo.fr
Sun May 11 01:05:04 PDT 2014


Hello Juli and all other WANproxy contributors.


Building wanproxy from its brand new git repository, I stumbled on some
portability problems between BSD and Linux (or, more precisely, between
their respective default compilers Clang ang gcc). Some of them are
about not standard (enough) string functions and one is about a missing
constant.

[...]
g++ -I../.. -Wno-deprecated -Wnon-virtual-dtor -include common/common.h -pipe -O -g -W -Wall -Wno-system-headers -Wno-uninitialized -Wpointer-arith -Wreturn-type -Wcast-qual -Wwrite-strings -Wswitch -Wshadow -Wcast-align -Wunused-parameter -Wchar-subscripts -Wreorder -DTHREADS -c -o proxy_socks_connection.o proxy_socks_connection.cc
proxy_socks_connection.cc: In member function ‘void ProxySocksConnection::write_complete(Event)’:
proxy_socks_connection.cc:274:34: erreur: ‘strlcpy’ was not declared in this scope
      strlcpy(hex, "0", sizeof hex);
                                  ^
proxy_socks_connection.cc:276:61: erreur: ‘snprintf’ was not declared in this scope
      snprintf(hex, sizeof hex, "%0x%02x", bytes[0], bytes[1]);
                                                             ^
../../common/program.mk:103: recipe for target 'proxy_socks_connection.o' failed
make: *** [proxy_socks_connection.o] Error 1

"strlcpy" (plus every "strl*" variant) and "snprintf" seem to raise
portability issues :
https://en.wikibooks.org/wiki/C_Programming/C_Reference/nonstandard/strlcpy
https://stackoverflow.com/questions/14519161/how-to-use-strlcpy-in-gs-std-c0x-mode

For "snprintf", I solved it by adding this include in
proxy_socks_connection.cc :
#include <cstdio>
https://stackoverflow.com/questions/20149633/how-to-use-snprintf-in-g-std-c11-version-4-8-2

For "strlcpy" I tried to substitute "strncpy" to it. The compiler accepts it
but it may have adverse effects. :P

The compilation then stopped on this missing constant :
[...]
g++ -I../.. -Wno-deprecated -Wnon-virtual-dtor -include common/common.h -pipe -O -g -W -Wall -Wno-system-headers -Wno-uninitialized -Wpointer-arith -Wreturn-type -Wcast-qual -Wwrite-strings -Wswitch -Wshadow -Wcast-align -Wunused-parameter -Wchar-subscripts -Wreorder -DTHREADS -c -o sleep_queue_posix.o ../../common/thread/sleep_queue_posix.cc
In file included from ../../common/common.h:32:0,
                 from <command-line>:0:
../../common/thread/sleep_queue_posix.h: In member function ‘void SleepQueueState::wait(const NanoTime*)’:
../../common/thread/sleep_queue_posix.h:106:62: erreur: ‘ETIMEDOUT’ was not declared in this scope
    ASSERT("/sleep/queue/posix/state", error == 0 || error == ETIMEDOUT);
                                                              ^

I added this include in common/thread/sleep_queue_posix.cc :
#include <errno.h>
...and then wanproxy built successfully. A cleaner placement could probably
have been to add my includes in common/common.h like this :
#ifndef __clang__
#include <errno.h>
#include <cstdio>
#endif

...to keep "non-clang-isms" neatly grouped.


Alain-Pierre


More information about the wanproxy mailing list