This is an old revision of the document!


> One author of a port that I maintain has accepted my patches, and he asked me if there exists a kind of check-list of things to avoid for a better portability: linuxisms, GNUisms, non-standard headers, etc. (the project is developed on Linux)

  • Don't use /proc if there are other ways to get the information, e.g. argv[0] if you want to “know your name”.
  • Don't rely on undocumented (by POSIX) behavior.
  • 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.
  • If you absolutely need to use a non-standard “thing”, 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 man pages at man.cgi] to see if the function you use is a POSIX interface (“STANDARDS” section of the man page).
  • Do not assume that /bin/sh is bash. Ensure that a command line passed to system() will work with a POSIX compliant shell.
  • Do not #include <stdint.h> if inttypes.h is 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.h is often forgotten, which doesn't seem to be as much of a problem for That Other OS as for FreeBSD.

* Compile threaded apps with “-pthread”, not “-lpthread” or variations thereof.

  • ports/portabilityguidelines.1138892979.txt.gz
  • Last modified: 2006/02/02 15:09
  • by VolkerStolz