If you need to make modifications to existing code in order to port it to Linux, you may need to use ifdef...endif pairs to surround parts of Linux-specific code--or, for that matter, code corresponding to other implementations. No real standard for selecting portions of code to be compiled based on the operating system exists, but many programs use a convention such as defining SVR4 for System V code, BSD for BSD code, and linux for Linux-specific code.
The GNU C library used by Linux allows you to turn on various features of the library by defining various macros at compile time. These are:
If you define _BSD_SOURCE yourself, the additional definition _FAVOR_BSD will be defined for the library. This will cause BSD behavior for certain things to be selected over POSIX or SVR4. For example, if _FAVOR_BSD is defined, setjmp and longjmp will save and restore the signal mask, and getpgrp will accept a PID argument. Note that you must still link against libbsd to get BSD-like behavior for the features mentioned earlier in this paper.
Under Linux, gcc defines a number of macros automatically which you can use in your program. These are:
#ifdef linuxto surround Linux-specific code. Using these compile-time macros you can easily adapt existing code to include or exclude changes necessary to port the program to Linux, Note that because Linux supports more System V-like features in general, the best code base to start from with a program written for both System V and BSD is probably the System V version. Alternately, you can start from the BSD base and link against libbsd.