mirror of
https://git.postgresql.org/git/postgresql.git
synced 2025-01-12 18:34:36 +08:00
Add code to provide useful dynamic-linking error messages on OS X.
This commit is contained in:
parent
e138630251
commit
ff5456feae
@ -3,31 +3,35 @@
|
||||
* available with a PostgreSQL-compatible license. Kudos Wilfredo
|
||||
* Sánchez <wsanchez@apple.com>.
|
||||
*
|
||||
* $Header: /cvsroot/pgsql/src/backend/port/dynloader/darwin.c,v 1.6 2002/10/01 05:06:44 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/port/dynloader/darwin.c,v 1.7 2003/04/13 01:19:06 tgl Exp $
|
||||
*/
|
||||
|
||||
#include "postgres.h"
|
||||
|
||||
#include <mach-o/dyld.h>
|
||||
|
||||
#include "dynloader.h"
|
||||
|
||||
|
||||
static NSObjectFileImageReturnCode cofiff_result = NSObjectFileImageFailure;
|
||||
|
||||
|
||||
void *
|
||||
pg_dlopen(char *filename)
|
||||
{
|
||||
NSObjectFileImage image;
|
||||
|
||||
if (NSCreateObjectFileImageFromFile(filename, &image) !=
|
||||
NSObjectFileImageSuccess)
|
||||
cofiff_result = NSCreateObjectFileImageFromFile(filename, &image);
|
||||
if (cofiff_result != NSObjectFileImageSuccess)
|
||||
return NULL;
|
||||
return NSLinkModule(image, filename,
|
||||
NSLINKMODULE_OPTION_BINDNOW |
|
||||
NSLINKMODULE_OPTION_RETURN_ON_ERROR);
|
||||
NSLINKMODULE_OPTION_BINDNOW |
|
||||
NSLINKMODULE_OPTION_RETURN_ON_ERROR);
|
||||
}
|
||||
|
||||
void
|
||||
pg_dlclose(void *handle)
|
||||
{
|
||||
NSUnLinkModule(handle, FALSE);
|
||||
return;
|
||||
}
|
||||
|
||||
PGFunction
|
||||
@ -53,5 +57,38 @@ pg_dlsym(void *handle, char *funcname)
|
||||
char *
|
||||
pg_dlerror(void)
|
||||
{
|
||||
return "no error message available";
|
||||
NSLinkEditErrors c;
|
||||
int errorNumber;
|
||||
const char *fileName;
|
||||
const char *errorString = NULL;
|
||||
|
||||
switch (cofiff_result)
|
||||
{
|
||||
case NSObjectFileImageSuccess:
|
||||
/* must have failed in NSLinkModule */
|
||||
NSLinkEditError(&c, &errorNumber, &fileName, &errorString);
|
||||
if (errorString == NULL || *errorString == '\0')
|
||||
errorString = "unknown link-edit failure";
|
||||
break;
|
||||
case NSObjectFileImageFailure:
|
||||
errorString = "failed to open object file";
|
||||
break;
|
||||
case NSObjectFileImageInappropriateFile:
|
||||
errorString = "inappropriate object file";
|
||||
break;
|
||||
case NSObjectFileImageArch:
|
||||
errorString = "object file is for wrong architecture";
|
||||
break;
|
||||
case NSObjectFileImageFormat:
|
||||
errorString = "object file has wrong format";
|
||||
break;
|
||||
case NSObjectFileImageAccess:
|
||||
errorString = "insufficient permissions for object file";
|
||||
break;
|
||||
default:
|
||||
errorString = "unknown failure to open object file";
|
||||
break;
|
||||
}
|
||||
|
||||
return (char *) errorString;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user