Fix xslt_process() to ensure that it inserts a NULL terminator after the
[PostgreSQL.git] / src / backend / port / dynloader / nextstep.c
blobc22a469a61d953695e64868359b8e6f69f1c3be4
1 /* $PostgreSQL$ */
3 #include "postgres.h"
5 #include "mach-o/rld.h"
6 #include "streams/streams.h"
8 static char *lastError = NULL;
10 static NXStream *
11 OpenError()
13 return NXOpenMemory(NULL, 0, NX_WRITEONLY);
16 static void
17 CloseError(NXStream * s)
19 if (s)
20 NXCloseMemory(s, NX_FREEBUFFER);
23 static void
24 TransferError(NXStream * s)
26 char *buffer;
27 int len,
28 maxlen;
30 if (lastError)
31 free(lastError);
32 NXGetMemoryBuffer(s, &buffer, &len, &maxlen);
33 lastError = malloc(len + 1);
34 strcpy(lastError, buffer);
37 void *
38 next_dlopen(char *name)
40 int rld_success;
41 NXStream *errorStream;
42 char *result = NULL;
43 char **p;
45 errorStream = OpenError();
46 p = calloc(2, sizeof(void *));
47 p[0] = name;
48 rld_success = rld_load(errorStream, NULL, p, NULL);
49 free(p);
51 if (!rld_success)
53 TransferError(errorStream);
54 result = (char *) 1;
56 CloseError(errorStream);
57 return result;
60 int
61 next_dlclose(void *handle)
63 return 0;
66 void *
67 next_dlsym(void *handle, char *symbol)
69 NXStream *errorStream = OpenError();
70 char symbuf[1024];
71 unsigned long symref = 0;
73 snprintf(symbuf, sizeof(symbuf), "_%s", symbol);
74 if (!rld_lookup(errorStream, symbuf, &symref))
75 TransferError(errorStream);
76 CloseError(errorStream);
77 return (void *) symref;
80 char *
81 next_dlerror(void)
83 return lastError;