[Xapian-devel] Re: [Xapian-commits] 7990: trunk/xapian-core/trunk/xapian-core/bin/ trunk/xapian-core/tests/harness/

Olly Betts olly at survex.com
Fri Mar 30 04:23:20 BST 2007


On Fri, Mar 30, 2007 at 11:11:28AM +1000, Mark Hammond wrote:
> Windows has an API function 'FormatMessage' which accepts socket error
> codes.  It also ensures a localized message is returned.

A localised version would be better.

> The only reason I didn't go that way was that I was concerned about the
> "footprint" of the patch and trying not to touch the non-windows code where
> possible.  I'm happy to help move this to a better solution though.

Actually, I think we can touch less generic code and get a better
result!

In xapian-core we always use '#include "safeerrno.h"' instead of
'#include <errno.h>', so we can hook in there, something like this:

Index: common/safeerrno.h
===================================================================
--- common/safeerrno.h	(revision 7970)
+++ common/safeerrno.h	(working copy)
@@ -33,4 +33,18 @@
 #endif
 #include <errno.h>
 
+#ifdef __WIN32__
+# include <string.h> // For strerror().
+
+// The MS implementation of strerror() (which mingw also uses) can't decode
+// socket-specific errno values.
+inline char * xapian_win32_strerror(int errno_val) {
+    if (errno_val > 42)
+	return xapian_win32_formaterror();
+    return strerror(errno_val);
+}
+
+# define strerror(E) xapian_win32_strerror(E)
+#endif
+
 #endif // XAPIAN_INCLUDED_SAFEERRNO_H

And then xapian_win32_formaterror() can be defined in a win32 specific
source file (looking at it, I think it will need a static buffer, which
makes inlining it from a header awkward).

The stuff in the inlined wrapper above is arbitrary of course - perhaps
it's best to just forward all calls by replacing the inlined wrapper
with a prototype for xapian_win32_strerror(), and then defining
xapian_win32_strerror() in the extra source file.

Cheers,
    Olly



More information about the Xapian-devel mailing list