~ubuntu-branches/ubuntu/natty/postgresql-8.4/natty-updates

« back to all changes in this revision

Viewing changes to src/backend/port/dynloader/nextstep.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2009-03-20 12:00:13 UTC
  • Revision ID: james.westby@ubuntu.com-20090320120013-hogj7egc5mjncc5g
Tags: upstream-8.4~0cvs20090328
ImportĀ upstreamĀ versionĀ 8.4~0cvs20090328

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $PostgreSQL$ */
 
2
 
 
3
#include "postgres.h"
 
4
 
 
5
#include "mach-o/rld.h"
 
6
#include "streams/streams.h"
 
7
 
 
8
static char *lastError = NULL;
 
9
 
 
10
static NXStream *
 
11
OpenError()
 
12
{
 
13
        return NXOpenMemory(NULL, 0, NX_WRITEONLY);
 
14
}
 
15
 
 
16
static void
 
17
CloseError(NXStream * s)
 
18
{
 
19
        if (s)
 
20
                NXCloseMemory(s, NX_FREEBUFFER);
 
21
}
 
22
 
 
23
static void
 
24
TransferError(NXStream * s)
 
25
{
 
26
        char       *buffer;
 
27
        int                     len,
 
28
                                maxlen;
 
29
 
 
30
        if (lastError)
 
31
                free(lastError);
 
32
        NXGetMemoryBuffer(s, &buffer, &len, &maxlen);
 
33
        lastError = malloc(len + 1);
 
34
        strcpy(lastError, buffer);
 
35
}
 
36
 
 
37
void *
 
38
next_dlopen(char *name)
 
39
{
 
40
        int                     rld_success;
 
41
        NXStream   *errorStream;
 
42
        char       *result = NULL;
 
43
        char      **p;
 
44
 
 
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);
 
50
 
 
51
        if (!rld_success)
 
52
        {
 
53
                TransferError(errorStream);
 
54
                result = (char *) 1;
 
55
        }
 
56
        CloseError(errorStream);
 
57
        return result;
 
58
}
 
59
 
 
60
int
 
61
next_dlclose(void *handle)
 
62
{
 
63
        return 0;
 
64
}
 
65
 
 
66
void *
 
67
next_dlsym(void *handle, char *symbol)
 
68
{
 
69
        NXStream   *errorStream = OpenError();
 
70
        char            symbuf[1024];
 
71
        unsigned long symref = 0;
 
72
 
 
73
        snprintf(symbuf, sizeof(symbuf), "_%s", symbol);
 
74
        if (!rld_lookup(errorStream, symbuf, &symref))
 
75
                TransferError(errorStream);
 
76
        CloseError(errorStream);
 
77
        return (void *) symref;
 
78
}
 
79
 
 
80
char *
 
81
next_dlerror(void)
 
82
{
 
83
        return lastError;
 
84
}