From 8ec5bd06b77fa483d055f71ed6847b40597b15ae Mon Sep 17 00:00:00 2001 From: "Marc G. Fournier" Date: Mon, 6 Jan 1997 00:12:34 +0000 Subject: [PATCH] Add NeXT port submitted by: Ovidiu Predescu --- src/backend/port/next/Makefile.inc | 14 ++++++ src/backend/port/next/externs.c | 43 +++++++++++++++++ src/backend/port/next/load.c | 73 +++++++++++++++++++++++++++++ src/backend/port/next/machine.h | 6 +++ src/backend/port/next/port-protos.h | 26 ++++++++++ 5 files changed, 162 insertions(+) create mode 100644 src/backend/port/next/Makefile.inc create mode 100644 src/backend/port/next/externs.c create mode 100644 src/backend/port/next/load.c create mode 100644 src/backend/port/next/machine.h create mode 100644 src/backend/port/next/port-protos.h diff --git a/src/backend/port/next/Makefile.inc b/src/backend/port/next/Makefile.inc new file mode 100644 index 0000000000..e5ac43ec80 --- /dev/null +++ b/src/backend/port/next/Makefile.inc @@ -0,0 +1,14 @@ +#------------------------------------------------------------------------- +# +# Makefile.inc-- +# Makefile for port/next (NeXTStep 3.3 specific stuff) +# +#------------------------------------------------------------------------- + +CFLAGS+= -DUSE_POSIX_TIME -DNO_EMPTY_STMTS + +SUBSRCS+= load.c externs.c + +HEADERS+= machine.h port-protos.h + +LDADD+= -lIPC diff --git a/src/backend/port/next/externs.c b/src/backend/port/next/externs.c new file mode 100644 index 0000000000..18ec7e90a8 --- /dev/null +++ b/src/backend/port/next/externs.c @@ -0,0 +1,43 @@ +#include +#include + +void putenv(char* name) +{ + extern char** environ; + static int was_mallocated = 0; + int size; + + /* Compute the size of environ array including the final NULL */ + for (size = 1; environ[size++];) + /* nothing */; + + if (!was_mallocated) { + char** tmp = environ; + int i; + + was_mallocated = 1; + environ = malloc (size * sizeof(char*)); + for (i = 0; i < size; i++) + environ[i] = tmp[i]; + } + + environ = realloc (environ, (size + 1) * sizeof (char*)); + environ[size - 1] = strcpy (malloc (strlen (name) + 1), name); + environ[size] = NULL; +} + +int sigaddset(int *set, int signo) +{ + *set |= sigmask(signo); + return *set; +} + +int sigemptyset(int *set) +{ + return (*set = 0); +} + +char *getcwd(char *buf, size_t size) +{ + return getwd (buf); +} diff --git a/src/backend/port/next/load.c b/src/backend/port/next/load.c new file mode 100644 index 0000000000..3d9dfb6eb1 --- /dev/null +++ b/src/backend/port/next/load.c @@ -0,0 +1,73 @@ +#include +#include +#include + +static char* lastError = NULL; + +static NXStream* OpenError() +{ + return NXOpenMemory(NULL, 0, NX_WRITEONLY); +} + +static void CloseError(NXStream* s) +{ + if (s) + NXCloseMemory (s, NX_FREEBUFFER); +} + +static void TransferError(NXStream* s) +{ + char *buffer; + int len, maxlen; + + if (lastError) + free (lastError); + NXGetMemoryBuffer (s, &buffer, &len, &maxlen); + lastError = malloc (len + 1); + strcpy (lastError, buffer); +} + +void* next_dlopen(char* name) +{ + int rld_success; + NXStream* errorStream; + char* result = NULL; + char **p; + + errorStream = OpenError(); + p = calloc (2, sizeof(void*)); + p[0] = name; + rld_success = rld_load(errorStream, NULL, p, NULL); + free (p); + + if (!rld_success) { + TransferError (errorStream); + result = (char*)1; + } + CloseError (errorStream); + return result; +} + +int next_dlclose(void* handle) +{ + return 0; +} + +void* next_dlsym (void *handle, char *symbol) +{ + NXStream* errorStream = OpenError(); + char symbuf[1024]; + unsigned long symref = 0; + + sprintf(symbuf, "_%s", symbol); + if (!rld_lookup (errorStream, symbuf, &symref)) + TransferError(errorStream); + CloseError(errorStream); + return (void*) symref; +} + +char* next_dlerror(void) +{ + return lastError; +} + diff --git a/src/backend/port/next/machine.h b/src/backend/port/next/machine.h new file mode 100644 index 0000000000..ef2585ccb0 --- /dev/null +++ b/src/backend/port/next/machine.h @@ -0,0 +1,6 @@ +#ifndef MACHINE_H +#define MACHINE_H + +#define BLCKSZ 8192 + +#endif diff --git a/src/backend/port/next/port-protos.h b/src/backend/port/next/port-protos.h new file mode 100644 index 0000000000..a25fe7b75f --- /dev/null +++ b/src/backend/port/next/port-protos.h @@ -0,0 +1,26 @@ +/*------------------------------------------------------------------------- + * + * port-protos.h-- + * port-specific prototypes for NeXT + * + *------------------------------------------------------------------------- + */ +#ifndef PORT_PROTOS_H +#define PORT_PROTOS_H + +#include "fmgr.h" /* for func_ptr */ +#include "utils/dynamic_loader.h" + +void* next_dlopen(char* name); +int next_dlclose(void* handle); +void* next_dlsym (void *handle, char *symbol); +char* next_dlerror(void); + +#define pg_dlopen(f) next_dlopen +#define pg_dlsym next_dlsym +#define pg_dlclose next_dlclose +#define pg_dlerror next_dlerror + +/* port.c */ + +#endif /* PORT_PROTOS_H */ -- 2.40.0