]> granicus.if.org Git - postgresql/blob - src/backend/port/dynloader/nextstep.c
Change #include's to use <> and "" as appropriate.
[postgresql] / src / backend / port / dynloader / nextstep.c
1 #include "mach-o/rld.h"
2 #include "streams/streams.h"
3 #include <stdlib.h>
4
5 static char *lastError = NULL;
6
7 static NXStream *
8 OpenError()
9 {
10         return NXOpenMemory(NULL, 0, NX_WRITEONLY);
11 }
12
13 static void
14 CloseError(NXStream * s)
15 {
16         if (s)
17                 NXCloseMemory(s, NX_FREEBUFFER);
18 }
19
20 static void
21 TransferError(NXStream * s)
22 {
23         char       *buffer;
24         int                     len,
25                                 maxlen;
26
27         if (lastError)
28                 free(lastError);
29         NXGetMemoryBuffer(s, &buffer, &len, &maxlen);
30         lastError = malloc(len + 1);
31         strcpy(lastError, buffer);
32 }
33
34 void *
35 next_dlopen(char *name)
36 {
37         int                     rld_success;
38         NXStream   *errorStream;
39         char       *result = NULL;
40         char      **p;
41
42         errorStream = OpenError();
43         p = calloc(2, sizeof(void *));
44         p[0] = name;
45         rld_success = rld_load(errorStream, NULL, p, NULL);
46         free(p);
47
48         if (!rld_success)
49         {
50                 TransferError(errorStream);
51                 result = (char *) 1;
52         }
53         CloseError(errorStream);
54         return result;
55 }
56
57 int
58 next_dlclose(void *handle)
59 {
60         return 0;
61 }
62
63 void *
64 next_dlsym(void *handle, char *symbol)
65 {
66         NXStream   *errorStream = OpenError();
67         char            symbuf[1024];
68         unsigned long symref = 0;
69
70         sprintf(symbuf, "_%s", symbol);
71         if (!rld_lookup(errorStream, symbuf, &symref))
72                 TransferError(errorStream);
73         CloseError(errorStream);
74         return (void *) symref;
75 }
76
77 char *
78 next_dlerror(void)
79 {
80         return lastError;
81 }