[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Bug in +[NSError _lastError] ?
From: |
Jens Alfke |
Subject: |
Re: Bug in +[NSError _lastError] ? |
Date: |
Tue, 28 Feb 2012 16:56:25 -0800 |
On Feb 28, 2012, at 4:43 PM, I wrote:
> I’m not sure what the best way is to fix this. It looks like one could either
> add
> #undef _GNU_SOURCE
> near the top of the file where it defines _XOPEN_SOURCE; or one could use an
> #if around the call to strerror_r to call either version depending on which
> one is available.
>
> For now I’m going to try the first option since it’s simpler.
That didn’t work, because “common.h” both defines _GNU_SOURCE and ends up
including <string.h> so the GNU version of strerror_r is already declared. So I
went with the second option, which was pretty easy.
I’ll get around to formally submitting a patch once I’ve got more stuff
working, but here’s a diff showing what I did:
Index: Source/Additions/NSError+GNUstepBase.m
===================================================================
--- Source/Additions/NSError+GNUstepBase.m (revision 34837)
+++ Source/Additions/NSError+GNUstepBase.m (working copy)
@@ -130,12 +130,17 @@
/* FIXME ... not all are POSIX, should we use NSMachErrorDomain for some? */
domain = NSPOSIXErrorDomain;
+#if _GNU_SOURCE
+ message = [NSString stringWithCString: strerror_r(code, buf, BUFSIZ)
+ encoding: [NSString defaultCStringEncoding]];
+#else
if (strerror_r(code, buf, BUFSIZ) < 0)
{
snprintf(buf, sizeof(buf), "%ld", code);
}
message = [NSString stringWithCString: buf
encoding: [NSString defaultCStringEncoding]];
+#endif
/* FIXME ... can we do better localisation? */
info = [NSMutableDictionary dictionaryWithObjectsAndKeys:
message, NSLocalizedDescriptionKey,