- Don't use
/procif there are other ways to get the information. For example, usesetprogname(argv[0])inmain()and thengetprogname()if you want to “know your name”.
- Don't rely on undocumented (by POSIX) behavior. 1)
- Don't record timestamps in the critical path of the app if it also works without (getting timestamps may be slow, depending on the accuracy of timestamps in the OS). If you have to get timestamps, 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,getpid) 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 at all possible.
- Do not rely on Linux-specific socket behaviour. In particular, default socket buffer sizes are different (call
setsockopt()withSO_SNDBUFandSO_RCVBUF), and while Linux'ssend()blocks when the socket buffer is full, FreeBSD's will fail and setENOBUFS` in errno. 2)
- If you absolutely need to rely on non-standard behaviour, properly encapsulate it into a generic API, do a check for the thing in the configure stage and bail out if it's missing.
- Check the FreeBSD Manual Pages to see if the function you use is a POSIX interface (“STANDARDS” section of the man page).
- Do not assume that
/bin/shisbash. Ensure that a command line passed tosystem()will work with a POSIX compliant shell.- Here is a list of common bash'isms (wiki.ubuntu.com)
- Do not
#include <stdint.h>ifinttypes.his sufficient. This will assure that your software builds on older versions of FreeBSD.
- Check that you include headers in the way recommended through POSIX or the man-page. Eg.
sys/types.his often forgotten, which doesn't seem to be as much of a problem for Linux as for FreeBSD.