## Table of Contents
%TOC%
## Overview
This is a recompilation of common porting problems and their solutions. Information is gathered from the following sources:
[Debian GNU/Hurd port guidelines](http://www.debian.org/ports/hurd/hurd-devel-debian/)
[James Morrison's GNU/Hurd pages](http://hurd.dyndns.org/)
as well as other misc. sources.
First of all, see [[BtsFiling]] if you need instructions on manipulating [Debian](http://www.debian.org/) source packages and submitting patches to their [Bug Tracking System](http://bugs.debian.org/).
## Missing pthreads
You can try out Neal Walfield's implementation of libpthreads. It will server as our pthreads library until "the one pthreads that will rule them all" in GLibC has native support on the Hurd. Quote is from the mailing lists by Roland McGrath.
Neal's lastest tar balls of libpthreads is available at:
*
## Undefined PIPE\_BUF
Change it to use sysconf(\_SC\_PIPE\_BUF) #ifndef PIPE\_BUF. (from a Roland McGrath message in debian-hurd)
## Bad File Descriptor
If you get Bad File Descriptor error when trying to read from a file (or accessing it at all), check the open() invocation. The second argument is the access method. If it is a hard coded number instead of a symbol defined in the standard header files, the code is screwed and should be fixed to either use O\_RDONLY, O\_WRONLY or O\_RDWR. This bug was observed in the fortunes and mtools packages for example.
## PATH\_MAX
Every unconditionalized use of PATH\_MAX is a POSIX incompatibility. If there is no upper limit on the length of a path, this symbol is not defined in any header file. Instead, you need to either use a different implementation that does not rely on the length of a string or use sysconf() to query the length at runtime. If sysconf() returns -1, you have to use realloc() to allocate the needed memory dynamically.
## MAX\_PATH
same as PATH\_MAX
## MAXPATHLEN
same as PATH\_MAX
## MAXHOSTNAMELEN
same as PATH\_MAX. When you find a gethostname() funcion, which acts on a static buffer, you can replace it with Neal's [xgethostname function](http://ftp.walfield.org/pub/people/neal/xgethostname/) which returns the hostname as a dynamic buffer. For example:
Buggy code:
char localhost[MAXHOSTNAMELEN]; ... gethostname(localhost, sizeof(localhost));
Fixed code:
#ifndef MAXHOSTNAMELEN #include "xgethostname.h" #endif ... #ifdef MAXHOSTNAMELEN char localhost[MAXHOSTNAMELEN]; #else char \*localhost; #endif ... #ifdef MAXHOSTNAMELEN gethostname(localhost, sizeof(localhost)); #else localhost = xgethostname(); #endif
## NOFILE
Replace with RLIMIT\_NOFILE
## GNU specific #define
If you need to include specific code for the Hurd using #if...#endif, then you can use the \_\_GNU\_\_ symbol to do so. But think (at least) thrice! before doing so. In most situations, this is completely unnecessary and will create more problems than it may solve. Better ask on the mailing list how to do it right if you can't think of a better solution.
## sys\_errlist[] vs. strerror()
If a program has only support for sys\_errlist[] you will have to do some work to make it compile on GNU, which has dropped support for it and does only provide strerror(). Steinar Hamre writes about strerror():
strerror() should be used because:
* It is the modern, POSIX way.
* It is localized.
* It handles invalid signals/numbers out of range. (better errorhandling and not a buffer-overflow-candidate/security risk)
strerror() should always be used if it is available. Unfortunaly there are still some old non-POSIX systems that do not have strerror(), only sys\_errlist[].
Today, only supporting strerror() is far better than only supporting sys\_errlist[]. The best (from a portability viewpoint), however is supporting both. For configure.in, you will need:
AC\_CHECK\_FUNCS(strerror)
To config.h.in, you need to add:
#undef HAVE\_STRERROR
Then something like:
#ifndef HAVE_STRERROR
static char *
private_strerror (errnum)
int errnum;
{
extern char *sys_errlist[];
extern int sys_nerr;
if (errnum > 0 && errnum <= sys_nerr)
return sys_errlist[errnum];
return "Unknown system error";
}
#define strerror private_strerror
#endif /* HAVE_STRERROR */
You can for example look in the latest coreutils (the above is a simplified version of what I found there.) Patches should of course be sent to upstream maintainers, this is very useful even for systems with a working sys\_errlist[].
Of course, if you don't care about broken systems (like MS-DOG) not supporting strerror() you can just replace sys\_errlist[] directly (upstream might not accept your patch, but debian should have no problem)
## Filenames ending in a slash \`/'
Those are evil if they don't exist and you want to name a directory this way. For example, mkdir foobar/ will not work on GNU. This is POSIX compatible. POSIX says that the path of a directory may have slashes appended to it. But the directory does not exist yet, so the path does not refer to a directory, and hence trailing slashes are not guaranteed to work. Just drop the slashes, and you're fine.
## Missing termio.h
Change it to use termios.h (check for it properly with autoconf HAVE\_TERMIOS\_H or the **_GLIBC_** macro)
## AC\_HEADER\_TERMIO
The autoconf check for AC\_HEADER\_TERMIO tryes to check tfor termios, but it's only really checking for termio in termios.h. It is better to use AC\_CHECK\_HEADERS(termio.h termios.h)
## broken libc6 dependency
Some packages use an erroneous dependency on libc6-dev. This is incorrect because libc6 is specific to GNU/Linux. The corresponding package for GNU is libc0.3-dev but other OSes will have different ones. You can locate the problem in the debian/control file of the source tree. Typical solutions include detecting the OS using dpkg-architecture and hardcoding the soname, or better, use a logical OR. eg: libc6-dev | libc0.3-dev | libc-dev. The libc-dev is a virtual package that works for any soname but you have to put it only as the last option.
-- [[Main/RobertMillan]] - 22 Jul 2002
Formatting and minor grammatical fixes.
-- [[Main/JoachimNilsson]] - 09 Sep 2002
Added more examples and misc semantical fixes.
-- [[Main/RobertMillan]] - 05 Oct 2002
Added xgethostname example.
-- [[Main/RobertMillan]] - 15 Nov 2002
Added broken libc6 dependency
-- [[Main/RobertMillan]] - 21 Nov 2002