FreeBSD port

This commit is contained in:
Walter Bright 2009-04-06 09:58:48 +00:00
parent 0be7d89863
commit cd79ee5861
26 changed files with 2354 additions and 34 deletions

80
etc/c/zlib/freebsd.mak Normal file
View file

@ -0,0 +1,80 @@
# Makefile for zlib
CC=gcc
LD=link
CFLAGS=-O -m32
LDFLAGS=
O=.o
.SUFFIXES: .c .o .d
.c.o:
$(CC) -c $(CFLAGS) $*
.d.o:
$(DMD) -c $(DFLAGS) $*
# variables
OBJS = adler32$(O) compress$(O) crc32$(O) gzio$(O) uncompr$(O) deflate$(O) \
trees$(O) zutil$(O) inflate$(O) infback$(O) inftrees$(O) inffast$(O)
all: zlib.a example minigzip
adler32.o: adler32.c zlib.h zconf.h
$(CC) -c $(cvarsdll) $(CFLAGS) $*.c
compress.o: compress.c zlib.h zconf.h
$(CC) -c $(cvarsdll) $(CFLAGS) $*.c
crc32.o: crc32.c zlib.h zconf.h
$(CC) -c $(cvarsdll) $(CFLAGS) $*.c
deflate.o: deflate.c deflate.h zutil.h zlib.h zconf.h
$(CC) -c $(cvarsdll) $(CFLAGS) $*.c
gzio.o: gzio.c zutil.h zlib.h zconf.h
$(CC) -c $(cvarsdll) $(CFLAGS) $*.c
infback.o: infback.c zlib.h zconf.h inftrees.h inflate.h inffast.h
$(CC) -c $(cvarsdll) $(CFLAGS) $*.c
inflate.o: inflate.c zlib.h zconf.h inftrees.h inflate.h inffast.h
$(CC) -c $(cvarsdll) $(CFLAGS) $*.c
inftrees.o: inftrees.c zlib.h zconf.h inftrees.h
$(CC) -c $(cvarsdll) $(CFLAGS) $*.c
inffast.o: inffast.c zlib.h zconf.h inftrees.h inflate.h inffast.h
$(CC) -c $(cvarsdll) $(CFLAGS) $*.c
trees.o: trees.c deflate.h zutil.h zlib.h zconf.h trees.h
$(CC) -c $(cvarsdll) $(CFLAGS) $*.c
uncompr.o: uncompr.c zlib.h zconf.h
$(CC) -c $(cvarsdll) $(CFLAGS) $*.c
zutil.o: zutil.c zutil.h zlib.h zconf.h
$(CC) -c $(cvarsdll) $(CFLAGS) $*.c
example.o: example.c zlib.h zconf.h
$(CC) -c $(cvarsdll) $(CFLAGS) $*.c
minigzip.o: minigzip.c zlib.h zconf.h
$(CC) -c $(cvarsdll) $(CFLAGS) $*.c
zlib.a: $(OBJS)
ar -r $@ $(OBJS)
example: example.o zlib.a
$(CC) -o $@ example.o zlib.a -g
minigzip: minigzip.o zlib.a
$(CC) -o $@ minigzip.o zlib.a -g
test: example minigzip
./example
echo hello world | minigzip | minigzip -d
clean:
$(RM) $(OBJS) zlib.a example.o example minigzip minigzip.o test foo.gz

644
freebsd.mak Normal file
View file

@ -0,0 +1,644 @@
# Makefile to build linux D runtime library libphobos.a.
# Targets:
# make
# Same as make unittest
# make libphobos.a
# Build libphobos.a
# make clean
# Delete unneeded files created by build process
# make unittest
# Build libphobos.a, build and run unit tests
LIB=libphobos.a
MAKEFILE=freebsd.mak
CFLAGS=-O -m32
#CFLAGS=-g -m32
DFLAGS=-O -release -w
#DFLAGS=-unittest -w
CC=gcc
#DMD=/dmd/bin/dmd
DMD=dmd
.SUFFIXES: .c .o .cpp .d .asm
.c.o:
$(CC) -c $(CFLAGS) $*.c
.cpp.o:
g++ -c $(CFLAGS) $*.cpp
.d.o:
$(DMD) -c $(DFLAGS) $*.d
.asm.o:
$(CC) -c $*.asm
targets : $(LIB)
test.o : test.d
$(DMD) -c test -g
test : test.o $(LIB)
$(CC) -o $@ test.o $(LIB) -lpthread -lm -g
OBJS = asserterror.o deh2.o complex.o gcstats.o \
critical.o object.o monitor.o \
outofmemory.o file.o \
compiler.o system.o moduleinit.o md5.o base64.o \
path.o string.o math.o mmfile.o \
outbuffer.o ctype.o regexp.o random.o \
freebsd.o freebsdsocket.o freebsdmath.o \
linux.o \
stream.o cstream.o switcherr.o array.o gc.o \
thread.o utf.o uri.o \
Dcrc32.o conv.o errno.o alloca.o cmath2.o \
process.o syserror.o metastrings.o \
socket.o socketstream.o stdarg.o stdio.o format.o \
perf.o openrj.o uni.o trace.o boxer.o \
demangle.o cover.o bitarray.o bind.o \
signals.o cpuid.o traits.o typetuple.o loader.o \
ti_wchar.o ti_uint.o ti_short.o ti_ushort.o \
ti_byte.o ti_ubyte.o ti_long.o ti_ulong.o ti_ptr.o \
ti_float.o ti_double.o ti_real.o ti_delegate.o \
ti_creal.o ti_ireal.o ti_cfloat.o ti_ifloat.o \
ti_cdouble.o ti_idouble.o \
ti_AC.o ti_Ag.o ti_Ashort.o \
ti_C.o ti_int.o ti_char.o ti_dchar.o \
ti_Aint.o ti_Along.o \
ti_Afloat.o ti_Adouble.o ti_Areal.o \
ti_Acfloat.o ti_Acdouble.o ti_Acreal.o \
ti_void.o \
date.o dateparse.o llmath.o math2.o Czlib.o Dzlib.o zip.o \
pthread.o
MAKEFILES= \
win32.mak linux.mak osx.mak freebsd.mak
SRCS= \
internal/aaA.d internal/adi.d \
internal/aApply.d internal/aApplyR.d internal/memset.d \
internal/arraycast.d internal/arraycat.d \
internal/switch.d internal/qsort.d internal/invariant.d \
internal/dmain2.d internal/cast.d internal/obj.d \
internal/arrayfloat.d internal/arraydouble.d internal/arrayreal.d \
internal/arraybyte.d internal/arrayshort.d internal/arrayint.d \
ZLIB_OBJS = etc/c/zlib/adler32.o etc/c/zlib/compress.o \
etc/c/zlib/crc32.o etc/c/zlib/gzio.o \
etc/c/zlib/uncompr.o etc/c/zlib/deflate.o \
etc/c/zlib/trees.o etc/c/zlib/zutil.o \
etc/c/zlib/inflate.o etc/c/zlib/infback.o \
etc/c/zlib/inftrees.o etc/c/zlib/inffast.o
GC_OBJS= internal/gc/gc.o internal/gc/gcold.o internal/gc/gcx.o \
internal/gc/gcbits.o internal/gc/gclinux.o
SRC= errno.c object.d unittest.d crc32.d gcstats.d
SRC_STD= std/zlib.d std/zip.d std/stdint.d std/conv.d std/utf.d std/uri.d \
std/gc.d std/math.d std/string.d std/path.d std/date.d \
std/ctype.d std/file.d std/compiler.d std/system.d std/moduleinit.d \
std/outbuffer.d std/math2.d std/thread.d std/md5.d std/base64.d \
std/asserterror.d std/dateparse.d std/outofmemory.d std/mmfile.d \
std/intrinsic.d std/array.d std/switcherr.d std/syserror.d \
std/regexp.d std/random.d std/stream.d std/process.d \
std/socket.d std/socketstream.d std/loader.d std/stdarg.d \
std/stdio.d std/format.d std/perf.d std/openrj.d std/uni.d \
std/boxer.d std/cstream.d std/demangle.d std/cover.d std/bitarray.d \
std/signals.d std/cpuid.d std/typetuple.d std/traits.d std/bind.d \
std/metastrings.d
SRC_STD_C= std/c/process.d std/c/stdlib.d std/c/time.d std/c/stdio.d \
std/c/math.d std/c/stdarg.d std/c/stddef.d std/c/fenv.d std/c/string.d \
std/d/locale.d
SRC_TI= \
std/typeinfo/ti_wchar.d std/typeinfo/ti_uint.d \
std/typeinfo/ti_short.d std/typeinfo/ti_ushort.d \
std/typeinfo/ti_byte.d std/typeinfo/ti_ubyte.d \
std/typeinfo/ti_long.d std/typeinfo/ti_ulong.d \
std/typeinfo/ti_ptr.d \
std/typeinfo/ti_float.d std/typeinfo/ti_double.d \
std/typeinfo/ti_real.d std/typeinfo/ti_delegate.d \
std/typeinfo/ti_creal.d std/typeinfo/ti_ireal.d \
std/typeinfo/ti_cfloat.d std/typeinfo/ti_ifloat.d \
std/typeinfo/ti_cdouble.d std/typeinfo/ti_idouble.d \
std/typeinfo/ti_Adchar.d \
std/typeinfo/ti_Ashort.d \
std/typeinfo/ti_Ag.d \
std/typeinfo/ti_AC.d std/typeinfo/ti_C.d \
std/typeinfo/ti_int.d std/typeinfo/ti_char.d \
std/typeinfo/ti_Aint.d \
std/typeinfo/ti_Along.d \
std/typeinfo/ti_Afloat.d std/typeinfo/ti_Adouble.d \
std/typeinfo/ti_Areal.d \
std/typeinfo/ti_Acfloat.d std/typeinfo/ti_Acdouble.d \
std/typeinfo/ti_Acreal.d \
std/typeinfo/ti_void.d
SRC_INT= \
internal/switch.d internal/complex.c internal/critical.c \
internal/minit.asm internal/alloca.d internal/llmath.d internal/deh.c \
internal/arraycat.d internal/invariant.d internal/monitor.c \
internal/memset.d internal/arraycast.d internal/aaA.d internal/adi.d \
internal/dmain2.d internal/cast.d internal/qsort.d internal/deh2.d \
internal/cmath2.d internal/obj.d internal/mars.h internal/aApply.d \
internal/aApplyR.d internal/object.d internal/trace.d internal/qsort2.d
SRC_STD_WIN= std/windows/registry.d \
std/windows/iunknown.d std/windows/charset.d
SRC_STD_C_WIN= std/c/windows/windows.d std/c/windows/com.d \
std/c/windows/winsock.d std/c/windows/stat.d
SRC_STD_C_LINUX= std/c/linux/linux.d std/c/linux/linuxextern.d \
std/c/linux/socket.d std/c/linux/pthread.d
SRC_STD_C_OSX= std/c/osx/osx.d
SRC_STD_C_FREEBSD= std/c/freebsd/freebsd.d \
std/c/freebsd/socket.d std/c/freebsd/pthread.d \
std/c/freebsd/math.d
SRC_ETC= etc/gamma.d
SRC_ETC_C= etc/c/zlib.d
SRC_ZLIB= etc/c/zlib/trees.h \
etc/c/zlib/inffixed.h \
etc/c/zlib/inffast.h \
etc/c/zlib/crc32.h \
etc/c/zlib/algorithm.txt \
etc/c/zlib/uncompr.c \
etc/c/zlib/compress.c \
etc/c/zlib/deflate.h \
etc/c/zlib/inftrees.h \
etc/c/zlib/infback.c \
etc/c/zlib/zutil.c \
etc/c/zlib/crc32.c \
etc/c/zlib/inflate.h \
etc/c/zlib/example.c \
etc/c/zlib/inffast.c \
etc/c/zlib/trees.c \
etc/c/zlib/inflate.c \
etc/c/zlib/gzio.c \
etc/c/zlib/zconf.h \
etc/c/zlib/zconf.in.h \
etc/c/zlib/minigzip.c \
etc/c/zlib/deflate.c \
etc/c/zlib/inftrees.c \
etc/c/zlib/zutil.h \
etc/c/zlib/zlib.3 \
etc/c/zlib/zlib.h \
etc/c/zlib/adler32.c \
etc/c/zlib/ChangeLog \
etc/c/zlib/README \
etc/c/zlib/win32.mak \
etc/c/zlib/linux.mak \
etc/c/zlib/osx.mak \
etc/c/zlib/freebsd.mak
SRC_GC= internal/gc/gc.d \
internal/gc/gcold.d \
internal/gc/gcx.d \
internal/gc/gcstub.d \
internal/gc/gcbits.d \
internal/gc/win32.d \
internal/gc/gclinux.d \
internal/gc/gcosxc.c \
internal/gc/testgc.d \
internal/gc/win32.mak \
internal/gc/linux.mak \
internal/gc/osx.mak \
internal/gc/freebsd.mak
ALLSRCS = $(SRC) $(SRC_STD) $(SRC_STD_C) $(SRC_TI) $(SRC_INT) $(SRC_STD_WIN) \
$(SRC_STD_C_WIN) $(SRC_STD_C_LINUX) $(SRC_ETC) $(SRC_ETC_C) \
$(SRC_ZLIB) $(SRC_GC) $(SRC_STD_C_FREEBSD)
$(LIB) : $(OBJS) $(GC_OBJS) $(ZLIB_OBJS) $(SRCS) $(MAKEFILE)
# rm -f $(LIB)
# ar -r $@ $(OBJS) $(ZLIB_OBJS) $(GC_OBJS)
$(DMD) -lib -of$(LIB) $(DFLAGS) $(SRCS) $(OBJS) $(ZLIB_OBJS) $(GC_OBJS)
unittest :
$(DMD) $(DFLAGS) -unittest -version=Unittest unittest.d $(SRCS) $(LIB)
./unittest
cov : $(SRCS) $(LIB)
$(DMD) -cov -unittest -ofcov unittest.d $(SRCS) $(LIB)
./cov
###########################################################
$(GC_OBJS):
# cd internal/gc
# make -f $(MAKEFILE) dmgc.a
# cd ../..
make DMD=$(DMD) -C ./internal/gc -f $(MAKEFILE)
$(ZLIB_OBJS):
# cd etc/c/zlib
# make -f $(MAKEFILE)
# cd ../../..
make -C ./etc/c/zlib -f $(MAKEFILE)
###
Dcrc32.o : crc32.d
$(DMD) -c $(DFLAGS) crc32.d -ofDcrc32.o
errno.o : errno.c
gcstats.o : gcstats.d
$(DMD) -c $(DFLAGS) gcstats.d
### internal
aaA.o : internal/aaA.d
$(DMD) -c $(DFLAGS) internal/aaA.d
aApply.o : internal/aApply.d
$(DMD) -c $(DFLAGS) internal/aApply.d
aApplyR.o : internal/aApplyR.d
$(DMD) -c $(DFLAGS) internal/aApplyR.d
adi.o : internal/adi.d
$(DMD) -c $(DFLAGS) internal/adi.d
alloca.o : internal/alloca.d
$(DMD) -c $(DFLAGS) internal/alloca.d
arraycast.o : internal/arraycast.d
$(DMD) -c $(DFLAGS) internal/arraycast.d
arraycat.o : internal/arraycat.d
$(DMD) -c $(DFLAGS) internal/arraycat.d
cast.o : internal/cast.d
$(DMD) -c $(DFLAGS) internal/cast.d
cmath2.o : internal/cmath2.d
$(DMD) -c $(DFLAGS) internal/cmath2.d
complex.o : internal/complex.c
$(CC) -c $(CFLAGS) internal/complex.c
critical.o : internal/critical.c
$(CC) -c $(CFLAGS) internal/critical.c
#deh.o : internal/mars.h internal/deh.cA
# $(CC) -c $(CFLAGS) internal/deh.c
deh2.o : internal/deh2.d
$(DMD) -c $(DFLAGS) -release internal/deh2.d
dmain2.o : internal/dmain2.d
$(DMD) -c $(DFLAGS) internal/dmain2.d
invariant.o : internal/invariant.d
$(DMD) -c $(DFLAGS) internal/invariant.d
llmath.o : internal/llmath.d
$(DMD) -c $(DFLAGS) internal/llmath.d
memset.o : internal/memset.d
$(DMD) -c $(DFLAGS) internal/memset.d
#minit.o : internal/minit.asm
# $(CC) -c internal/minit.asm
monitor.o : internal/mars.h internal/monitor.c
$(CC) -c $(CFLAGS) internal/monitor.c
obj.o : internal/obj.d
$(DMD) -c $(DFLAGS) internal/obj.d
object.o : internal/object.d
$(DMD) -c $(DFLAGS) internal/object.d
qsort.o : internal/qsort.d
$(DMD) -c $(DFLAGS) internal/qsort.d
switch.o : internal/switch.d
$(DMD) -c $(DFLAGS) internal/switch.d
trace.o : internal/trace.d
$(DMD) -c $(DFLAGS) internal/trace.d
### std
array.o : std/array.d
$(DMD) -c $(DFLAGS) std/array.d
asserterror.o : std/asserterror.d
$(DMD) -c $(DFLAGS) std/asserterror.d
base64.o : std/base64.d
$(DMD) -c $(DFLAGS) std/base64.d
bind.o : std/bind.d
$(DMD) -c $(DFLAGS) std/bind.d
bitarray.o : std/bitarray.d
$(DMD) -c $(DFLAGS) std/bitarray.d
boxer.o : std/boxer.d
$(DMD) -c $(DFLAGS) std/boxer.d
compiler.o : std/compiler.d
$(DMD) -c $(DFLAGS) std/compiler.d
conv.o : std/conv.d
$(DMD) -c $(DFLAGS) std/conv.d
cover.o : std/cover.d
$(DMD) -c $(DFLAGS) std/cover.d
cpuid.o : std/cpuid.d
$(DMD) -c $(DFLAGS) std/cpuid.d
cstream.o : std/cstream.d
$(DMD) -c $(DFLAGS) std/cstream.d
ctype.o : std/ctype.d
$(DMD) -c $(DFLAGS) std/ctype.d
date.o : std/dateparse.d std/date.d
$(DMD) -c $(DFLAGS) std/date.d
dateparse.o : std/dateparse.d std/date.d
$(DMD) -c $(DFLAGS) std/dateparse.d
demangle.o : std/demangle.d
$(DMD) -c $(DFLAGS) std/demangle.d
file.o : std/file.d
$(DMD) -c $(DFLAGS) std/file.d
format.o : std/format.d
$(DMD) -c $(DFLAGS) std/format.d
gc.o : std/gc.d
$(DMD) -c $(DFLAGS) std/gc.d
loader.o : std/loader.d
$(DMD) -c $(DFLAGS) std/loader.d
math.o : std/math.d
$(DMD) -c $(DFLAGS) std/math.d
math2.o : std/math2.d
$(DMD) -c $(DFLAGS) std/math2.d
md5.o : std/md5.d
$(DMD) -c $(DFLAGS) std/md5.d
metastrings.o : std/metastrings.d
$(DMD) -c $(DFLAGS) std/metastrings.d
mmfile.o : std/mmfile.d
$(DMD) -c $(DFLAGS) std/mmfile.d
moduleinit.o : std/moduleinit.d
$(DMD) -c $(DFLAGS) std/moduleinit.d
openrj.o : std/openrj.d
$(DMD) -c $(DFLAGS) std/openrj.d
outbuffer.o : std/outbuffer.d
$(DMD) -c $(DFLAGS) std/outbuffer.d
outofmemory.o : std/outofmemory.d
$(DMD) -c $(DFLAGS) std/outofmemory.d
path.o : std/path.d
$(DMD) -c $(DFLAGS) std/path.d
perf.o : std/perf.d
$(DMD) -c $(DFLAGS) std/perf.d
process.o : std/process.d
$(DMD) -c $(DFLAGS) std/process.d
random.o : std/random.d
$(DMD) -c $(DFLAGS) std/random.d
regexp.o : std/regexp.d
$(DMD) -c $(DFLAGS) std/regexp.d
signals.o : std/signals.d
$(DMD) -c $(DFLAGS) std/signals.d
socket.o : std/socket.d
$(DMD) -c $(DFLAGS) std/socket.d
socketstream.o : std/socketstream.d
$(DMD) -c $(DFLAGS) std/socketstream.d
stdio.o : std/stdio.d
$(DMD) -c $(DFLAGS) std/stdio.d
stream.o : std/stream.d
$(DMD) -c $(DFLAGS) -d std/stream.d
string.o : std/string.d
$(DMD) -c $(DFLAGS) std/string.d
switcherr.o : std/switcherr.d
$(DMD) -c $(DFLAGS) std/switcherr.d
system.o : std/system.d
$(DMD) -c $(DFLAGS) std/system.d
syserror.o : std/syserror.d
$(DMD) -c $(DFLAGS) std/syserror.d
thread.o : std/thread.d
$(DMD) -c $(DFLAGS) std/thread.d
traits.o : std/traits.d
$(DMD) -c $(DFLAGS) std/traits.d
typetuple.o : std/typetuple.d
$(DMD) -c $(DFLAGS) std/typetuple.d
uri.o : std/uri.d
$(DMD) -c $(DFLAGS) std/uri.d
uni.o : std/uni.d
$(DMD) -c $(DFLAGS) std/uni.d
utf.o : std/utf.d
$(DMD) -c $(DFLAGS) std/utf.d
Dzlib.o : std/zlib.d
$(DMD) -c $(DFLAGS) std/zlib.d -ofDzlib.o
zip.o : std/zip.d
$(DMD) -c $(DFLAGS) std/zip.d
### std/c
stdarg.o : std/c/stdarg.d
$(DMD) -c $(DFLAGS) std/c/stdarg.d
### std/c/freebsd
freebsd.o : std/c/freebsd/freebsd.d
$(DMD) -c $(DFLAGS) std/c/freebsd/freebsd.d
freebsdsocket.o : std/c/freebsd/socket.d
$(DMD) -c $(DFLAGS) std/c/freebsd/socket.d -offreebsdsocket.o
freebsdmath.o : std/c/freebsd/math.d
$(DMD) -c $(DFLAGS) std/c/freebsd/math.d -offreebsdmath.o
pthread.o : std/c/freebsd/pthread.d
$(DMD) -c $(DFLAGS) std/c/freebsd/pthread.d
### std/c/linux
linux.o : std/c/linux/linux.d
$(DMD) -c $(DFLAGS) std/c/linux/linux.d
### etc
### etc/c
Czlib.o : etc/c/zlib.d
$(DMD) -c $(DFLAGS) etc/c/zlib.d -ofCzlib.o
### std/typeinfo
ti_void.o : std/typeinfo/ti_void.d
$(DMD) -c $(DFLAGS) std/typeinfo/ti_void.d
ti_wchar.o : std/typeinfo/ti_wchar.d
$(DMD) -c $(DFLAGS) std/typeinfo/ti_wchar.d
ti_dchar.o : std/typeinfo/ti_dchar.d
$(DMD) -c $(DFLAGS) std/typeinfo/ti_dchar.d
ti_uint.o : std/typeinfo/ti_uint.d
$(DMD) -c $(DFLAGS) std/typeinfo/ti_uint.d
ti_short.o : std/typeinfo/ti_short.d
$(DMD) -c $(DFLAGS) std/typeinfo/ti_short.d
ti_ushort.o : std/typeinfo/ti_ushort.d
$(DMD) -c $(DFLAGS) std/typeinfo/ti_ushort.d
ti_byte.o : std/typeinfo/ti_byte.d
$(DMD) -c $(DFLAGS) std/typeinfo/ti_byte.d
ti_ubyte.o : std/typeinfo/ti_ubyte.d
$(DMD) -c $(DFLAGS) std/typeinfo/ti_ubyte.d
ti_long.o : std/typeinfo/ti_long.d
$(DMD) -c $(DFLAGS) std/typeinfo/ti_long.d
ti_ulong.o : std/typeinfo/ti_ulong.d
$(DMD) -c $(DFLAGS) std/typeinfo/ti_ulong.d
ti_ptr.o : std/typeinfo/ti_ptr.d
$(DMD) -c $(DFLAGS) std/typeinfo/ti_ptr.d
ti_float.o : std/typeinfo/ti_float.d
$(DMD) -c $(DFLAGS) std/typeinfo/ti_float.d
ti_double.o : std/typeinfo/ti_double.d
$(DMD) -c $(DFLAGS) std/typeinfo/ti_double.d
ti_real.o : std/typeinfo/ti_real.d
$(DMD) -c $(DFLAGS) std/typeinfo/ti_real.d
ti_delegate.o : std/typeinfo/ti_delegate.d
$(DMD) -c $(DFLAGS) std/typeinfo/ti_delegate.d
ti_creal.o : std/typeinfo/ti_creal.d
$(DMD) -c $(DFLAGS) std/typeinfo/ti_creal.d
ti_ireal.o : std/typeinfo/ti_ireal.d
$(DMD) -c $(DFLAGS) std/typeinfo/ti_ireal.d
ti_cfloat.o : std/typeinfo/ti_cfloat.d
$(DMD) -c $(DFLAGS) std/typeinfo/ti_cfloat.d
ti_ifloat.o : std/typeinfo/ti_ifloat.d
$(DMD) -c $(DFLAGS) std/typeinfo/ti_ifloat.d
ti_cdouble.o : std/typeinfo/ti_cdouble.d
$(DMD) -c $(DFLAGS) std/typeinfo/ti_cdouble.d
ti_idouble.o : std/typeinfo/ti_idouble.d
$(DMD) -c $(DFLAGS) std/typeinfo/ti_idouble.d
ti_AC.o : std/typeinfo/ti_AC.d
$(DMD) -c $(DFLAGS) std/typeinfo/ti_AC.d
ti_Ag.o : std/typeinfo/ti_Ag.d
$(DMD) -c $(DFLAGS) std/typeinfo/ti_Ag.d
ti_Abit.o : std/typeinfo/ti_Abit.d
$(DMD) -c $(DFLAGS) std/typeinfo/ti_Abit.d
ti_Ashort.o : std/typeinfo/ti_Ashort.d
$(DMD) -c $(DFLAGS) std/typeinfo/ti_Ashort.d
ti_Aint.o : std/typeinfo/ti_Aint.d
$(DMD) -c $(DFLAGS) std/typeinfo/ti_Aint.d
ti_Along.o : std/typeinfo/ti_Along.d
$(DMD) -c $(DFLAGS) std/typeinfo/ti_Along.d
ti_Afloat.o : std/typeinfo/ti_Afloat.d
$(DMD) -c $(DFLAGS) std/typeinfo/ti_Afloat.d
ti_Adouble.o : std/typeinfo/ti_Adouble.d
$(DMD) -c $(DFLAGS) std/typeinfo/ti_Adouble.d
ti_Areal.o : std/typeinfo/ti_Areal.d
$(DMD) -c $(DFLAGS) std/typeinfo/ti_Areal.d
ti_Acfloat.o : std/typeinfo/ti_Acfloat.d
$(DMD) -c $(DFLAGS) std/typeinfo/ti_Acfloat.d
ti_Acdouble.o : std/typeinfo/ti_Acdouble.d
$(DMD) -c $(DFLAGS) std/typeinfo/ti_Acdouble.d
ti_Acreal.o : std/typeinfo/ti_Acreal.d
$(DMD) -c $(DFLAGS) std/typeinfo/ti_Acreal.d
ti_C.o : std/typeinfo/ti_C.d
$(DMD) -c $(DFLAGS) std/typeinfo/ti_C.d
ti_char.o : std/typeinfo/ti_char.d
$(DMD) -c $(DFLAGS) std/typeinfo/ti_char.d
ti_int.o : std/typeinfo/ti_int.d
$(DMD) -c $(DFLAGS) std/typeinfo/ti_int.d
ti_bit.o : std/typeinfo/ti_bit.d
$(DMD) -c $(DFLAGS) std/typeinfo/ti_bit.d
##########################################################
zip : $(ALLSRCS) $(MAKEFILES) phoboslicense.txt
$(RM) phobos.zip
zip phobos $(ALLSRCS) $(MAKEFILES) phoboslicense.txt
clean:
$(RM) $(LIB) $(OBJS) unittest unittest.o
make -C ./internal/gc -f $(MAKEFILE) clean
make -C ./etc/c/zlib -f $(MAKEFILE) clean

View file

@ -75,17 +75,19 @@ void _STD_critical_term()
/* ================================= linux ============================ */
#if linux || __APPLE__
#if linux || __APPLE__ || __FreeBSD__
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
// PTHREAD_MUTEX_RECURSIVE is the "standard" symbol,
#if linux || __APPLE__
// while the _NP version is specific to Linux
#ifndef PTHREAD_MUTEX_RECURSIVE
# define PTHREAD_MUTEX_RECURSIVE PTHREAD_MUTEX_RECURSIVE_NP
#endif
#endif
/******************************************
* Enter/exit critical section.

View file

@ -459,7 +459,7 @@ void _d_monitor_epilog(void *x, void *y, Object *h)
/* ======================== linux =============================== */
#if linux || __APPLE__
#if linux || __APPLE__ || __FreeBSD__
#include "mars.h"

View file

@ -29,6 +29,12 @@ version (OSX)
extern (C) void* __osx_stack_end = cast(void*)0xC0000000;
}
version (FreeBSD)
{
// The bottom of the stack
extern (C) void* __libc_stack_end;
}
/***********************************
* The D main() function supplied by the user's program
*/
@ -57,6 +63,15 @@ extern (C) int main(size_t argc, char **argv)
__osx_stack_end = cast(void*)&argv;
}
version (FreeBSD)
{ /* FreeBSD does not provide a way to get at the top of the
* stack.
* But as far as the gc is concerned, argv is at the top
* of the main thread's stack, so save the address of that.
*/
__libc_stack_end = cast(void*)&argv;
}
version (Posix)
{
_STI_monitor_staticctor();

56
internal/gc/freebsd.mak Normal file
View file

@ -0,0 +1,56 @@
# makefile to build linux D garbage collector
#DMD=../../../dmd
DMD=dmd
CFLAGS=-g -m32
#DFLAGS=-unittest -g -release
DFLAGS=-release -O -inline -I../..
#DFLAGS=-release -inline -O
CC=gcc
OBJS= gc.o gcx.o gcbits.o gclinux.o gcold.o
SRC= gc.d gcx.d gcbits.d win32.d gclinux.d gcold.d testgc.d \
win32.mak linux.mak osx.mak freebsd.mak
.SUFFIXES: .c .o .d
.c.o:
$(CC) -c $(CFLAGS) $*
.d.o:
$(DMD) -c $(DFLAGS) $*
targets : testgc dmgc.a
testgc : testgc.o $(OBJS) freebsd.mak
$(DMD) -of$@ testgc.o gc.o gcx.o gcbits.o gclinux.o -g
testgc.o : testgc.d
$(DMD) -c $(DFLAGS) testgc.d
dmgc.a : $(OBJS) freebsd.mak
ar -r $@ $(OBJS)
gc.o : gc.d
$(DMD) -c $(DFLAGS) gc.d
gcold.o : gcold.d
$(DMD) -c $(DFLAGS) gcold.d
gcx.o : gcx.d
$(DMD) -c $(DFLAGS) gcx.d gcbits.d
#gcbits.o : gcbits.d
# $(DMD) -c $(DFLAGS) gcbits.d
gclinux.o : gclinux.d
$(DMD) -c $(DFLAGS) gclinux.d
zip : $(SRC)
$(RM) dmgc.zip
zip dmgc $(SRC)
clean:
$(RM) $(OBJS) dmgc.a testgc testgc.o

View file

@ -1,10 +1,14 @@
// Copyright (C) 2001-2004 by Digital Mars, www.digitalmars.com
// Copyright (C) 2001-2009 by Digital Mars, http://www.digitalmars.com
// All Rights Reserved
// Written by Walter Bright
import std.c.linux.linuxextern;
import std.c.linux.linux;
//import std.c.linux.linuxextern;
version (FreeBSD)
import std.c.freebsd.freebsd;
else
import std.c.linux.linux;
version (OSX)
{
@ -18,6 +22,14 @@ version (OSX)
}
}
version (FreeBSD)
{
extern (C)
{
extern char etext;
}
}
/+
extern (C)
{
@ -134,6 +146,11 @@ void os_query_staticdataseg(void **base, uint *nbytes)
*base = null;
*nbytes = 0;
}
else version (FreeBSD)
{
*base = cast(void *)&etext;
*nbytes = cast(byte *)&_end - cast(byte *)&etext;
}
else
{
*base = cast(void *)&__data_start;

View file

@ -12,7 +12,7 @@
#include <assert.h>
#if _WIN32
#elif linux || __APPLE__
#elif linux || __APPLE__ || __FreeBSD__
#define USE_PTHREADS 1
#else
#endif
@ -125,9 +125,11 @@ void _d_monitorrelease(Object *h)
#if USE_PTHREADS
#if linux || __APPLE__
#ifndef PTHREAD_MUTEX_RECURSIVE
# define PTHREAD_MUTEX_RECURSIVE PTHREAD_MUTEX_RECURSIVE_NP
#endif
#endif
// Includes attribute fixes from David Friedman's GDC port

View file

@ -23,6 +23,8 @@ CC=gcc
#DMD=/dmd/bin/dmd
DMD=dmd
.SUFFIXES: .c .o .cpp .d .asm
.c.o:
$(CC) -c $(CFLAGS) $*.c
@ -48,7 +50,8 @@ OBJS = asserterror.o deh2.o complex.o gcstats.o \
outofmemory.o file.o \
compiler.o system.o moduleinit.o md5.o base64.o \
path.o string.o math.o mmfile.o \
outbuffer.o ctype.o regexp.o random.o linux.o linuxsocket.o \
outbuffer.o ctype.o regexp.o random.o \
linux.o linuxsocket.o \
stream.o cstream.o switcherr.o array.o gc.o \
thread.o utf.o uri.o \
Dcrc32.o conv.o errno.o alloca.o cmath2.o \
@ -71,6 +74,9 @@ OBJS = asserterror.o deh2.o complex.o gcstats.o \
date.o dateparse.o llmath.o math2.o Czlib.o Dzlib.o zip.o \
pthread.o
MAKEFILES= \
win32.mak linux.mak osx.mak freebsd.mak
SRCS= \
internal/aaA.d internal/adi.d \
internal/aApply.d internal/aApplyR.d internal/memset.d \
@ -152,6 +158,12 @@ SRC_STD_C_WIN= std/c/windows/windows.d std/c/windows/com.d \
SRC_STD_C_LINUX= std/c/linux/linux.d std/c/linux/linuxextern.d \
std/c/linux/socket.d std/c/linux/pthread.d
SRC_STD_C_OSX= std/c/osx/osx.d
SRC_STD_C_FREEBSD= std/c/freebsd/freebsd.d \
std/c/freebsd/socket.d std/c/freebsd/pthread.d \
std/c/freebsd/math.d
SRC_ETC= etc/gamma.d
SRC_ETC_C= etc/c/zlib.d
@ -187,7 +199,8 @@ SRC_ZLIB= etc/c/zlib/trees.h \
etc/c/zlib/README \
etc/c/zlib/win32.mak \
etc/c/zlib/linux.mak \
etc/c/zlib/osx.mak
etc/c/zlib/osx.mak \
etc/c/zlib/freebsd.mak
SRC_GC= internal/gc/gc.d \
internal/gc/gcold.d \
@ -196,14 +209,16 @@ SRC_GC= internal/gc/gc.d \
internal/gc/gcbits.d \
internal/gc/win32.d \
internal/gc/gclinux.d \
internal/gc/gcosxc.c \
internal/gc/testgc.d \
internal/gc/win32.mak \
internal/gc/linux.mak \
internal/gc/osx.mak
internal/gc/osx.mak \
internal/gc/freebsd.mak
ALLSRCS = $(SRC) $(SRC_STD) $(SRC_STD_C) $(SRC_TI) $(SRC_INT) $(SRC_STD_WIN) \
$(SRC_STD_C_WIN) $(SRC_STD_C_LINUX) $(SRC_ETC) $(SRC_ETC_C) \
$(SRC_ZLIB) $(SRC_GC)
$(SRC_ZLIB) $(SRC_GC) $(SRC_STD_C_FREEBSD)
$(LIB) : $(OBJS) $(GC_OBJS) $(ZLIB_OBJS) $(SRCS) $(MAKEFILE)
@ -609,9 +624,9 @@ ti_bit.o : std/typeinfo/ti_bit.d
##########################################################
zip : $(ALLSRCS) osx.mak linux.mak win32.mak phoboslicense.txt
zip : $(ALLSRCS) $(MAKEFILES) phoboslicense.txt
$(RM) phobos.zip
zip phobos $(ALLSRCS) osx.mak linux.mak win32.mak phoboslicense.txt
zip phobos $(ALLSRCS) $(MAKEFILES) phoboslicense.txt
clean:
$(RM) $(LIB) $(OBJS) unittest unittest.o

27
osx.mak
View file

@ -23,6 +23,8 @@ CC=gcc
#DMD=/dmd/bin/dmd
DMD=dmd
.SUFFIXES: .c .o .cpp .d .asm
.c.o:
$(CC) -c $(CFLAGS) $*.c
@ -48,7 +50,8 @@ OBJS = asserterror.o deh2.o complex.o gcstats.o \
outofmemory.o file.o \
compiler.o system.o moduleinit.o md5.o base64.o \
path.o string.o math.o mmfile.o \
outbuffer.o ctype.o regexp.o random.o linux.o osx.o linuxsocket.o \
outbuffer.o ctype.o regexp.o random.o \
linux.o osx.o linuxsocket.o \
stream.o cstream.o switcherr.o array.o gc.o \
thread.o utf.o uri.o \
Dcrc32.o conv.o errno.o alloca.o cmath2.o \
@ -71,6 +74,9 @@ OBJS = asserterror.o deh2.o complex.o gcstats.o \
date.o dateparse.o llmath.o math2.o Czlib.o Dzlib.o zip.o \
pthread.o
MAKEFILES= \
win32.mak linux.mak osx.mak freebsd.mak
SRCS= \
internal/aaA.d internal/adi.d \
internal/aApply.d internal/aApplyR.d internal/memset.d \
@ -152,6 +158,12 @@ SRC_STD_C_WIN= std/c/windows/windows.d std/c/windows/com.d \
SRC_STD_C_LINUX= std/c/linux/linux.d std/c/linux/linuxextern.d \
std/c/linux/socket.d std/c/linux/pthread.d
SRC_STD_C_OSX= std/c/osx/osx.d
SRC_STD_C_FREEBSD= std/c/freebsd/freebsd.d \
std/c/freebsd/socket.d std/c/freebsd/pthread.d \
std/c/freebsd/math.d
SRC_ETC= etc/gamma.d
SRC_ETC_C= etc/c/zlib.d
@ -200,11 +212,12 @@ SRC_GC= internal/gc/gc.d \
internal/gc/testgc.d \
internal/gc/win32.mak \
internal/gc/linux.mak \
internal/gc/osx.mak
internal/gc/osx.mak \
internal/gc/freebsd.mak
ALLSRCS = $(SRC) $(SRC_STD) $(SRC_STD_C) $(SRC_TI) $(SRC_INT) $(SRC_STD_WIN) \
$(SRC_STD_C_WIN) $(SRC_STD_C_LINUX) $(SRC_ETC) $(SRC_ETC_C) \
$(SRC_ZLIB) $(SRC_GC)
$(SRC_ZLIB) $(SRC_GC) $(SRC_STD_C_FREEBSD)
$(LIB) : $(OBJS) $(GC_OBJS) $(ZLIB_OBJS) $(SRCS) $(MAKEFILE)
@ -483,9 +496,9 @@ linux.o : std/c/linux/linux.d
linuxsocket.o : std/c/linux/socket.d
$(DMD) -c $(DFLAGS) std/c/linux/socket.d -oflinuxsocket.o
pthread.o : std/c/linux/pthread.d
$(DMD) -c $(DFLAGS) std/c/linux/pthread.d
$(DMD) -c $(DFLAGS) std/c/linux/pthread.d
### std/c/osx
@ -615,9 +628,9 @@ ti_bit.o : std/typeinfo/ti_bit.d
##########################################################
zip : $(ALLSRCS) osx.mak linux.mak win32.mak phoboslicense.txt
zip : $(ALLSRCS) $(MAKEFILES) phoboslicense.txt
$(RM) phobos.zip
zip phobos $(ALLSRCS) osx.mak linux.mak win32.mak phoboslicense.txt
zip phobos $(ALLSRCS) $(MAKEFILES) phoboslicense.txt
clean:
$(RM) $(LIB) $(OBJS) unittest unittest.o

600
std/c/freebsd/freebsd.d Normal file
View file

@ -0,0 +1,600 @@
/* Written by Walter Bright, Christopher E. Miller, and many others.
* http://www.digitalmars.com/d/
* Placed into public domain.
*/
module std.c.freebsd.freebsd;
version (FreeBSD) { } else { static assert(0); }
public import std.c.freebsd.pthread;
private import std.c.stdio;
alias uint fflags_t;
alias int clockid_t;
alias int time_t;
alias int __time_t;
alias int pid_t;
alias long off_t;
alias long blkcnt_t;
alias uint blksize_t;
alias uint dev_t;
alias uint gid_t;
alias long id_t;
//alias ulong ino64_t;
alias uint ino_t;
alias ushort mode_t;
alias ushort nlink_t;
alias uint uid_t;
alias ulong fsblkcnt_t;
alias ulong fsfilcnt_t;
struct timespec
{
time_t tv_sec;
int tv_nsec;
}
static if (size_t.sizeof == 4)
alias int ssize_t;
else
alias long ssize_t;
alias ssize_t intptr_t;
enum : int
{
SIGHUP = 1,
SIGINT = 2,
SIGQUIT = 3,
SIGILL = 4,
SIGTRAP = 5,
SIGABRT = 6,
SIGIOT = 6,
SIGEMT = 7,
SIGFPE = 8,
SIGKILL = 9,
SIGBUS = 10,
SIGSEGV = 11,
SIGSYS = 12,
SIGPIPE = 13,
SIGALRM = 14,
SIGTERM = 15,
SIGURG = 16,
SIGSTOP = 17,
SIGTSTP = 18,
SIGCONT = 19,
SIGCHLD = 20,
SIGTTIN = 21,
SIGTTOU = 22,
SIGIO = 23,
SIGXCPU = 24,
SIGXFSZ = 25,
SIGVTALRM = 26,
SIGPROF = 27,
SIGWINCH = 28,
SIGINFO = 29,
SIGUSR1 = 30,
SIGUSR2 = 31,
SIGTHR = 32,
SIGLWP = SIGTHR,
SIGRTMIN = 65,
SIGRTMAX = 126,
}
// fcntl.h
enum
{
O_RDONLY = 0,
O_WRONLY = 1,
O_RDWR = 2,
O_CREAT = 0x200,
O_EXCL = 0x800,
O_TRUNC = 0x400,
O_APPEND = 8,
O_NONBLOCK = 4,
O_SYNC = 0x80,
O_SHLOCK = 0x10,
O_EXLOCK = 0x20,
O_ASYNC = 0x40,
O_NOFOLLOW = 0x100,
O_NOCTTY = 0x8000,
O_DIRECT = 0x1000,
}
// sys/stat.h
struct struct_stat
{
dev_t st_dev;
ino_t st_ino;
mode_t st_mode;
nlink_t st_nlink;
uid_t st_uid;
gid_t st_gid;
dev_t st_rdev;
timespec st_atimespec;
timespec st_mtimespec;
timespec st_ctimespec;
off_t st_size;
blkcnt_t st_blocks;
blksize_t st_blksize;
fflags_t st_flags;
uint st_gen;
int st_lspare;
timespec st_birthtimesspec;
ubyte[16 - timespec.sizeof] st_qspare;
}
unittest
{
version (FreeBSD) assert(struct_stat.sizeof == 96);
}
// sys/stat.h
enum : int
{
S_IFIFO = 0010000,
S_IFCHR = 0020000,
S_IFDIR = 0040000,
S_IFBLK = 0060000,
S_IFREG = 0100000,
S_IFLNK = 0120000,
S_IFSOCK = 0140000,
S_ISVTX = 0001000,
S_IFWHT = 0160000,
S_IFMT = 0170000,
S_IREAD = 0000400,
S_IWRITE = 0000200,
S_IEXEC = 0000100,
}
extern (C)
{
int access(in char*, int);
int open(in char*, int, ...);
int read(int, void*, int);
int write(int, in void*, int);
int close(int);
int lseek(int, off_t, int);
int fstat(int, struct_stat*);
int lstat(in char*, struct_stat*);
int stat(in char*, struct_stat*);
int chdir(in char*);
int mkdir(in char*, int);
int rmdir(in char*);
char* getcwd(char*, int);
int chmod(in char*, mode_t);
int fork();
int dup(int);
int dup2(int, int);
int pipe(int[2]);
pid_t wait(int*);
int waitpid(pid_t, int*, int);
uint alarm(uint);
char* basename(char*);
//wint_t btowc(int);
int chown(in char*, uid_t, gid_t);
int chroot(in char*);
size_t confstr(int, char*, size_t);
int creat(in char*, mode_t);
char* ctermid(char*);
int dirfd(DIR*);
char* dirname(char*);
int fattach(int, char*);
int fchmod(int, mode_t);
int fdatasync(int);
int ffs(int);
int fmtmsg(int, char*, int, char*, char*, char*);
int fpathconf(int, int);
int fseeko(FILE*, off_t, int);
off_t ftello(FILE*);
extern char** environ;
}
alias int suseconds_t;
struct timeval
{
time_t tv_sec;
suseconds_t tv_usec;
}
struct struct_timezone
{
int tz_minuteswest;
int tz_dstime;
}
struct tm
{
int tm_sec;
int tm_min;
int tm_hour;
int tm_mday;
int tm_mon;
int tm_year;
int tm_wday;
int tm_yday;
int tm_isdst;
int tm_gmtoff;
char* tm_zone;
}
extern (C)
{
int gettimeofday(timeval*, struct_timezone*);
int settimeofday(in timeval*, in struct_timezone*);
__time_t time(__time_t*);
char* asctime(in tm*);
char* ctime(in __time_t*);
tm* gmtime(in __time_t*);
tm* localtime(in __time_t*);
__time_t mktime(tm*);
char* asctime_r(in tm* t, char* buf);
char* ctime_r(in __time_t* timep, char* buf);
tm* gmtime_r(in __time_t* timep, tm* result);
tm* localtime_r(in __time_t* timep, tm* result);
}
/**************************************************************/
// Memory mapping from <sys/mman.h> and <bits/mman.h>
enum
{
PROT_NONE = 0,
PROT_READ = 1,
PROT_WRITE = 2,
PROT_EXEC = 4,
}
// Memory mapping sharing types
enum
{ MAP_SHARED = 1,
MAP_PRIVATE = 2,
MAP_COPY = MAP_PRIVATE,
MAP_FIXED = 0x10,
MAP_FILE = 0,
MAP_ANON = 0x1000,
MAP_NORESERVE = 0x40,
MAP_RENAME = 0x20,
MAP_RESERVED0080 = 0x80,
MAP_NOEXTEND = 0x100,
MAP_HASSEMAPHORE = 0x200,
MAP_STACK = 0x400,
MAP_NOSYNC = 0x800,
MAP_NOCORE = 0x20000,
}
// Values for msync()
enum
{ MS_ASYNC = 1,
MS_INVALIDATE = 2,
MS_SYNC = 0,
}
// Values for mlockall()
enum
{
MCL_CURRENT = 1,
MCL_FUTURE = 2,
}
// Values for madvise
enum
{ MADV_NORMAL = 0,
MADV_RANDOM = 1,
MADV_SEQUENTIAL = 2,
MADV_WILLNEED = 3,
MADV_DONTNEED = 4,
MADV_FREE = 5,
MADV_NOSYNC = 6,
MADV_AUTOSYNC = 7,
MADV_NOCORE = 8,
MADV_CORE = 9,
MADV_PROTECT = 10,
}
enum
{
MINCORE_INCORE = 1,
MINCORE_REFERENCED = 2,
MINCORE_MODIFIED = 4,
MINCORE_REFERENCED_OTHER = 8,
MINCORE_MODIFIED_OTHER = 0x10,
}
extern (C)
{
void* mmap(void*, size_t, int, int, int, off_t);
const void* MAP_FAILED = cast(void*)-1;
int madvise(void*, size_t, int);
int minherit(void*, size_t, int);
int munmap(void*, size_t);
int mprotect(void*, size_t, int);
int msync(void*, size_t, int);
int madvise(void*, size_t, int);
int mlock(void*, size_t);
int munlock(void*, size_t);
int mlockall(int);
int munlockall();
void* mremap(void*, size_t, size_t, int);
int mincore(/*const*/ void*, size_t, ubyte*);
int remap_file_pages(void*, size_t, int, size_t, int);
int shm_open(in char*, int, int);
int shm_unlink(in char*);
}
extern(C)
{
enum
{
DT_UNKNOWN = 0,
DT_FIFO = 1,
DT_CHR = 2,
DT_DIR = 4,
DT_BLK = 6,
DT_REG = 8,
DT_LNK = 10,
DT_SOCK = 12,
DT_WHT = 14,
}
struct dirent
{
uint d_fileno; // this is int on some linuxes
ushort d_reclen;
ubyte d_type; // this field isn't there on some linuxes
ubyte d_namlen;
char[256] d_name;
}
struct DIR
{
// Managed by OS.
}
DIR* opendir(in char* name);
int closedir(DIR* dir);
dirent* readdir(DIR* dir);
void rewinddir(DIR* dir);
off_t telldir(DIR* dir);
void seekdir(DIR* dir, off_t offset);
}
extern(C)
{
private import std.intrinsic;
int select(int nfds, fd_set* readfds, fd_set* writefds, fd_set* errorfds, timeval* timeout);
int fcntl(int s, int f, ...);
enum
{
EINTR = 4,
EINPROGRESS = 36,
}
const uint FD_SETSIZE = 1024;
//const uint NFDBITS = 8 * int.sizeof; // DMD 0.110: 8 * (int).sizeof is not an expression
const int NFDBITS = 32;
struct fd_set
{
int[FD_SETSIZE / NFDBITS] fds_bits;
alias fds_bits __fds_bits;
}
int FDELT(int d)
{
return d / NFDBITS;
}
int FDMASK(int d)
{
return 1 << (d % NFDBITS);
}
// Removes.
void FD_CLR(int fd, fd_set* set)
{
btr(cast(uint*)&set.fds_bits.ptr[FDELT(fd)], cast(uint)(fd % NFDBITS));
}
// Tests.
int FD_ISSET(int fd, fd_set* set)
{
return bt(cast(uint*)&set.fds_bits.ptr[FDELT(fd)], cast(uint)(fd % NFDBITS));
}
// Adds.
void FD_SET(int fd, fd_set* set)
{
bts(cast(uint*)&set.fds_bits.ptr[FDELT(fd)], cast(uint)(fd % NFDBITS));
}
// Resets to zero.
void FD_ZERO(fd_set* set)
{
set.fds_bits[] = 0;
}
}
extern (C)
{
/* From <dlfcn.h>
* See http://www.opengroup.org/onlinepubs/007908799/xsh/dlsym.html
*/
const int RTLD_NOW = 2;
void* dlopen(in char* file, int mode);
int dlclose(void* handle);
void* dlsym(void* handle, char* name);
char* dlerror();
}
extern (C)
{
/* from <pwd.h>
*/
struct passwd
{
char *pw_name;
char *pw_passwd;
uid_t pw_uid;
gid_t pw_gid;
time_t pw_change;
char* pw_class;
char* pw_gecos;
char* pw_dir;
char* pw_shell;
time_t pw_expire;
int pw_fields;
}
int getpwnam_r(char*, passwd*, void*, size_t, passwd**);
passwd* getpwnam(in char*);
passwd* getpwuid(uid_t);
int getpwuid_r(uid_t, passwd*, char*, size_t, passwd**);
int kill(pid_t, int);
int sem_close(sem_t*);
}
extern (C)
{
/* from sched.h
*/
int sched_yield();
}
extern (C)
{
/* from signal.h
*/
extern (C) alias void (*__sighandler_t)(int);
extern (C) alias void (*__sigaction_t)(int, void*, void*);
const SA_RESTART = 2;
const size_t _SIGSET_WORDS = 4;
struct sigset_t
{
uint[_SIGSET_WORDS] __bits;
}
alias sigset_t __sigset;
alias sigset_t __sigset_t;
struct sigaction_t
{
union
{ __sighandler_t sa_handler;
__sigaction_t sa_sigaction;
}
int sa_flags;
sigset_t sa_mask;
}
int sigfillset(sigset_t*);
int sigdelset(sigset_t*, int);
int sigismember(sigset_t*, int);
int sigaction(int, sigaction_t*, sigaction_t*);
int sigsuspend(sigset_t*);
}
extern (C)
{
/* from semaphore.h
*/
alias intptr_t semid_t;
struct sem_t
{
uint magic;
pthread_mutex_t lock;
pthread_cond_t gtzero;
uint count;
uint nwaiters;
semid_t semid;
int syssem;
struct LIST_ENTRY
{ sem_t *le_next;
sem_t **le_prev;
}
LIST_ENTRY entry;
sem_t **backpointer;
}
int sem_init(sem_t*, int, uint);
int sem_wait(sem_t*);
int sem_trywait(sem_t*);
int sem_post(sem_t*);
int sem_getvalue(sem_t*, int*);
int sem_destroy(sem_t*);
}
extern (C)
{
/* from utime.h
*/
struct utimbuf
{
__time_t actime;
__time_t modtime;
}
int utime(in char* filename, in utimbuf* buf);
}
extern (C)
{
extern
{
void* __libc_stack_end;
int __data_start;
int _end;
int timezone;
void *_deh_beg;
void *_deh_end;
}
}
// sched.h
enum
{
SCHED_FIFO = 1,
SCHED_OTHER = 2,
SCHED_RR = 3
}
struct sched_param
{
int sched_priority;
}

97
std/c/freebsd/math.d Normal file
View file

@ -0,0 +1,97 @@
/**
* Missing functions from C's &lt;math.h&gt;
* Authors: Walter Bright, Digital Mars, http://www.digitalmars.com
* License: Public Domain
* Macros:
* WIKI=Phobos/StdCMath
*/
module std.c.freebsd.math;
import std.c.math;
extern (C):
/* FreeBSD doesn't do the 'l' math functions.
* So we provide our own (lame) implementations.
*/
real acosl(real x) { return acos(x); }
real asinl(real x) { return asin(x); }
real atanl(real x) { return atan(x); }
real atan2l(real y, real x) { return atan2(y, x); }
real cosl(real x) { return cos(x); }
real sinl(real x) { return sin(x); }
real tanl(real x) { return tan(x); }
real acoshl(real x) { return acosh(x); }
real asinhl(real x) { return asinh(x); }
real atanhl(real x) { return atanh(x); }
real coshl(real x) { return cosh(x); }
real sinhl(real x) { return sinh(x); }
real tanhl(real x) { return tanh(x); }
real expl(real x) { return exp(x); }
real exp2l(real x) { return exp2(x); }
real expm1l(real x) { return expm1(x); }
//real frexpl(real x, int *exp) { return frexp(x, exp); }
//real ldexpl(real x, int exp) { return ldexp(x, exp); }
//real ilogbl(real x) { return ilogb(x); }
real logl(real x) { return log(x); }
real log10l(real x) { return log10(x); }
real log1pl(real x) { return log1p(x); }
real log2l(real x) { return log10(x) / log10(2); }
real logbl(real x) { return logb(x); }
/*
real modfl(real x, real *iptr)
{ double d;
auto r = modf(x, &d);
*iptr = d;
return r;
}
*/
//real scalbnl(real x, int n) { return scalbn(x, n); }
//real scalblnl(real x, int n) { return scalbln(x, n); }
real cbrtl(real x) { return cbrt(x); }
//real fabsl(real x) { return fabs(x); }
real hypotl(real x, real y) { return hypot(x, y); }
real powl(real x, real y) { return pow(x, y); }
real sqrtl(real x) { return sqrt(x); }
real erfl(real x) { return erf(x); }
real erfcl(real x) { return erfc(x); }
real lgammal(real x) { return lgamma(x); }
real tgammal(real x) { return tgamma(x); }
real ceill(real x) { return ceil(x); }
//real floorl(real x) { return floor(x); }
real nearbyintl(real x) { return nearbyint(x); }
real rintl(real x) { return rint(x); }
int lrintl(real x) { return lrint(x); }
long llrintl(real x) { return llrint(x); }
//real roundl(real x) { return round(x); }
//int lroundl(real x) { return lround(x); }
//long llroundl(real x) { return llround(x); }
//real truncl(real x) { return trunc(x); }
real fmodl(real x, real y) { return fmod(x, y); }
real remainderl(real x, real y) { return remainder(x, y); }
real remquol(real x, real y, int* quo) { return remquo(x, y, quo); }
real copysignl(real x, real y) { return copysign(x, y); }
real nanl(char *tagp) { return real.nan; }
//real nextafterl(real x, real y) { return nextafter(x, y); }
//real nexttowardl(real x, real y) { return nexttoward(x, y); }
//real fdiml(real x, real y) { return fdim(x, y); }
//real fmaxl(real x, real y) { return fmax(x, y); }
//real fminl(real x, real y) { return fmin(x, y); }
//real fmal(real x, real y, real z) { return fma(x, y, z); }

197
std/c/freebsd/pthread.d Normal file
View file

@ -0,0 +1,197 @@
/* Written by Walter Bright
* http://www.digitalmars.com
* Placed into public domain.
*/
module std.c.freebsd.pthread;
version (FreeBSD) { } else { static assert(0); }
import std.c.freebsd.freebsd;
extern (C):
enum
{
PTHREAD_DESTRUCTOR_ITERATIONS = 4,
PTHREAD_KEYS_MAX = 256,
PTHREAD_STACK_MIN = 2048,
PTHREAD_THREADS_MAX = uint.max,
PTHREAD_BARRIER_SERIAL_THREAD = -1
}
enum
{
PTHREAD_DETACHED = 1,
PTHREAD_SCOPE_SYSTEM = 2,
PTHREAD_INHERIT_SCHED = 4,
PTHREAD_NOFLOAT = 8,
PTHREAD_CREATE_DETACHED = PTHREAD_DETACHED,
PTHREAD_CREATE_JOINABLE = 0,
PTHREAD_SCOPE_PROCESS = 0,
PTHREAD_EXPLICIT_SCHED = 0
}
enum
{
PTHREAD_PROCESS_PRIVATE = 0,
PTHREAD_PROCESS_SHARED = 1
}
enum
{
PTHREAD_CANCEL_ENABLE = 0,
PTHREAD_CANCEL_DISABLE = 1,
PTHREAD_CANCEL_DEFERRED = 0,
PTHREAD_CANCEL_ASYNCHRONOUS = 2,
PTHREAD_CANCELED = cast(void*)1
}
enum
{
PTHREADS_NEEDS_INIT = 0,
PTHREAD_DONE_INIT = 1
}
enum
{
PTHREAD_PRIO_NONE = 0,
PTHREAD_PRIO_INHERIT = 1,
PTHREAD_PRIO_PROTECT = 2
}
enum pthread_mutextype
{
PTHREAD_MUTEX_ERRORCHECK = 1,
PTHREAD_MUTEX_RECURSIVE = 2,
PTHREAD_MUTEX_NORMAL = 3,
PTHREAD_MUTEX_ADAPTIVE_NP = 4,
PTHREAD_MUTEX_TYPE_MAX,
PTHREAD_MUTEX_DEFAULT = PTHREAD_MUTEX_ERRORCHECK
}
typedef void* pthread_t;
typedef void* pthread_attr_t;
typedef void* pthread_mutex_t;
typedef void* pthread_mutexattr_t;
typedef void* pthread_cond_t;
typedef void* pthread_condattr_t;
typedef int pthread_key_t;
typedef void* pthread_rwlock_t;
typedef void* pthread_rwlockattr_t;
typedef void* pthread_barrier_t;
typedef void* pthread_barrierattr_t;
typedef void* pthread_spinlock_t;
typedef void* pthread_addr_t;
alias void* function(void*) pthread_startroutine_t;
struct pthread_once_t
{
int state;
pthread_mutex_t mutex;
}
int pthread_atfork(void function(), void function(), void function());
int pthread_attr_destroy(pthread_attr_t*);
int pthread_attr_getdetachstate(in pthread_attr_t*, int*);
int pthread_attr_getguardsize(in pthread_attr_t*, size_t*);
int pthread_attr_getinheritsched(in pthread_attr_t*, int*);
int pthread_attr_getschedparam(in pthread_attr_t*, sched_param*);
int pthread_attr_getschedpolicy(in pthread_attr_t*, int*);
int pthread_attr_getscope(in pthread_attr_t*, int*);
int pthread_attr_getstack(in pthread_attr_t*, void**, size_t*);
int pthread_attr_getstackaddr(in pthread_attr_t*, void**);
int pthread_attr_getstacksize(in pthread_attr_t*, size_t*);
int pthread_attr_init(pthread_attr_t*);
int pthread_attr_setdetachstate(pthread_attr_t*, int);
int pthread_attr_setguardsize(pthread_attr_t*, size_t);
int pthread_attr_setinheritsched(pthread_attr_t*, int);
int pthread_attr_setschedparam(pthread_attr_t*, in sched_param*);
int pthread_attr_setschedpolicy(pthread_attr_t*, int);
int pthread_attr_setscope(pthread_attr_t*, int);
int pthread_attr_setstack(pthread_attr_t*, void*, size_t);
int pthread_attr_setstackaddr(pthread_attr_t*, void*);
int pthread_attr_setstacksize(pthread_attr_t*, size_t);
int pthread_barrier_destroy(pthread_barrier_t*);
int pthread_barrier_init(pthread_barrier_t*, in pthread_barrierattr_t*, uint);
int pthread_barrier_wait(pthread_barrier_t*);
int pthread_barrierattr_destroy(pthread_barrierattr_t*);
int pthread_barrierattr_getpshared(in pthread_barrierattr_t*, int*);
int pthread_barrierattr_init(pthread_barrierattr_t*);
int pthread_barrierattr_setpshared(pthread_barrierattr_t*, int);
int pthread_cancel(pthread_t);
int pthread_cond_broadcast(pthread_cond_t*);
int pthread_cond_destroy(pthread_cond_t*);
int pthread_cond_init(pthread_cond_t*, in pthread_condattr_t*);
int pthread_cond_signal(pthread_cond_t*);
int pthread_cond_timedwait(pthread_cond_t*, pthread_mutex_t*, in timespec*);
int pthread_cond_wait(pthread_cond_t*, pthread_mutex_t*);
int pthread_condattr_destroy(pthread_condattr_t*);
int pthread_condattr_getclock(in pthread_condattr_t*, clockid_t*);
int pthread_condattr_getpshared(in pthread_condattr_t*, int*);
int pthread_condattr_init(pthread_condattr_t*);
int pthread_condattr_setclock(pthread_condattr_t*, clockid_t);
int pthread_condattr_setpshared(pthread_condattr_t*, int);
int pthread_create(pthread_t*, in pthread_attr_t*, void* function(void*), void*);
int pthread_detach(pthread_t);
int pthread_equal(pthread_t, pthread_t);
int pthread_getconcurrency();
int pthread_getprio(pthread_t);
int pthread_getschedparam(pthread_t pthread, int*, sched_param*);
int pthread_join(pthread_t, void**);
int pthread_key_create(pthread_key_t*, void function(void*));
int pthread_key_delete(pthread_key_t);
int pthread_kill(pthread_t, int);
int pthread_mutex_destroy(pthread_mutex_t*);
int pthread_mutex_getprioceiling(pthread_mutex_t*, int*);
int pthread_mutex_init(pthread_mutex_t*, in pthread_mutexattr_t*);
int pthread_mutex_lock(pthread_mutex_t*);
int pthread_mutex_setprioceiling(pthread_mutex_t*, int, int*);
int pthread_mutex_timedlock(pthread_mutex_t*, in timespec*);
int pthread_mutex_trylock(pthread_mutex_t*);
int pthread_mutex_unlock(pthread_mutex_t*);
int pthread_mutexattr_destroy(pthread_mutexattr_t*);
int pthread_mutexattr_getprioceiling(pthread_mutexattr_t*, int*);
int pthread_mutexattr_getprotocol(pthread_mutexattr_t*, int*);
int pthread_mutexattr_getpshared(in pthread_mutexattr_t*, int*);
int pthread_mutexattr_gettype(pthread_mutexattr_t*, int*);
int pthread_mutexattr_init(pthread_mutexattr_t*);
int pthread_mutexattr_setprioceiling(pthread_mutexattr_t*, int);
int pthread_mutexattr_setprotocol(pthread_mutexattr_t*, int);
int pthread_mutexattr_setpshared(pthread_mutexattr_t*, int);
int pthread_mutexattr_settype(pthread_mutexattr_t*, int);
int pthread_once(pthread_once_t*, void function());
int pthread_rwlock_destroy(pthread_rwlock_t*);
int pthread_rwlock_init(pthread_rwlock_t*, in pthread_rwlockattr_t*);
int pthread_rwlock_rdlock(pthread_rwlock_t*);
int pthread_rwlock_timedrdlock(pthread_rwlock_t*, in timespec*);
int pthread_rwlock_timedwrlock(pthread_rwlock_t*, in timespec*);
int pthread_rwlock_tryrdlock(pthread_rwlock_t*);
int pthread_rwlock_trywrlock(pthread_rwlock_t*);
int pthread_rwlock_unlock(pthread_rwlock_t*);
int pthread_rwlock_wrlock(pthread_rwlock_t*);
int pthread_rwlockattr_destroy(pthread_rwlockattr_t*);
int pthread_rwlockattr_getpshared(in pthread_rwlockattr_t*, int*);
int pthread_rwlockattr_init(pthread_rwlockattr_t*);
int pthread_rwlockattr_setpshared(pthread_rwlockattr_t*, int);
int pthread_setcancelstate(int, int*);
int pthread_setcanceltype(int, int*);
int pthread_setconcurrency(int);
int pthread_setprio(pthread_t, int);
int pthread_setschedparam(pthread_t, int, in sched_param*);
int pthread_setspecific(pthread_key_t, in void*);
int pthread_sigmask(int, in __sigset_t*, __sigset_t*);
int pthread_spin_destroy(pthread_spinlock_t*);
int pthread_spin_init(pthread_spinlock_t*, int);
int pthread_spin_lock(pthread_spinlock_t*);
int pthread_spin_trylock(pthread_spinlock_t*);
int pthread_spin_unlock(pthread_spinlock_t*);
pthread_t pthread_self();
void pthread_cleanup_pop(int);
void pthread_cleanup_push(void function(void*), void*);
void pthread_exit(void*);
void pthread_testcancel();
void pthread_yield();
void* pthread_getspecific(pthread_key_t);

390
std/c/freebsd/socket.d Normal file
View file

@ -0,0 +1,390 @@
/*
Written by Christopher E. Miller
Placed into public domain.
*/
module std.c.freebsd.socket;
private import std.stdint;
private import std.c.freebsd.freebsd;
version (FreeBSD) { } else { static assert(0); }
extern(C):
alias uint socklen_t;
enum: int
{
AF_UNSPEC = 0,
AF_UNIX = 1,
AF_INET = 2,
AF_IPX = 23,
AF_APPLETALK = 16,
AF_INET6 = 28,
// ...
PF_UNSPEC = AF_UNSPEC,
PF_UNIX = AF_UNIX,
PF_INET = AF_INET,
PF_IPX = AF_IPX,
PF_APPLETALK = AF_APPLETALK,
PF_INET6 = AF_INET6,
}
enum: int
{
SOL_SOCKET = 0xFFFF,
}
enum: int
{
SO_DEBUG = 1,
SO_BROADCAST = 0x20,
SO_REUSEADDR = 4,
SO_LINGER = 0x80,
//SO_DONTLINGER = ~SO_LINGER,
SO_OOBINLINE = 0x100,
SO_SNDBUF = 0x1001,
SO_RCVBUF = 0x1002,
SO_ACCEPTCONN = 2,
SO_DONTROUTE = 0x10,
SO_TYPE = 0x1008,
// netinet/tcp.h
TCP_NODELAY = 1,
// netinet/in.h
IP_MULTICAST_LOOP = 11,
IP_ADD_MEMBERSHIP = 12,
IP_DROP_MEMBERSHIP = 13,
// netinet6/in6.h
//IPV6_ADDRFORM = 1,
IPV6_PKTINFO = 46,
IPV6_HOPOPTS = 49,
IPV6_DSTOPTS = 50,
IPV6_RTHDR = 51,
IPV6_PKTOPTIONS = 52,
IPV6_CHECKSUM = 26,
IPV6_HOPLIMIT = 47,
IPV6_NEXTHOP = 48,
//IPV6_AUTHHDR = 10,
IPV6_UNICAST_HOPS = 4,
IPV6_MULTICAST_IF = 9,
IPV6_MULTICAST_HOPS = 10,
IPV6_MULTICAST_LOOP = 11,
IPV6_JOIN_GROUP = 12,
IPV6_LEAVE_GROUP = 13,
//IPV6_ROUTER_ALERT = 22,
//IPV6_MTU_DISCOVER = 23,
//IPV6_MTU = 24,
//IPV6_RECVERR = 25,
IPV6_V6ONLY = 27,
//IPV6_JOIN_ANYCAST = 27,
//IPV6_LEAVE_ANYCAST = 28,
IPV6_IPSEC_POLICY = 28,
//IPV6_XFRM_POLICY = 35,
}
// sys/socket.h
enum: int
{
MSG_OOB = 0x1,
MSG_PEEK = 0x2,
MSG_DONTROUTE = 0x4,
MSG_NOSIGNAL = 0x20000,
}
enum: int
{
SHUT_RD = 0,
SHUT_WR = 1,
SHUT_RDWR = 2,
}
enum: int // not defined in FreeBSD, but we'll do it
{
SD_RECEIVE = SHUT_RD,
SD_SEND = SHUT_WR,
SD_BOTH = SHUT_RDWR,
}
alias ubyte sa_family_t;
struct sockaddr
{
ubyte sa_len;
sa_family_t sa_family;
ubyte[14] sa_data;
}
alias uint in_addr_t;
alias ushort in_port_t;
// netinet/in.h
struct sockaddr_in
{
ubyte sin_len;
sa_family_t sin_family;
in_port_t sin_port;
in_addr sin_addr;
ubyte[8] sin_zero;
}
// netinet6/in6.h
struct sockaddr_in6
{
ubyte sin6_len;
sa_family_t sin6_family;
in_port_t sin6_port;
uint sin6_flowinfo;
in6_addr sin6_addr;
uint sin6_scope_id;
}
// netdb.h
struct addrinfo
{
int ai_flags;
int ai_family;
int ai_socktype;
int ai_protocol;
socklen_t ai_addrlen;
char* ai_canonname;
sockaddr* ai_addr;
addrinfo* ai_next;
}
// fcntl.h
const int F_GETFL = 3;
const int F_SETFL = 4;
int socket(int af, int type, int protocol);
int bind(int s, /*const*/ sockaddr* name, int namelen);
int connect(int s, /*const*/ sockaddr* name, int namelen);
int listen(int s, int backlog);
int accept(int s, sockaddr* addr, int* addrlen);
int shutdown(int s, int how);
int getpeername(int s, sockaddr* name, int* namelen);
int getsockname(int s, sockaddr* name, int* namelen);
int send(int s, void* buf, int len, int flags);
int sendto(int s, void* buf, int len, int flags, sockaddr* to, int tolen);
int recv(int s, void* buf, int len, int flags);
int recvfrom(int s, void* buf, int len, int flags, sockaddr* from, int* fromlen);
int getsockopt(int s, int level, int optname, void* optval, int* optlen);
int setsockopt(int s, int level, int optname, void* optval, int optlen);
uint inet_addr(char* cp);
char* inet_ntoa(in_addr ina);
hostent* gethostbyname(char* name);
int gethostbyname_r(char* name, hostent* ret, void* buf, size_t buflen, hostent** result, int* h_errnop);
int gethostbyname2_r(char* name, int af, hostent* ret, void* buf, size_t buflen, hostent** result, int* h_errnop);
hostent* gethostbyaddr(void* addr, int len, int type);
protoent* getprotobyname(char* name);
protoent* getprotobynumber(int number);
servent* getservbyname(char* name, char* proto);
servent* getservbyport(int port, char* proto);
int gethostname(char* name, int namelen);
int getaddrinfo(char* nodename, char* servname, addrinfo* hints, addrinfo** res);
void freeaddrinfo(addrinfo* ai);
int getnameinfo(sockaddr* sa, socklen_t salen, char* node, socklen_t nodelen, char* service, socklen_t servicelen, int flags);
struct linger
{
int l_onoff;
int l_linger;
}
// netdb.h
struct protoent
{
char* p_name;
char** p_aliases;
int p_proto;
}
// netdb.h
struct servent
{
char* s_name;
char** s_aliases;
int s_port;
char* s_proto;
}
version(BigEndian)
{
ushort htons(ushort x)
{
return x;
}
uint htonl(uint x)
{
return x;
}
}
else version(LittleEndian)
{
private import std.intrinsic;
ushort htons(ushort x)
{
return cast(ushort)((x >> 8) | (x << 8));
}
uint htonl(uint x)
{
return bswap(x);
}
}
else
{
static assert(0);
}
ushort ntohs(ushort x)
{
return htons(x);
}
uint ntohl(uint x)
{
return htonl(x);
}
enum: int
{
SOCK_STREAM = 1,
SOCK_DGRAM = 2,
SOCK_RAW = 3,
SOCK_RDM = 4,
SOCK_SEQPACKET = 5,
}
// netinet/in.h
enum: int
{
IPPROTO_IP = 0,
IPPROTO_ICMP = 1,
IPPROTO_IGMP = 2,
IPPROTO_GGP = 3,
IPPROTO_TCP = 6,
IPPROTO_PUP = 12,
IPPROTO_UDP = 17,
IPPROTO_IDP = 22,
IPPROTO_IPV6 = 41,
IPPROTO_ND = 77,
IPPROTO_RAW = 255,
IPPROTO_MAX = 256,
}
enum: uint
{
INADDR_ANY = 0,
INADDR_LOOPBACK = 0x7F000001,
INADDR_BROADCAST = 0xFFFFFFFF,
INADDR_NONE = 0xFFFFFFFF,
ADDR_ANY = INADDR_ANY,
}
// netdb.h
enum: int
{
AI_PASSIVE = 0x1,
AI_CANONNAME = 0x2,
AI_NUMERICHOST = 0x4,
AI_NUMERICSERV = 8,
}
union in_addr
{
private union _S_un_t
{
private struct _S_un_b_t
{
uint8_t s_b1, s_b2, s_b3, s_b4;
}
_S_un_b_t S_un_b;
private struct _S_un_w_t
{
ushort s_w1, s_w2;
}
_S_un_w_t S_un_w;
uint S_addr;
}
_S_un_t S_un;
uint s_addr;
struct
{
uint8_t s_net, s_host;
union
{
ushort s_imp;
struct
{
uint8_t s_lh, s_impno;
}
}
}
}
union in6_addr
{
private union _in6_u_t
{
uint8_t[16] u6_addr8;
ushort[8] u6_addr16;
uint[4] u6_addr32;
}
_in6_u_t in6_u;
uint8_t[16] s6_addr8;
ushort[8] s6_addr16;
uint[4] s6_addr32;
}
const in6_addr IN6ADDR_ANY = { s6_addr8: [0] };
const in6_addr IN6ADDR_LOOPBACK = { s6_addr8: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1] };
//alias IN6ADDR_ANY IN6ADDR_ANY_INIT;
//alias IN6ADDR_LOOPBACK IN6ADDR_LOOPBACK_INIT;
const uint INET_ADDRSTRLEN = 16;
const uint INET6_ADDRSTRLEN = 46;
// netdb.h
struct hostent
{
char* h_name;
char** h_aliases;
int h_addrtype;
int h_length;
char** h_addr_list;
char* h_addr()
{
return h_addr_list[0];
}
}

View file

@ -8,6 +8,12 @@
module std.c.linux.linux;
version (FreeBSD)
{
public import std.c.freebsd.freebsd;
}
else
{
public import std.c.linux.linuxextern;
public import std.c.linux.pthread;
@ -682,3 +688,4 @@ extern (C)
int utime(char* filename, utimbuf* buf);
}
}

View file

@ -1,10 +1,17 @@
/* Written by Walter Bright, Christopher E. Miller, and many others.
* www.digitalmars.com
* http://www.digitalmars.com
* Placed into public domain.
*/
module std.c.linux.pthread;
version (FreeBSD)
{
public import std.c.freebsd.pthread;
}
else
{
import std.c.linux.linux;
extern (C):
@ -386,3 +393,5 @@ version(linux)
void _pthread_cleanup_push_defer(_pthread_cleanup_buffer*, void function(void*), void*);
void _pthread_cleanup_pop(_pthread_cleanup_buffer*, int);
void _pthread_cleanup_pop_restore(_pthread_cleanup_buffer*, int);
}

View file

@ -6,6 +6,13 @@
module std.c.linux.socket;
version (FreeBSD)
{
public import std.c.freebsd.socket;
}
else
{
private import std.stdint;
private import std.c.linux.linux;
@ -509,3 +516,4 @@ struct hostent
}
}
}

View file

@ -1147,6 +1147,12 @@ void getTimes(string name, out d_time ftc, out d_time fta, out d_time ftm)
fta = cast(d_time)statbuf.st_atimespec.tv_sec * std.date.TicksPerSecond;
ftm = cast(d_time)statbuf.st_mtimespec.tv_sec * std.date.TicksPerSecond;
}
else version (FreeBSD)
{ // BUG: should add in tv_nsec field
ftc = cast(d_time)statbuf.st_ctimespec.tv_sec * std.date.TicksPerSecond;
fta = cast(d_time)statbuf.st_atimespec.tv_sec * std.date.TicksPerSecond;
ftm = cast(d_time)statbuf.st_mtimespec.tv_sec * std.date.TicksPerSecond;
}
else
{
static assert(0);
@ -1341,6 +1347,12 @@ struct DirEntry
_lastAccessTime = cast(d_time)statbuf.st_atimespec.tv_sec * std.date.TicksPerSecond;
_lastWriteTime = cast(d_time)statbuf.st_mtimespec.tv_sec * std.date.TicksPerSecond;
}
else version (FreeBSD)
{
_creationTime = cast(d_time)statbuf.st_ctimespec.tv_sec * std.date.TicksPerSecond;
_lastAccessTime = cast(d_time)statbuf.st_atimespec.tv_sec * std.date.TicksPerSecond;
_lastWriteTime = cast(d_time)statbuf.st_mtimespec.tv_sec * std.date.TicksPerSecond;
}
else
{
static assert(0);
@ -1532,6 +1544,11 @@ void copy(string from, string to)
utim.actime = cast(__time_t)statbuf.st_atimespec.tv_sec;
utim.modtime = cast(__time_t)statbuf.st_mtimespec.tv_sec;
}
else version (FreeBSD)
{
utim.actime = cast(__time_t)statbuf.st_atimespec.tv_sec;
utim.modtime = cast(__time_t)statbuf.st_mtimespec.tv_sec;
}
else
{
static assert(0);

View file

@ -83,6 +83,9 @@ version(GNU){
}
}
version(DigitalMars){
version=INLINE_YL2X; // x87 has opcodes for these
}
private:
/*
@ -1223,7 +1226,18 @@ real ldexp(real n, int exp); /* intrinsic */
* )
*/
real log(real x) { return std.c.math.logl(x); }
real log(real x)
{
version (INLINE_YL2X)
return yl2x(x, LN2);
else
return std.c.math.logl(x);
}
unittest
{
assert(log(E) == 1);
}
/**************************************
* Calculate the base-10 logarithm of x.
@ -1235,7 +1249,19 @@ real log(real x) { return std.c.math.logl(x); }
* $(TR $(TD +$(INFIN)) $(TD +$(INFIN)) $(TD no) $(TD no))
* )
*/
real log10(real x) { return std.c.math.log10l(x); }
real log10(real x)
{
version (INLINE_YL2X)
return yl2x(x, LOG2);
else
return std.c.math.log10l(x);
}
unittest
{
assert(log10(1000) == 3);
}
/******************************************
* Calculates the natural logarithm of 1 + x.
@ -1265,7 +1291,14 @@ real log1p(real x) { return std.c.math.log1pl(x); }
* $(TR $(TD +$(INFIN)) $(TD +$(INFIN)) $(TD no) $(TD no) )
* )
*/
real log2(real x) { return std.c.math.log2l(x); }
real log2(real x)
{
version (INLINE_YL2X)
return yl2x(x, 1);
else
return std.c.math.log2l(x);
}
/*****************************************
* Extracts the exponent of x as a signed integral value.
@ -2791,6 +2824,34 @@ body
;
}
}
else version (FreeBSD)
{
asm // assembler by W. Bright
{
// EDX = (A.length - 1) * real.sizeof
mov ECX,A[EBP] ; // ECX = A.length
dec ECX ;
lea EDX,[ECX*8] ;
lea EDX,[EDX][ECX*4] ;
add EDX,A+4[EBP] ;
fld real ptr [EDX] ; // ST0 = coeff[ECX]
jecxz return_ST ;
fld x[EBP] ; // ST0 = x
fxch ST(1) ; // ST1 = x, ST0 = r
align 4 ;
L2: fmul ST,ST(1) ; // r *= x
fld real ptr -12[EDX] ;
sub EDX,12 ; // deg--
faddp ST(1),ST ;
dec ECX ;
jne L2 ;
fxch ST(1) ; // ST1 = r, ST0 = x
fstp ST(0) ; // dump x
align 4 ;
return_ST: ;
;
}
}
else
{
static assert(0);
@ -2817,3 +2878,22 @@ unittest
assert( poly(x, pp) == (56.1L + (32.7L + 6L * x) * x) );
}
/* **********************************
* Building block functions, they
* translate to a single x87 instruction.
*/
real yl2x(real x, real y); // y * log2(x)
real yl2xp1(real x, real y); // y * log2(x + 1)
unittest
{
version (INLINE_YL2X)
{
assert(yl2x(1024, 1) == 10);
assert(yl2xp1(1023, 1) == 10);
}
}

View file

@ -307,6 +307,7 @@ class MmFile
fd = -1;
version (linux) flags |= MAP_ANONYMOUS;
else version (OSX) flags |= MAP_ANON;
else version (FreeBSD) flags |= MAP_ANON;
else static assert(0);
}
this.size = size;

View file

@ -77,6 +77,19 @@ version (linux)
extern (C) ModuleReference *_Dmodule_ref; // start of linked list
}
version (FreeBSD)
{
// This linked list is created by a compiler generated function inserted
// into the .ctor list by the compiler.
struct ModuleReference
{
ModuleReference* next;
ModuleInfo mod;
}
extern (C) ModuleReference *_Dmodule_ref; // start of linked list
}
version (OSX)
{
extern (C)
@ -115,6 +128,21 @@ extern (C) void _moduleCtor()
}
}
version (FreeBSD)
{
int len = 0;
ModuleReference *mr;
for (mr = _Dmodule_ref; mr; mr = mr.next)
len++;
_moduleinfo_array = new ModuleInfo[len];
len = 0;
for (mr = _Dmodule_ref; mr; mr = mr.next)
{ _moduleinfo_array[len] = mr.mod;
len++;
}
}
version (OSX)
{ /* The ModuleInfo references are stored in the special segment
* __minfodata, which is bracketed by the segments __minfo_beg

View file

@ -65,8 +65,12 @@ else version(BsdSockets)
{
version(Posix)
{
private import std.c.linux.linux, std.c.linux.socket;
private alias std.c.linux.linux.timeval _ctimeval;
version (FreeBSD)
private import std.c.freebsd.socket;
else
private import std.c.linux.socket;
private import std.c.linux.linux;
private alias std.c.linux.linux.timeval _ctimeval;
}
typedef int32_t socket_t = -1;
@ -113,6 +117,16 @@ class SocketException: Exception
cs = "Unknown error";
}
}
else version (FreeBSD)
{
auto errs = strerror_r(errorCode, buf.ptr, buf.length);
if (errs == 0)
cs = buf.ptr;
else
{
cs = "Unknown error";
}
}
else
{
static assert(0);

View file

@ -48,6 +48,11 @@ version (OSX)
version = GENERIC_IO;
}
version (FreeBSD)
{
version = GENERIC_IO;
}
version (DIGITAL_MARS_STDIO)
{
extern (C)

View file

@ -20,13 +20,14 @@ const
Win32 = 1, // Microsoft 32 bit Windows systems
linux, // all linux systems
OSX,
FreeBSD,
}
version (Win32)
{
Family family = Family.Win32;
}
else version (Posix)
else version (linux)
{
Family family = Family.linux;
}
@ -34,6 +35,10 @@ const
{
Family family = Family.OSX;
}
else version (FreeBSD)
{
Family family = Family.FreeBSD;
}
else
{
static assert(0);
@ -51,6 +56,7 @@ const
RedHatLinux,
OSX,
FreeBSD,
}
/// Byte order endianness

View file

@ -530,9 +530,16 @@ void *os_query_stackBottom()
version (Posix)
{
private import std.c.linux.linux;
private import std.c.linux.linuxextern;
private import std.c.linux.pthread;
version (FreeBSD)
{
private import std.c.freebsd.freebsd;
private import std.c.freebsd.pthread;
}
else
{
private import std.c.linux.linux;
private import std.c.linux.pthread;
}
version (OSX)
{

View file

@ -64,6 +64,9 @@ OBJS= deh.obj complex.obj gcstats.obj \
# ti_bit.obj ti_Abit.obj
MAKEFILES= \
win32.mak linux.mak osx.mak freebsd.mak
SRCS= std\math.d std\stdio.d std\dateparse.d std\date.d std\uni.d std\string.d \
std\base64.d std\md5.d std\regexp.d \
std\compiler.d std\cpuid.d std\format.d std\demangle.d \
@ -246,6 +249,10 @@ SRC_STD_C_LINUX= std\c\linux\linux.d std\c\linux\linuxextern.d \
SRC_STD_C_OSX= std\c\osx\osx.d
SRC_STD_C_FREEBSD= std\c\freebsd\freebsd.d \
std\c\freebsd\socket.d std\c\freebsd\pthread.d \
std\c\freebsd\math.d
SRC_ETC= etc\gamma.d
SRC_ETC_C= etc\c\zlib.d
@ -281,7 +288,8 @@ SRC_ZLIB= etc\c\zlib\trees.h \
etc\c\zlib\README \
etc\c\zlib\win32.mak \
etc\c\zlib\linux.mak \
etc\c\zlib\osx.mak
etc\c\zlib\osx.mak \
etc\c\zlib\freebsd.mak
SRC_GC= internal\gc\gc.d \
internal\gc\gcold.d \
@ -294,7 +302,8 @@ SRC_GC= internal\gc\gc.d \
internal\gc\testgc.d \
internal\gc\win32.mak \
internal\gc\linux.mak \
internal\gc\osx.mak
internal\gc\osx.mak \
internal\gc\freebsd.mak
phobos.lib : $(OBJS) $(SRCS) minit.obj internal\gc\dmgc.lib \
etc\c\zlib\zlib.lib win32.mak
@ -884,11 +893,11 @@ $(DOC)\std_c_wcharh.html : std.ddoc std\c\wcharh.d
######################################################
zip : win32.mak linux.mak osx.mak phoboslicense.txt std.ddoc $(SRC) \
zip : $(MAKEFILES) phoboslicense.txt std.ddoc $(SRC) \
$(SRC_STD) $(SRC_STD_C) $(SRC_TI) $(SRC_INT) $(SRC_STD_WIN) \
$(SRC_STDLINUX) $(SRC_ETC) $(SRC_ETC_C) $(SRC_ZLIB) $(SRC_GC)
del phobos.zip
zip32 -u phobos win32.mak linux.mak osx.mak std.ddoc
zip32 -u phobos $(MAKEFILES) std.ddoc
zip32 -u phobos $(SRC)
zip32 -u phobos $(SRC_TI)
zip32 -u phobos $(SRC_INT)
@ -912,7 +921,7 @@ cleanhtml:
install:
$(CP) phobos.lib gcstub.obj $(DIR)\windows\lib
$(CP) win32.mak linux.mak osx.mak phoboslicense.txt minit.obj std.ddoc $(DIR)\src\phobos
$(CP) $(MAKEFILES) phoboslicense.txt minit.obj std.ddoc $(DIR)\src\phobos
$(CP) $(SRC) $(DIR)\src\phobos
$(CP) $(SRC_STD) $(DIR)\src\phobos\std
$(CP) $(SRC_STD_C) $(DIR)\src\phobos\std\c
@ -922,6 +931,7 @@ install:
$(CP) $(SRC_STD_C_WIN) $(DIR)\src\phobos\std\c\windows
$(CP) $(SRC_STD_C_LINUX) $(DIR)\src\phobos\std\c\linux
$(CP) $(SRC_STD_C_OSX) $(DIR)\src\phobos\std\c\osx
$(CP) $(SRC_STD_C_FREEBSD) $(DIR)\src\phobos\std\c\freebsd
$(CP) $(SRC_ETC) $(DIR)\src\phobos\etc
$(CP) $(SRC_ETC_C) $(DIR)\src\phobos\etc\c
$(CP) $(SRC_ZLIB) $(DIR)\src\phobos\etc\c\zlib