- static char* errbuf = NULL;
- NSLinkEditErrors a;
- int b;
- char *c, *d;
- NSLinkEditError(&a, &b, &c, &d);
- if (!errbuf) {
- errbuf = (char*) malloc(256*sizeof(char));
- }
- if (!(c || d)) {
- last_was_error = 0;
- snprintf(errbuf, 255, "%s in %s: %d %d", c, d, a, b);
- return errbuf;
- } else if (last_was_error) {
- last_was_error = 0;
- snprintf(errbuf, 255, "Can't find symbol");
- return errbuf;
+ NSLinkEditErrors c;
+ int errorNumber;
+ const char *fileName, *errorString;
+ char *result = NULL;
+
+ if (last_error) {
+ NSLinkEditError(&c, &errorNumber, &fileName, &errorString);
+ /* The errorString obtained by the above is too verbose for
+ * our needs, so we just translate the errno.
+ *
+ * We also have simple fallbacks in case we've somehow lost
+ * the context before this point. */
+ if (errorNumber) {
+ result = strerror(errorNumber);
+ } else if (DLSYM_ERROR == last_error) {
+ result = "dlsym(3) failed";
+ } else if (DLOPEN_ERROR == last_error) {
+ result = "dlopen(3) failed";
+ }
+ last_error = 0;