12.18.Â Avoiding Linuxisms

Do not use /proc if there are any
other ways of getting the information. For example,
setprogname(argv[0]) in
main() and then getprogname(3)
to know the executable name>.

Do not rely on behavior 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.