.\" .\" libexplain - Explain errno values returned by libc functions .\" Copyright (C) 2008, 2009 Peter Miller .\" Written by Peter Miller .\" .\" This program is free software; you can redistribute it and/or modify .\" it under the terms of the GNU General Public License as published by .\" the Free Software Foundation; either version 3 of the License, or (at .\" your option) any later version. .\" .\" This program is distributed in the hope that it will be useful, .\" but WITHOUT ANY WARRANTY; without even the implied warranty of .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU .\" General Public License for more details. .\" .\" You should have received a copy of the GNU General Public License .\" along with this program. If not, see . .\" .ad l .hy 0 .so etc/version.so .br libexplain \*(v) .br

libexplain \*(v)

The libexplain project provides a library which may be used to explain Unix and Linux system call errors. This will make your application's error messages much more informative to your users.

The library is not quite a drop-in replacement for strerror, but it comes close. Each system call has a dedicated libexplain function, for example

.nf
fd = open(path, flags, mode);
if (fd < 0)
{
    fprintf(stderr, "%s\en", explain_open(path, flags, mode));
    exit(EXIT_FAILURE);
}
.fi

If, for example, you were to try to open .br no-such-dir/some-file, you would see a message like

open(pathname = "no-such-dir/some-file", flags = O_RDONLY) failed, No such file or directory (2, ENOENT) because there is no "no-such-dir" directory in the current directory

The good news is that for each of these functions there is a wrapper function, in this case explain_open_or_die(3), that includes the above code fragment. Adding good error reporting is as simple as using a different, but similarly named, function. The library also provides thread safe variants of each explanation function.

The coverage for system calls is being improved all the time, as you can see from this documentation page generated from the source code. .so etc/coverage.so

Some Common Explanations

‘I think it's totally awesome, in the category of “why hasn't this existed for n years” awesome.&rsquo — Parker san
file descriptors
Where only a file descriptor is passed, the message will include the pathname of the file.

EACCES
When this is caused by a pathname component, rather than the last component, the name of the problematic component will be included in the message, along with some additional permissions information.

ENOENT
If this error is caused by a missing path component, rather than the last path component,
  • the name of the missing component is included in the explanation;
  • if the system call takes more than one path, the message will distinguish which of the paths is at fault;
  • if there is a similarly named file in the directory, the name of the similar file will be included in the message.

ENOTDIR
The name of the component which is not a directory will be included in the message, along with its file type.

ELOOP
The path of the first symbolic link in the loop will be included in the message. Or, if there was too many indirections but no loop, this will be included in the message, along with the actual limit.

EFAULT
If a system call takes more than one pointer argument, the message will indicate which pointer is at fault.

EEXIST
If a file should not exists, but does, the message will include the existing file's file type.

etc
There are many more. The philosophy is to include as much information as is available.

Documentation

.br

Download

The following files are available for download:

.br .br .br .br .br
File Description
libexplain-\*(V).README The README file form the tarball.
libexplain-\*(V).tar.gz The complete source.
libexplain-\*(V).ae The complete source, in aedist format.
libexplain-\*(V).pdf The reference manual, in PDF format.
debian Pre-built debian packages for Ubuntu 8.04 Jaunty i386
.\" ------------------------------------------------------------------------

Services provided by SourceForge

.\" ------------------------------------------------------------------------ .br
.br .br Libexplain is written and owned by Peter Miller <pmiller@opensource.org.au> and is freely distributable under the terms and conditions of the GNU LGPL, so you may use libexplain with proprietary programs. .br .br .fi Libexplain is developed using Aegis, a transaction based software configuration management system. The Aegis repository for this project is available. .br .br .br .br There is more Software by Peter Miller at his home page. .br
.\" ------------------------------------------------------------------------ .br
SourceForge.net Logo This page is hosted by SourceForge.
This page has been accessed approximately number times since .ds MO1 Jan .ds MO2 Feb .ds MO3 Mar .ds MO4 Apr .ds MO5 May .ds MO6 Jun .ds MO7 Jul .ds MO8 Aug .ds MO9 Sep .ds MO10 Oct .ds MO11 Nov .ds MO12 Dec .nr y4 \n[yr]+1900 \n[dy]-\*[MO\n[mo]]-\n[y4].