Linux Magazine article

djberg96 on 2002-09-09T19:50:40

I read an article in Linux Magazine called "Writing Portable Code". I took an interest in this article because of my Ruby port of Proc::ProcessTable, where I'm currently following Dan's technique of creating source and header files for each platform in a subdirectory, and then building the appropriate files based on a platform check within the make file.

What caught my attention is that the author, Eric Schnoebelen, says that you should use, for example, "HAVE_GETHOSTNAME_R" instead of just testing the platform with "defined __LINUX__", because it's better to test the API than the platform.

The problem with this, of course, is that he chose to use a re-entrant function in his example. The problem with re-entrant functions is that several platforms implement them, but each with their own API. Thus, the *only* way to tell *which* API to use is to test the platform at some point.

Oops.