PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
darwin.c File Reference
#include "postgres.h"
#include <mach-o/dyld.h>
#include "dynloader.h"
Include dependency graph for darwin.c:

Go to the source code of this file.

Functions

void * pg_dlopen (char *filename)
 
void pg_dlclose (void *handle)
 
PGFunction pg_dlsym (void *handle, char *funcname)
 
char * pg_dlerror (void)
 

Variables

static NSObjectFileImageReturnCode cofiff_result = NSObjectFileImageFailure
 

Function Documentation

void pg_dlclose ( void *  handle)

Definition at line 70 of file darwin.c.

71 {
72  NSUnLinkModule(handle, FALSE);
73 }
#define FALSE
Definition: c.h:218
char* pg_dlerror ( void  )

Definition at line 100 of file darwin.c.

101 {
102  NSLinkEditErrors c;
103  int errorNumber;
104  const char *fileName;
105  const char *errorString = NULL;
106 
107  switch (cofiff_result)
108  {
109  case NSObjectFileImageSuccess:
110  /* must have failed in NSLinkModule */
111  NSLinkEditError(&c, &errorNumber, &fileName, &errorString);
112  if (errorString == NULL || *errorString == '\0')
113  errorString = "unknown link-edit failure";
114  break;
115  case NSObjectFileImageFailure:
116  errorString = "failed to open object file";
117  break;
118  case NSObjectFileImageInappropriateFile:
119  errorString = "inappropriate object file";
120  break;
121  case NSObjectFileImageArch:
122  errorString = "object file is for wrong architecture";
123  break;
124  case NSObjectFileImageFormat:
125  errorString = "object file has wrong format";
126  break;
127  case NSObjectFileImageAccess:
128  errorString = "insufficient permissions for object file";
129  break;
130  default:
131  errorString = "unknown failure to open object file";
132  break;
133  }
134 
135  return (char *) errorString;
136 }
static NSObjectFileImageReturnCode cofiff_result
Definition: darwin.c:54
char * c
#define NULL
Definition: c.h:226
void* pg_dlopen ( char *  filename)

Definition at line 57 of file darwin.c.

58 {
59  NSObjectFileImage image;
60 
61  cofiff_result = NSCreateObjectFileImageFromFile(filename, &image);
62  if (cofiff_result != NSObjectFileImageSuccess)
63  return NULL;
64  return NSLinkModule(image, filename,
65  NSLINKMODULE_OPTION_BINDNOW |
66  NSLINKMODULE_OPTION_RETURN_ON_ERROR);
67 }
static NSObjectFileImageReturnCode cofiff_result
Definition: darwin.c:54
#define NULL
Definition: c.h:226
static char * filename
Definition: pg_dumpall.c:84
PGFunction pg_dlsym ( void *  handle,
char *  funcname 
)

Definition at line 76 of file darwin.c.

77 {
78  NSSymbol symbol;
79  char *symname = (char *) malloc(strlen(funcname) + 2);
80 
81  if (!symname)
82  return NULL;
83 
84  sprintf(symname, "_%s", funcname);
85  if (NSIsSymbolNameDefined(symname))
86  {
87  symbol = NSLookupAndBindSymbol(symname);
88 
89  free(symname);
90  return (PGFunction) NSAddressOfSymbol(symbol);
91  }
92  else
93  {
94  free(symname);
95  return NULL;
96  }
97 }
Datum(* PGFunction)(FunctionCallInfo fcinfo)
Definition: fmgr.h:40
#define malloc(a)
Definition: header.h:45
#define free(a)
Definition: header.h:60
#define NULL
Definition: c.h:226
unsigned char symbol
Definition: api.h:2

Variable Documentation

NSObjectFileImageReturnCode cofiff_result = NSObjectFileImageFailure
static

Definition at line 54 of file darwin.c.

Referenced by pg_dlerror(), and pg_dlopen().