This page is a collection of random notes about which portability issues exist on various OSes and architectures and how we can work-around them.
- 1 Generic
- 2 Linux
- 3 Mac OS X
- 4 Windows
- 5 FreeBSD
- 6 NetBSD
- 7 OpenBSD
Use glib API calls if available
We use glib in (e.g. in libsigrok, libsigrokdecode, and other subprojects) as a helper library for various purposes. One of the advantages of glib is that it has many API calls that already take care of various portability issues for us. Thus, if there is a glib function for a certain task it should generally be preferred over the "native" way of doing the same task (since the latter will be more likely to break on other OSes or architectures).
Any sigrok code should be able to work on systems of any endianness (big endian, little endian, or others). Care has to be taken in various places in the code to ensure there will be no endianness issues.
The configure script of e.g. libsigrok uses AC_C_BIGENDIAN to check for the endianness of the host where you compile (and seems to use some grep magic when cross-compiling). Per default it'll add a #define named WORDS_BIGENDIAN to config.h if it detects a big-endian host, otherwise WORDS_BIGENDIAN will not be defined. Thus, any code can use #ifdef WORDS_BIGENDIAN et al to handle endianness correctly.
32bit vs. 64bit systems
Mac OS X
FDs vs. sockets
While this library mimics the API of libusb-1.0 quite closely in order to be a compatible drop-in replacement from the point of view of applications that link this library, there are a few differences that have to be taken into account.
Problem: LIBUSB_CLASS_APPLICATION (an enum entry in libusb.org's libusb-1.0) doesn't exist in the FreeBSD libusb library/header.
Solution: A simple #define in libsigrok-internal.h can be added as workaround.
Problem: The libusb_handle_events_timeout_completed() call is not available in FreeBSD's libusb.
Solution: Since libusb_handle_events_timeout_completed() is mostly libusb_handle_events_timeout() with an additional (unused by us) parameter, a simple #define in libsigrok-internal.h can be used as workaround.