12.19 Avoiding Linuxisms

Do not use /proc if there are any other ways of getting the information, e.g., setprogname(argv[0]) in main() and then getprogname(3) if you want to ``know your name''.

Do not rely on behaviour that is undocumented by POSIX.

Do not record timestamps in the critical path of the application if it also works without. Getting timestamps may be slow, depending on the accuracy of timestamps in the OS. If timestamps are really needed, determine how precise they have to be and use an API which is documented to just deliver the needed precision.

A number of simple syscalls (for example gettimeofday(2), getpid(2)) are much faster on Linux® than on any other operating system due to caching and the vsyscall performance optimizations. Do not rely on them being cheap in performance-critical applications. In general, try hard to avoid syscalls if possible.

Do not rely on Linux-specific socket behaviour. In particular, default socket buffer sizes are different (call setsockopt(2) with SO_SNDBUF and SO_RCVBUF, and while Linux's send(2) blocks when the socket buffer is full, FreeBSD's will fail and set ENOBUFS in errno.

If relying on non-standard behaviour is required, encapsulate it properly into a generic API, do a check for the behaviour in the configure stage, and stop if it is missing.

Check the man pages to see if the function used is a POSIX interface (in the ``STANDARDS'' section of the man page).

Do not assume that /bin/sh is bash. Ensure that a command line passed to system(3) will work with a POSIX compliant shell.

A list of common bashisms is available here.

Do not #include <stdint.h> if inttypes.h is sufficient. This will ensure that the software builds on older versions of FreeBSD.

Check that headers are included in the POSIX or man page recommended way, e.g., sys/types.h is often forgotten, which is not as much of a problem for Linux as it is for FreeBSD.

Compile threaded applications with ``-pthread'', not ``-lpthread'' or variations thereof.

For questions about the FreeBSD ports system, e-mail <ports@FreeBSD.org>.
For questions about this documentation, e-mail <doc@FreeBSD.org>.