Skip to content

Commit 2de3d96

Browse files
author
Bryan Henderson
committed
Add nextstep port, courtesy of Ovidiu Predescu.
1 parent ef228cb commit 2de3d96

File tree

5 files changed

+194
-0
lines changed

5 files changed

+194
-0
lines changed

src/backend/port/nextstep/Makefile

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#-------------------------------------------------------------------------
2+
#
3+
# Makefile--
4+
# Makefile for port/next (NeXTStep 3.3 specific stuff)
5+
#
6+
#-------------------------------------------------------------------------
7+
8+
SRCDIR = ../../..
9+
include ../../../Makefile.global
10+
11+
INCLUDE_OPT = -I../.. \
12+
-I../../../include
13+
14+
CFLAGS+=$(INCLUDE_OPT)
15+
16+
OBJS = dynloader.o port.o
17+
18+
all: SUBSYS.o
19+
20+
SUBSYS.o: $(OBJS)
21+
$(LD) -r -o SUBSYS.o $(OBJS)
22+
23+
depend dep:
24+
$(CC) -MM $(INCLUDE_OPT) *.c >depend
25+
26+
clean:
27+
rm -f SUBSYS.o $(OBJS)
28+
29+
ifeq (depend,$(wildcard depend))
30+
include depend
31+
endif

src/backend/port/nextstep/dynloader.c

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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* OpenError()
8+
{
9+
return NXOpenMemory(NULL, 0, NX_WRITEONLY);
10+
}
11+
12+
static void CloseError(NXStream* s)
13+
{
14+
if (s)
15+
NXCloseMemory (s, NX_FREEBUFFER);
16+
}
17+
18+
static void TransferError(NXStream* s)
19+
{
20+
char *buffer;
21+
int len, maxlen;
22+
23+
if (lastError)
24+
free (lastError);
25+
NXGetMemoryBuffer (s, &buffer, &len, &maxlen);
26+
lastError = malloc (len + 1);
27+
strcpy (lastError, buffer);
28+
}
29+
30+
void* next_dlopen(char* name)
31+
{
32+
int rld_success;
33+
NXStream* errorStream;
34+
char* result = NULL;
35+
char **p;
36+
37+
errorStream = OpenError();
38+
p = calloc (2, sizeof(void*));
39+
p[0] = name;
40+
rld_success = rld_load(errorStream, NULL, p, NULL);
41+
free (p);
42+
43+
if (!rld_success) {
44+
TransferError (errorStream);
45+
result = (char*)1;
46+
}
47+
CloseError (errorStream);
48+
return result;
49+
}
50+
51+
int next_dlclose(void* handle)
52+
{
53+
return 0;
54+
}
55+
56+
void* next_dlsym (void *handle, char *symbol)
57+
{
58+
NXStream* errorStream = OpenError();
59+
char symbuf[1024];
60+
unsigned long symref = 0;
61+
62+
sprintf(symbuf, "_%s", symbol);
63+
if (!rld_lookup (errorStream, symbuf, &symref))
64+
TransferError(errorStream);
65+
CloseError(errorStream);
66+
return (void*) symref;
67+
}
68+
69+
char* next_dlerror(void)
70+
{
71+
return lastError;
72+
}

src/backend/port/nextstep/machine.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#ifndef MACHINE_H
2+
#define MACHINE_H
3+
4+
#define BLCKSZ 8192
5+
6+
#endif
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*-------------------------------------------------------------------------
2+
*
3+
* port-protos.h--
4+
* port-specific prototypes for NeXT
5+
*
6+
7+
-------------------------------------------------------------------------
8+
*/
9+
#ifndef PORT_PROTOS_H
10+
#define PORT_PROTOS_H
11+
12+
#include "fmgr.h" /* for func_ptr */
13+
#include "utils/dynamic_loader.h"
14+
15+
void* next_dlopen(char* name);
16+
int next_dlclose(void* handle);
17+
void* next_dlsym (void *handle, char *symbol);
18+
char* next_dlerror(void);
19+
20+
#define pg_dlopen(f) next_dlopen
21+
#define pg_dlsym next_dlsym
22+
#define pg_dlclose next_dlclose
23+
#define pg_dlerror next_dlerror
24+
25+
/* port.c */
26+
27+
#endif /* PORT_PROTOS_H */

src/backend/port/nextstep/port.c

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#ifndef _POSIX_SOURCE
2+
# include <libc.h>
3+
#else
4+
# include <unistd.h>
5+
# include <stdlib.h>
6+
#endif
7+
8+
#include <string.h>
9+
#include <sys/signal.h>
10+
11+
12+
void putenv(char* name)
13+
{
14+
extern char** environ;
15+
static int was_mallocated = 0;
16+
int size;
17+
18+
/* Compute the size of environ array including the final NULL */
19+
for (size = 1; environ[size++];)
20+
/* nothing */;
21+
22+
if (!was_mallocated) {
23+
char** tmp = environ;
24+
int i;
25+
26+
was_mallocated = 1;
27+
environ = malloc (size * sizeof(char*));
28+
for (i = 0; i < size; i++)
29+
environ[i] = tmp[i];
30+
}
31+
32+
environ = realloc (environ, (size + 1) * sizeof (char*));
33+
environ[size - 1] = strcpy (malloc (strlen (name) + 1), name);
34+
environ[size] = NULL;
35+
}
36+
37+
char* strdup (const char* string)
38+
{
39+
return strcpy (malloc (strlen (string) + 1), string);
40+
}
41+
42+
#ifndef _POSIX_SOURCE
43+
int sigaddset(int *set, int signo)
44+
{
45+
*set |= sigmask(signo);
46+
return *set;
47+
}
48+
49+
int sigemptyset(int *set)
50+
{
51+
return (*set = 0);
52+
}
53+
54+
char *getcwd(char *buf, size_t size)
55+
{
56+
return getwd (buf);
57+
}
58+
#endif

0 commit comments

Comments
 (0)