cc-preprocessorfreebsd

Check FreeBSD version at compile-time with the preprocessor


I am aware that I can use __FreeBSD__ to detect the operating system, but how do I detect the version of the operating system?

My requirement is to detect whether copy_file_range() function is available, which according to FreeBSD's man page appeared in FreeBSD 13.0.


Solution

  • According to this page, the macro __FreeBSD_version is defined in <sys/param.h> that contains the value of the current operating system version.