[Introduction]
Unix Incompatibility Notes:
Header Files
So far as I can tell the C compiler directive
#include <stdio.h>
works everywhere. But many other header files vary.
In many cases, the only thing to do is to have a configure script look for
header files and define appropriate compiler symbols so you can do things like:
#ifdef HAVE_FCNTL_H
# include <fcntl.h>
#endif
Gnu's autoconf
package does this kind of thing for you rather painlessly.
If you are building your own configure script, note that you can't always
test for the existence of /usr/include/fcntl.h. Some systems don't
put their header files under /usr/include (e.g., NextStep).
Sanest way to test for header files is to do what Gnu autoconf does:
test compiles.
Luckily, there are now standards defining which header files should exist and
what should be in them. These standards are themselves evolving, the original
ANSI standard having been adopted as an International ISO standard, and having
been steadily revised in small ways. For the issues discussed here, the
distinction between ANSI C and ISO C and various revisions can be entirely
ignored.
This page collects notes on portability issues with header files.
It isn't complete. As usual, I'm entering things here as I encounter them.
- alloc.h
- This is required for malloc() and calloc()
to work right in Turbo C, but so far as I know, isn't needed anywhere else.
(Wait! Turbo C isn't Unix! I can ignore it!)
- assert.h
Mandated by ANSI C standard. Defines assert() macro.
Not sure how prevalent it was in pre-ANSI C.
- ctype.h
Available everywhere.
See page on Character Type Functions.
- dirent.h
- Some use sys/ndir.h or sys/dir.h or ndir.h
instead. These are not generally interchangable.
See `autoconf' documentation.
- fcntl.h
- Not available on all systems.
- float.h
- Mandated by ANSI C standard.
I'm not sure how standard it was before the standard.
- limits.h
- Mandated by ANSI C standard.
Available on all ANSI systems, but not on all pre-ANSI ones.
- malloc.h
- Exists in most places, but stdlib.h seems to be prefered on
newer systems.
- ndir.h
- Some use sys/ndir.h or sys/dir.h or dirent.h
instead. These are not generally interchangable.
See `autoconf' documentation.
- paths.h
- Not available on all systems.
- regex.h
- Not all systems have POSIX regular expressions.
Worse, some systems that have regex.h don't have anything
resembling POSIX regular expressions (e.g., NextStep). I look for
the string `regex_t' in the header file to recognize POSIX
regular expression libraries.
- setjmp.h
- stdarg.h
- Available in all ANSI C compilers, but not in any pre-ANSI compiler.
Many but not all pre-ANSI systems will have varargs.h which
can be used slightly differently to achieve the same effect.
- stddef.h
Just defines NULL and offsetof() and sometimes
ptrdiff_t, wchar_t and size_t. Most of these
are defined by other files as well. Mostly only in ANSI compilers.
- stdlib.h
- Mandated by ANSI C standard.
Not available on all pre-ANSI C systems.
The prototypes defined here are often not easily findable,
so it's generally easiest to define them yourself. For example:
#ifdef HAVE_STDLIB_H
# include <stdlib.h>
#else
char *getenv();
void *malloc(), *realloc();
#endif
See autoconf documentation.
- string.h
- Doesn't always exist, and doesn't always define all the functions
it ought to
(however, I haven't run into any problems with this for a long time).
Some older BSD systems define strings.h instead of string.h,
but it's probably not worth the effort to have your config file look for
strings.h. Instead just declare them yourself if you don't
find string.h, like:
#ifdef HAVE_STRING_H
# include <string.h>
#else
# ifndef HAVE_STRCHR
# define strchr index
# define strrchr rindex
# endif
char *strchr(), *strrchr();
#endif
- sys/file.h
- Not available on all systems.
- sys/dir.h
- Some use ndir.h or sys/ndir.h or dirent.h
instead. These are not generally interchangable.
See `autoconf' documentation.
- sys/ndir.h
- Some use ndir.h or sys/dir.h or dirent.h
instead. These are not generally interchangable.
See `autoconf' documentation.
- sys/resource.h
- This seems to exist on all systems that have the setrlimit()
library function, but not all systems have that.
- sys/time.h
- Not available on all systems.
Most systems have both time.h and sys/time.h but some
won't allow you to include both.
- sys/wait.h
- Not available on all systems, and doesn't
always define the nice macros like WEXITSTATUS.
See autoconf documentation.
- unistd.h
- Not available on all systems.
- utmp.h
- This seems to exist everywhere, but on some systems (e.g., OpenBSD) you must
include sys/types.h before utmp.h.
Jan Wolter (E-Mail)
Sat Apr 15 14:43:20 EDT 2000
- Original Release.