Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
ports:portabilityguidelines [2018/10/09 10:31] – add to CategoryHowTo MateuszPiotrowskiports:portabilityguidelines [2022/10/06 23:39] (current) – Fix list item and link KubilayKocak
Line 1: Line 1:
-  * Don't use /proc if there are other ways to get the information, e.g. setprogname(argv[0]) in main() and then getprogname() if you want to "know your name".+  * Don't use ''%%/proc%%'' if there are other ways to get the information. For example, use ''%%setprogname(argv[0])%%'' in ''%%main()%%'' and then ''%%getprogname()%%'' if you want to "know your name".
  
-  * Don't rely on undocumented (by POSIX) behavior.+  * Don't rely on undocumented (by POSIX) behavior. ((A few specific examples and better options/solutions here would be great))
  
   * 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.   * 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.
Line 7: Line 7:
   * 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.   * 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()%%'' with SO_SNDBUF and SO_RCVBUF), and while Linux's ''%%send()%%'' blocks when the socket buffer is full, %%FreeBSD%%'s will fail and set ENOBUFS in errno.+  * Do not rely on Linux-specific socket behaviour. In particular, default socket buffer sizes are different (call ''%%setsockopt()%%'' with ''%%SO_SNDBUF%%'' an''%%d %%''SO_RCVBUF''%%), and while Linux's %%''send()''%% blocks when the socket buffer is full, FreeBSD's will fail and set %%''ENOBUFS` in errno. ((A few specific examples and better options/solutions here would be great))
  
   * 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.   * 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 man pages at [[http://www.freebsd.org/cgi/man.cgi]] to see if the function you use is a POSIX interface ("STANDARDS" section of the man page).+  * Check the [[https://man.freebsd.org/|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/sh%%'' is **bash**.  Ensure that a command line passed to ''%%system()%%'' will work with a POSIX compliant shell.+  * Do not assume that ''%%/bin/sh%%'' is ''%%bash%%''. Ensure that a command line passed to ''%%system()%%'' will work with a POSIX compliant shell. 
 +    * Here is a [[https://wiki.ubuntu.com/DashAsBinSh|list of common bash'isms]] (wiki.ubuntu.com)
  
   * Do not ''%%#include <stdint.h>%%'' if ''%%inttypes.h%%'' is sufficient. This will assure that your software builds on older versions of %%FreeBSD%%.   * 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%%.+  * 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 Linux as for %%FreeBSD%%.
  
-  * Compile threaded apps with "-pthread", not "-lpthread" or variations thereof. +  * Compile threaded apps with ''%%-pthread%%'', not ''%%-lpthread%%'' or variations thereof. ((A history and explanation here would be great))
- +
-  * A list of common bashisms is available at https://wiki.ubuntu.com/DashAsBinSh+
  
 ---- ----
  
 {{tag>HowTo}} {{tag>HowTo}}
 +{{tag>Ports}}
 +{{tag>NeedsContent}}
  
  • ports/portabilityguidelines.1539081116.txt.gz
  • Last modified: 2018/10/09 10:31
  • by MateuszPiotrowski