Explorar o código

* a new qod port of the freebsd rtl. To be refined in the coming days.

marco %!s(int64=21) %!d(string=hai) anos
pai
achega
d3e862638f

+ 45 - 228
rtl/netbsd/Makefile

@@ -1,8 +1,8 @@
 #
-# Don't edit, this file is generated by FPCMake Version 1.1 [2003/10/28]
+# Don't edit, this file is generated by FPCMake Version 1.1 [2002/05/20]
 #
 default: all
-MAKEFILETARGETS=linux go32v2 win32 os2 freebsd beos netbsd amiga atari sunos qnx netware openbsd wdosx palmos macos darwin emx watcom
+MAKEFILETARGETS=linux go32v2 win32 os2 freebsd beos netbsd amiga atari sunos qnx netware
 override PATH:=$(subst \,/,$(PATH))
 ifeq ($(findstring ;,$(PATH)),)
 inUnix=1
@@ -10,7 +10,6 @@ SEARCHPATH:=$(filter-out .,$(subst :, ,$(PATH)))
 else
 SEARCHPATH:=$(subst ;, ,$(PATH))
 endif
-SEARCHPATH+=$(patsubst %/,%,$(subst \,/,$(dir $(MAKE))))
 PWD:=$(strip $(wildcard $(addsuffix /pwd.exe,$(SEARCHPATH))))
 ifeq ($(PWD),)
 PWD:=$(strip $(wildcard $(addsuffix /pwd,$(SEARCHPATH))))
@@ -33,7 +32,7 @@ inOS2=1
 endif
 endif
 else
-ifneq ($(findstring cygdrive,$(PATH)),)
+ifneq ($(findstring cygwin,$(MACHTYPE)),)
 inCygWin=1
 endif
 endif
@@ -43,9 +42,6 @@ endif
 ifeq ($(OS_TARGET),netbsd)
 BSDhier=1
 endif
-ifeq ($(OS_TARGET),openbsd)
-BSDhier=1
-endif
 ifdef inUnix
 BATCHEXT=.sh
 else
@@ -59,9 +55,6 @@ ifdef inUnix
 PATHSEP=/
 else
 PATHSEP:=$(subst /,\,/)
-ifdef inCygWin
-PATHSEP=/
-endif
 endif
 ifdef PWD
 BASEDIR:=$(subst \,/,$(shell $(PWD)))
@@ -91,7 +84,7 @@ endif
 endif
 export ECHO
 endif
-override OS_TARGET_DEFAULT=netbsd
+OS_TARGET=netbsd
 override DEFAULT_FPCDIR=../..
 ifndef FPC
 ifdef PP
@@ -113,38 +106,37 @@ endif
 override FPC:=$(subst $(SRCEXEEXT),,$(FPC))
 override FPC:=$(subst \,/,$(FPC))$(SRCEXEEXT)
 ifndef FPC_VERSION
-FPC_COMPILERINFO:=$(shell $(FPC) -iVSPTPSOTO)
-FPC_VERSION:=$(word 1,$(FPC_COMPILERINFO))
+FPC_VERSION:=$(shell $(FPC) -iV)
 endif
-export FPC FPC_VERSION FPC_COMPILERINFO
+export FPC FPC_VERSION
 unexport CHECKDEPEND ALLDEPENDENCIES
+ifeq ($(findstring 1.0.,$(FPC_VERSION)),)
+COMPILERINFO:=$(shell $(FPC) -iSP -iTP -iSO -iTO)
+ifndef CPU_SOURCE
+CPU_SOURCE:=$(word 1,$(COMPILERINFO))
+endif
 ifndef CPU_TARGET
-ifdef CPU_TARGET_DEFAULT
-CPU_TARGET=$(CPU_TARGET_DEFAULT)
+CPU_TARGET:=$(word 2,$(COMPILERINFO))
 endif
+ifndef OS_SOURCE
+OS_SOURCE:=$(word 3,$(COMPILERINFO))
 endif
 ifndef OS_TARGET
-ifdef OS_TARGET_DEFAULT
-OS_TARGET=$(OS_TARGET_DEFAULT)
-endif
-endif
-ifneq ($(words $(FPC_COMPILERINFO)),5)
-FPC_COMPILERINFO+=$(shell $(FPC) -iSP)
-FPC_COMPILERINFO+=$(shell $(FPC) -iTP)
-FPC_COMPILERINFO+=$(shell $(FPC) -iSO)
-FPC_COMPILERINFO+=$(shell $(FPC) -iTO)
+OS_TARGET:=$(word 4,$(COMPILERINFO))
 endif
+else
 ifndef CPU_SOURCE
-CPU_SOURCE:=$(word 2,$(FPC_COMPILERINFO))
+CPU_SOURCE:=$(shell $(FPC) -iSP)
 endif
 ifndef CPU_TARGET
-CPU_TARGET:=$(word 3,$(FPC_COMPILERINFO))
+CPU_TARGET:=$(shell $(FPC) -iTP)
 endif
 ifndef OS_SOURCE
-OS_SOURCE:=$(word 4,$(FPC_COMPILERINFO))
+OS_SOURCE:=$(shell $(FPC) -iSO)
 endif
 ifndef OS_TARGET
-OS_TARGET:=$(word 5,$(FPC_COMPILERINFO))
+OS_TARGET:=$(shell $(FPC) -iTO)
+endif
 endif
 FULL_TARGET=$(CPU_TARGET)-$(OS_TARGET)
 FULL_SOURCE=$(CPU_SOURCE)-$(OS_SOURCE)
@@ -219,7 +211,7 @@ LINUXUNIT=
 PRT0=prt0
 else
 SYSTEMUNIT=sysbsd
-LINUXUNIT=linux
+LINUXUNIT=
 override FPCOPT+=-dUNIX
 PRT0=prt0_10
 endif
@@ -231,14 +223,9 @@ GRAPHDIR=$(INC)/graph
 ifndef USELIBGGI
 USELIBGGI=NO
 endif
-override TARGET_UNITS+=$(SYSTEMUNIT) objpas strings baseunix $(LINUXUNIT) unix initc dos crt objects printer sysutils classes typinfo math varutils charset ucomplex getopts heaptrc lineinfo errors sockets gpm ipc terminfo video mouse keyboard  serial variants types systhrds sysctl
-ifeq ($(OS_TARGET),netbsd)
-ifeq ($(CPU_TARGET),i386)
-override TARGET_UNITS+=mmx cpu
-endif
-endif
+override TARGET_UNITS+=$(SYSTEMUNIT) objpas strings syscall baseunix $(LINUXUNIT) unix initc systhrds dos crt objects printer sysutils classes typinfo math varutils charset ucomplex getopts heaptrc lineinfo errors sockets gpm ipc terminfo video mouse keyboard  serial variants types systhrds sysctl sysconst
 override TARGET_LOADERS+=prt0 cprt0
-override TARGET_RSTS+=math varutils typinfo variants classes
+override TARGET_RSTS+=math varutils typinfo variants classes sysconst
 override INSTALL_FPCPACKAGE=y y
 override COMPILER_INCLUDEDIR+=$(INC) $(PROCINC) $(UNIXINC) $(BSDINC) $(BSDPROCINC)
 override COMPILER_SOURCEDIR+=$(INC) $(PROCINC) $(UNIXINC) $(BSDINC)
@@ -259,15 +246,9 @@ endif
 ifeq ($(OS_TARGET),netbsd)
 UNIXINSTALLDIR=1
 endif
-ifeq ($(OS_TARGET),openbsd)
-UNIXINSTALLDIR=1
-endif
 ifeq ($(OS_TARGET),sunos)
 UNIXINSTALLDIR=1
 endif
-ifeq ($(OS_TARGET),qnx)
-UNIXINSTALLDIR=1
-endif
 else
 ifeq ($(OS_SOURCE),linux)
 UNIXINSTALLDIR=1
@@ -278,15 +259,9 @@ endif
 ifeq ($(OS_SOURCE),netbsd)
 UNIXINSTALLDIR=1
 endif
-ifeq ($(OS_SOURCE),openbsd)
-UNIXINSTALLDIR=1
-endif
 ifeq ($(OS_TARGET),sunos)
 UNIXINSTALLDIR=1
 endif
-ifeq ($(OS_TARGET),qnx)
-UNIXINSTALLDIR=1
-endif
 endif
 ifndef INSTALL_PREFIX
 ifdef PREFIX
@@ -325,17 +300,9 @@ endif
 endif
 ifndef INSTALL_BINDIR
 ifdef UNIXINSTALLDIR
-ifdef CROSSCOMPILE
-INSTALL_BINDIR:=$(INSTALL_BASEDIR)/cross/$(FULL_TARGET)/bin
-else
 INSTALL_BINDIR:=$(INSTALL_PREFIX)/bin
-endif
-else
-ifdef CROSSCOMPILE
-INSTALL_BINDIR:=$(INSTALL_BASEDIR)/cross/$(FULL_TARGET)/bin
 else
 INSTALL_BINDIR:=$(INSTALL_BASEDIR)/bin
-endif
 ifdef INSTALL_FPCPACKAGE
 INSTALL_BINDIR:=$(INSTALL_BINDIR)/$(OS_TARGET)
 endif
@@ -456,111 +423,6 @@ SHAREDLIBEXT=.so
 STATICLIBPREFIX=libp
 RSTEXT=.rst
 FPCMADE=fpcmade
-ifeq ($(findstring 1.0.,$(FPC_VERSION)),)
-ifeq ($(OS_TARGET),go32v1)
-STATICLIBPREFIX=
-FPCMADE=fpcmade.v1
-PACKAGESUFFIX=v1
-endif
-ifeq ($(OS_TARGET),go32v2)
-STATICLIBPREFIX=
-FPCMADE=fpcmade.dos
-ZIPSUFFIX=go32
-endif
-ifeq ($(OS_TARGET),watcom)
-STATICLIBPREFIX=
-FPCMADE=fpcmade.wat
-ZIPSUFFIX=watc
-OEXT=.obj
-ASMEXT=.asm
-SHAREDLIBEXT=.dll
-endif
-ifeq ($(OS_TARGET),linux)
-EXEEXT=
-HASSHAREDLIB=1
-FPCMADE=fpcmade.lnx
-ZIPSUFFIX=linux
-endif
-ifeq ($(OS_TARGET),freebsd)
-EXEEXT=
-HASSHAREDLIB=1
-FPCMADE=fpcmade.freebsd
-ZIPSUFFIX=freebsd
-endif
-ifeq ($(OS_TARGET),netbsd)
-EXEEXT=
-HASSHAREDLIB=1
-FPCMADE=fpcmade.netbsd
-ZIPSUFFIX=netbsd
-endif
-ifeq ($(OS_TARGET),openbsd)
-EXEEXT=
-HASSHAREDLIB=1
-FPCMADE=fpcmade.openbsd
-ZIPSUFFIX=openbsd
-endif
-ifeq ($(OS_TARGET),win32)
-SHAREDLIBEXT=.dll
-FPCMADE=fpcmade.w32
-ZIPSUFFIX=w32
-endif
-ifeq ($(OS_TARGET),os2)
-AOUTEXT=.out
-STATICLIBPREFIX=
-SHAREDLIBEXT=.dll
-FPCMADE=fpcmade.os2
-ZIPSUFFIX=os2
-ECHO=echo
-endif
-ifeq ($(OS_TARGET),emx)
-AOUTEXT=.out
-STATICLIBPREFIX=
-SHAREDLIBEXT=.dll
-FPCMADE=fpcmade.emx
-ZIPSUFFIX=emx
-ECHO=echo
-endif
-ifeq ($(OS_TARGET),amiga)
-EXEEXT=
-SHAREDLIBEXT=.library
-FPCMADE=fpcmade.amg
-endif
-ifeq ($(OS_TARGET),atari)
-EXEEXT=.ttp
-FPCMADE=fpcmade.ata
-endif
-ifeq ($(OS_TARGET),beos)
-EXEEXT=
-FPCMADE=fpcmade.be
-ZIPSUFFIX=be
-endif
-ifeq ($(OS_TARGET),sunos)
-EXEEXT=
-FPCMADE=fpcmade.sun
-ZIPSUFFIX=sun
-endif
-ifeq ($(OS_TARGET),qnx)
-EXEEXT=
-FPCMADE=fpcmade.qnx
-ZIPSUFFIX=qnx
-endif
-ifeq ($(OS_TARGET),netware)
-EXEEXT=.nlm
-STATICLIBPREFIX=
-FPCMADE=fpcmade.nw
-ZIPSUFFIX=nw
-endif
-ifeq ($(OS_TARGET),macos)
-EXEEXT=
-FPCMADE=fpcmade.mcc
-endif
-ifeq ($(OS_TARGET),darwin)
-EXEEXT=
-HASSHAREDLIB=1
-FPCMADE=fpcmade.darwin
-ZIPSUFFIX=darwin
-endif
-else
 ifeq ($(OS_TARGET),go32v1)
 PPUEXT=.pp1
 OEXT=.o1
@@ -577,11 +439,6 @@ STATICLIBPREFIX=
 FPCMADE=fpcmade.dos
 ZIPSUFFIX=go32
 endif
-ifeq ($(OS_TARGET),watcom)
-STATICLIBPREFIX=
-FPCMADE=fpcmade.dos
-ZIPSUFFIX=watcom
-endif
 ifeq ($(OS_TARGET),linux)
 EXEEXT=
 HASSHAREDLIB=1
@@ -600,12 +457,6 @@ HASSHAREDLIB=1
 FPCMADE=fpcmade.netbsd
 ZIPSUFFIX=netbsd
 endif
-ifeq ($(OS_TARGET),openbsd)
-EXEEXT=
-HASSHAREDLIB=1
-FPCMADE=fpcmade.openbsd
-ZIPSUFFIX=openbsd
-endif
 ifeq ($(OS_TARGET),win32)
 PPUEXT=.ppw
 OEXT=.ow
@@ -631,7 +482,7 @@ ECHO=echo
 endif
 ifeq ($(OS_TARGET),amiga)
 EXEEXT=
-PPUEXT=.ppu
+PPUEXT=.ppa
 ASMEXT=.asm
 OEXT=.o
 SMARTEXT=.sl
@@ -640,7 +491,7 @@ SHAREDLIBEXT=.library
 FPCMADE=fpcmade.amg
 endif
 ifeq ($(OS_TARGET),atari)
-PPUEXT=.ppu
+PPUEXT=.ppt
 ASMEXT=.s
 OEXT=.o
 SMARTEXT=.sl
@@ -680,8 +531,8 @@ ZIPSUFFIX=qnx
 endif
 ifeq ($(OS_TARGET),netware)
 STATICLIBPREFIX=
-PPUEXT=.ppu
-OEXT=.o
+PPUEXT=.ppn
+OEXT=.on
 ASMEXT=.s
 SMARTEXT=.sl
 STATICLIBEXT=.a
@@ -690,16 +541,6 @@ FPCMADE=fpcmade.nw
 ZIPSUFFIX=nw
 EXEEXT=.nlm
 endif
-ifeq ($(OS_TARGET),macos)
-PPUEXT=.ppu
-ASMEXT=.s
-OEXT=.o
-SMARTEXT=.sl
-STATICLIBEXT=.a
-EXEEXT=
-FPCMADE=fpcmade.mcc
-endif
-endif
 ifndef ECHO
 ECHO:=$(strip $(wildcard $(addsuffix /gecho$(SRCEXEEXT),$(SEARCHPATH))))
 ifeq ($(ECHO),)
@@ -770,11 +611,7 @@ endif
 endif
 export MVPROG
 ifndef ECHOREDIR
-ifndef inUnix
-ECHOREDIR=echo
-else
-ECHOREDIR=$(ECHO)
-endif
+ECHOREDIR:=$(subst /,$(PATHSEP),$(ECHO))
 endif
 ifndef COPY
 COPY:=$(CPPROG) -fp
@@ -845,16 +682,14 @@ TARPROG:=$(firstword $(TARPROG))
 endif
 endif
 export TARPROG
-ASNAME=$(BINUTILSPREFIX)as
-LDNAME=$(BINUTILSPREFIX)ld
-ARNAME=$(BINUTILSPREFIX)ar
-RCNAME=$(BINUTILSPREFIX)rc
-ifneq ($(findstring 1.0.,$(FPC_VERSION)),)
-ifeq ($(OS_TARGET),win32)
 ASNAME=as
 LDNAME=ld
 ARNAME=ar
-endif
+RCNAME=rc
+ifeq ($(OS_TARGET),win32)
+ASNAME=asw
+LDNAME=ldw
+ARNAME=arw
 endif
 ifndef ASPROG
 ifdef CROSSBINDIR
@@ -933,17 +768,6 @@ endif
 ifneq ($(OS_TARGET),$(OS_SOURCE))
 override FPCOPT+=-T$(OS_TARGET)
 endif
-ifeq ($(OS_SOURCE),openbsd)
-override FPCOPT+=-FD$(NEW_BINUTILS_PATH)
-endif
-ifndef CROSSBOOTSTRAP
-ifneq ($(BINUTILSPREFIX),)
-override FPCOPT+=-XP$(BINUTILSPREFIX) -Xc
-endif
-ifneq ($(BINUTILSPREFIX),)
-override FPCOPT+=-Xr$(RLINKPATH)
-endif
-endif
 ifdef UNITDIR
 override FPCOPT+=$(addprefix -Fu,$(UNITDIR))
 endif
@@ -1025,11 +849,6 @@ override COMPILER_UNITTARGETDIR=$(COMPILER_TARGETDIR)
 override UNITTARGETDIRPREFIX=$(TARGETDIRPREFIX)
 endif
 endif
-ifeq ($(OS_TARGET),linux)
-ifeq ($(FPC_VERSION),1.0.6)
-override FPCOPTDEF+=HASUNIX
-endif
-endif
 ifdef OPT
 override FPCOPT+=$(OPT)
 endif
@@ -1048,7 +867,7 @@ override COMPILER:=$(FPC) $(FPCOPT)
 ifeq (,$(findstring -s ,$(COMPILER)))
 EXECPPAS=
 else
-ifeq ($(FULL_SOURCE),$(FULL_TARGET))
+ifeq ($(OS_SOURCE),$(OS_TARGET))
 EXECPPAS:=@$(PPAS)
 endif
 endif
@@ -1090,7 +909,7 @@ fpc_debug:
 	$(MAKE) all DEBUG=1
 fpc_release:
 	$(MAKE) all RELEASE=1
-.SUFFIXES: $(EXEEXT) $(PPUEXT) $(OEXT) .pas .dpr .pp .rc .res
+.SUFFIXES: $(EXEEXT) $(PPUEXT) $(OEXT) .pas .pp .rc .res
 %$(PPUEXT): %.pp
 	$(COMPILER) $<
 	$(EXECPPAS)
@@ -1103,14 +922,10 @@ fpc_release:
 %$(EXEEXT): %.pas
 	$(COMPILER) $<
 	$(EXECPPAS)
-%$(EXEEXT): %.dpr
-	$(COMPILER) $<
-	$(EXECPPAS)
 %.res: %.rc
 	windres -i $< -o $@
 vpath %.pp $(COMPILER_SOURCEDIR) $(COMPILER_INCLUDEDIR)
 vpath %.pas $(COMPILER_SOURCEDIR) $(COMPILER_INCLUDEDIR)
-vpath %.dpr $(COMPILER_SOURCEDIR) $(COMPILER_INCLUDEDIR)
 vpath %$(PPUEXT) $(COMPILER_UNITTARGETDIR)
 .PHONY: fpc_install fpc_sourceinstall fpc_exampleinstall
 ifdef INSTALL_UNITS
@@ -1268,7 +1083,6 @@ fpc_baseinfo:
 	@$(ECHO)  Rm........ $(RMPROG)
 	@$(ECHO)  GInstall.. $(GINSTALL)
 	@$(ECHO)  Echo...... $(ECHO)
-	@$(ECHO)  Shell..... $(SHELL)
 	@$(ECHO)  Date...... $(DATE)
 	@$(ECHO)  FPCMake... $(FPCMAKE)
 	@$(ECHO)  PPUMove... $(PPUMOVE)
@@ -1366,21 +1180,20 @@ strings$(PPUEXT) : $(INC)/strings.pp $(INC)/stringsi.inc\
 		   $(PROCINC)/strings.inc $(PROCINC)/stringss.inc\
 		   $(SYSTEMUNIT)$(PPUEXT)
 baseunix$(PPUEXT) : errno.inc $(BSDINC)/bunxtype.inc ptypes.inc $(BSDINC)/ctypes.inc \
-	signal.inc $(UNIXINC)/bunxh.inc $(BSDINC)/bunxmain.inc $(BSDINC)/ostypes.inc \
-	$(BSDINC)/bunxfunc.inc $(BSDPROCINC)/syscallh.inc sysnr.inc \
-	$(BSDINC)/ostypes.inc $(BSDINC)/ossysch.inc $(BSDINC)/bunxmacr.inc $(UNIXINC)/gensigset.inc \
-	$(UNIXINC)/genfuncs.inc $(SYSTEMUNIT)$(PPUEXT)
+  signal.inc $(UNIXINC)/bunxh.inc $(BSDINC)/bunxmain.inc $(BSDINC)/ostypes.inc \
+  $(BSDINC)/bunxfunc.inc $(BSDPROCINC)/syscallh.inc sysnr.inc \
+  $(BSDINC)/ostypes.inc $(BSDINC)/ossysch.inc $(BSDINC)/bunxmacr.inc $(UNIXINC)/gensigset.inc \
+  $(UNIXINC)/genfuncs.inc $(SYSTEMUNIT)$(PPUEXT)
 unix$(PPUEXT) : $(UNIXINC)/unix.pp strings$(PPUEXT) $(INC)/textrec.inc $(INC)/filerec.inc \
 		 syscalls.inc systypes.inc sysconst.inc $(UNIXINC)/timezone.inc \
 		 unixsysc.inc baseunix$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
-linux$(PPUEXT) : baseunix$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
 dos$(PPUEXT) : $(UNIXINC)/dos.pp $(INC)/filerec.inc $(INC)/textrec.inc strings$(PPUEXT) \
 	       unix$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
 crt$(PPUEXT) : $(UNIXINC)/crt.pp $(INC)/textrec.inc unix$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
 objects$(PPUEXT) : $(INC)/objects.pp $(SYSTEMUNIT)$(PPUEXT)
 printer$(PPUEXT) : $(UNIXINC)/printer.pp $(INC)/textrec.inc unix$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
 sysutils$(PPUEXT) : $(UNIXINC)/sysutils.pp $(wildcard $(OBJPASDIR)/sysutils/*.inc) \
-		    objpas$(PPUEXT) unix$(PPUEXT) errors$(PPUEXT)
+		    objpas$(PPUEXT) unix$(PPUEXT) errors$(PPUEXT) sysconst$(PPUEXT)
 	$(COMPILER) -Fi$(OBJPASDIR)/sysutils $(UNIXINC)/sysutils.pp
 classes$(PPUEXT) : classes.pp $(wildcard $(OBJPASDIR)/classes/*.inc) \
 		   sysutils$(PPUEXT) typinfo$(PPUEXT)
@@ -1411,3 +1224,7 @@ ipc$(PPUEXT) : $(UNIXINC)/ipc.pp unix$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
 terminfo$(PPUEXT) : terminfo.pp unix$(PPUEXT)
 callspec$(PPUEXT) : $(INC)/callspec.pp $(SYSTEMUNIT)$(PPUEXT)
 sysctl$(PPUEXT) : $(BSDINC)/sysctl.pp $(SYSTEMUNIT)$(PPUEXT)
+syscall$(PPUEXT) : $(UNIXINC)/syscall.pp
+sysconst$(PPUEXT) : $(OBJPASDIR)/sysconst.pp objpas$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
+	$(COMPILER) $(OBJPASDIR)/sysconst.pp
+cthreads$(PPUEXT) : $(UNIXINC)/cthreads.pp systhrds$(PPUEXT)

+ 10 - 4
rtl/netbsd/Makefile.fpc

@@ -10,8 +10,8 @@ fpcpackage=y
 
 [target]
 loaders=prt0 cprt0
-units=$(SYSTEMUNIT) objpas strings baseunix \
-      $(LINUXUNIT) unix initc \
+units=$(SYSTEMUNIT) objpas strings syscall baseunix \
+      $(LINUXUNIT) unix initc systhrds \
       dos crt objects printer \
       sysutils classes typinfo math varutils \
        charset ucomplex getopts heaptrc lineinfo \
@@ -60,7 +60,7 @@ LINUXUNIT=
 PRT0=prt0
 else
 SYSTEMUNIT=sysbsd
-LINUXUNIT=linux
+LINUXUNIT=
 override FPCOPT+=-dUNIX
 PRT0=prt0_10
 endif
@@ -142,7 +142,6 @@ unix$(PPUEXT) : $(UNIXINC)/unix.pp strings$(PPUEXT) $(INC)/textrec.inc $(INC)/fi
                  syscalls.inc systypes.inc sysconst.inc $(UNIXINC)/timezone.inc \
                  unixsysc.inc baseunix$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
 
-linux$(PPUEXT) : baseunix$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
 
 #
 # TP7 Compatible RTL Units
@@ -224,3 +223,10 @@ terminfo$(PPUEXT) : terminfo.pp unix$(PPUEXT)
 callspec$(PPUEXT) : $(INC)/callspec.pp $(SYSTEMUNIT)$(PPUEXT)
 
 sysctl$(PPUEXT) : $(BSDINC)/sysctl.pp $(SYSTEMUNIT)$(PPUEXT)
+
+syscall$(PPUEXT) : $(UNIXINC)/syscall.pp
+
+sysconst$(PPUEXT) : $(OBJPASDIR)/sysconst.pp objpas$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
+        $(COMPILER) $(OBJPASDIR)/sysconst.pp
+
+cthreads$(PPUEXT) : $(UNIXINC)/cthreads.pp systhrds$(PPUEXT)

+ 29 - 9
rtl/netbsd/classes.pp

@@ -3,7 +3,7 @@
     This file is part of the Free Component Library (FCL)
     Copyright (c) 1999-2000 by Michael Van Canneyt and Florian Klaempfl
 
-    Classes unit for linux
+    Classes unit for FreeBSD
 
     See the file COPYING.FPC, included in this distribution,
     for details about the copyright.
@@ -32,11 +32,7 @@ uses
 implementation
 
 uses
-{$ifdef ver1_0}
-  linux
-{$else}
-  unix
-{$endif}
+  baseunix,unix,Systhrds
   ;
 
 { OS - independent class implementations are in /inc directory. }
@@ -49,16 +45,40 @@ initialization
 finalization
   CommonCleanup;
 
+{$ifndef ver1_0}
   if ThreadsInited then
      DoneThreads;
-
+{$endif}
 end.
 {
   $Log$
-  Revision 1.1  2003-10-06 21:01:06  peter
+  Revision 1.2  2004-01-04 01:11:28  marco
+   * a new qod port of the freebsd rtl. To be refined in the coming days.
+
+  Revision 1.5  2004/01/03 12:18:29  marco
+   * a lot of copyright notices and CVS logs added and fixed
+
+  Revision 1.4  2003/12/22 16:16:33  marco
+   * small 1.0 compat fix
+
+  Revision 1.3  2003/11/17 10:05:51  marco
+   * threads for FreeBSD. Not working tho
+
+  Revision 1.2  2003/10/09 10:55:20  marco
+   * fix for moving classes to rtl while cycling with 1.0 start
+
+  Revision 1.1  2003/10/06 21:01:06  peter
     * moved classes unit to rtl
 
-  Revision 1.2  2002/09/07 15:15:27  peter
+  Revision 1.1  2003/10/06 20:33:58  peter
+    * classes moved to rtl for 1.1
+    * classes .inc and classes.pp files moved to fcl/classes for
+      backwards 1.0.x compatiblity to have it in the fcl
+
+  Revision 1.6  2003/09/20 12:38:29  marco
+   * FCL now compiles for FreeBSD with new 1.1. Now Linux.
+
+  Revision 1.5  2002/09/07 15:15:24  peter
     * old logs removed and tabs fixed
 
 }

+ 19 - 1
rtl/netbsd/ptypes.inc

@@ -71,11 +71,26 @@ type
     time_t   = clong;           { used for returning the time  }
     TTime    = time_t; 
     pTime    = ^time_t;
+    ptime_t  = ^time_t;
 
     socklen_t= cuint32;
     TSocklen = socklen_t;
     pSocklen = ^socklen_t;
 
+    timeval = packed record
+		tv_sec,
+		tv_usec : clong;
+		end;
+    ptimeval= ^timeval;
+    TTimeval= timeval;
+
+    timespec = packed record
+      tv_sec   : time_t;
+      tv_nsec  : clong;
+    end;
+  ptimespec= ^timespec;
+  Ttimespec= timespec;
+
 CONST
    { System limits, POSIX value in parentheses, used for buffer and stack allocation }
     ARG_MAX  = 256*1024;   {4096}  { Maximum number of argument size     }
@@ -86,7 +101,10 @@ CONST
 
 {
   $Log$
-  Revision 1.3  2003-01-17 22:13:47  marco
+  Revision 1.4  2004-01-04 01:11:28  marco
+   * a new qod port of the freebsd rtl. To be refined in the coming days.
+
+  Revision 1.3  2003/01/17 22:13:47  marco
    * some updates
 
   Revision 1.5  2003/01/03 13:11:32  marco

+ 13 - 3
rtl/netbsd/signal.inc

@@ -125,7 +125,14 @@ type sigset_t = array[0..3] of cardinal;
   PSignalHandler  = ^SignalHandler;
   SignalRestorer  = Procedure;cdecl;
   PSignalRestorer = ^SignalRestorer;
-  TSigAction = procedure(Sig: Longint; SigContext: SigContextRec;someptr:pointer);cdecl;
+
+{$define BSDHandler}
+
+{$ifdef BSDHandler}
+  TSigAction = procedure(Sig: Longint; code:longint;var SigContext: SigContextRec);cdecl;
+{$else}
+  TSigAction = procedure(Sig: Longint; var sininfo:tsiginfo_t;var SigContext: SigContextRec);cdecl;
+{$endif}
 
   Sigset=sigset_t;
   TSigset=sigset_t;
@@ -133,7 +140,7 @@ type sigset_t = array[0..3] of cardinal;
 
   SigActionRec = packed record
 //    Handler  : record
-    sa_handler : SignalHandler;
+    sa_handler : TSigAction;
 //      case byte of
 //        0: (Sh: SignalHandler);
 //        1: (Sa: TSigAction);
@@ -154,7 +161,10 @@ type sigset_t = array[0..3] of cardinal;
 
 {
   $Log$
-  Revision 1.2  2003-01-21 15:39:45  marco
+  Revision 1.3  2004-01-04 01:11:28  marco
+   * a new qod port of the freebsd rtl. To be refined in the coming days.
+
+  Revision 1.2  2003/01/21 15:39:45  marco
    * NetBSD first rtl. Still not 100%, but close
 
   Revision 1.1.2.1  2001/08/10 11:07:17  pierre

+ 4 - 338
rtl/netbsd/syscalls.inc

@@ -13,348 +13,14 @@
 
  **********************************************************************}
 
-{BSD version of the syscalls required to implement SysLinux.}
-
-{No debugging for syslinux include !}
-{$IFDEF SYS_LINUX}
-  {$UNDEF SYSCALL_DEBUG}
-{$ENDIF SYS_LINUX}
-
-{*****************************************************************************
-                     --- Main:The System Call Self ---
-*****************************************************************************}
-
-{ The system designed for Linux can't be used for FreeBSD so easily, since
-  FreeBSD pushes arguments, instead of loading them to registers.
-
-For now I do them in assembler, which makes it easier to test them (copy and
-paste to and AS source). Ultimately I hope to design something like this}
-
-type size_t=longint;
-     off_t=int64;
-     cint=longint;
-
-
-{$i syscallh.inc}
-{$i ossysch.inc}
-
-function Fplseek(fd : cint; offset : off_t; whence : cint): off_t; cdecl; external name 'FPC_SYSC_LSEEK';
-
-Function Sys_Time:longint;
-
-VAR tv     : timeval;
-    tz     : timezone;
-    retval : longint;
-
-begin
-  Retval:=do_syscall(116,longint(@tv),longint(@tz));
-  If retval=-1 then
-   sys_time:=-1
-  else
-   sys_time:=tv.sec;
-end;
-
-{*****************************************************************************
-               --- File:File handling related calls ---
-*****************************************************************************}
-
-
-Function Sys_Open(f:pchar;flags:longint;mode:integer):longint;
-
-Begin
- sys_open:=do_syscall(syscall_nr_open,longint(f),flags,mode);
-End;
-
-Function Sys_Close(f:longint):longint;
-
-begin
- sys_close:=do_syscall(syscall_nr_close,f);
-end;
-
-{$ifndef cpum68k}
-Function Sys_Lseek(F:longint;Off:longint;Whence:longint):longint;
-var returnvalue64 : int64;
-begin
- {Lseek's offset is 64-bit, the highword  is the 0}
-{$ifdef cpui386} 
- do_syscall(syscall_nr___syscall,syscall_nr_lseek,0,f,0,off,0,whence);
- asm
-  lea  returnvalue64,%ebx
-  movl %eax,(%ebx)
-  movl %edx,4(%ebx)
- end;
- sys_lseek:=longint(returnvalue64);
- {$else}		// cpupowerpc
-  sys_lseek:=fplseek(f,off,whence);
- {$endif}
-end;
-{$endif cpum68k}
-
-
-Function Sys_Read(f:longint;buffer:pchar;count:longint):longint;
-
-begin
-  sys_read:=do_syscall(syscall_nr_read,F,longint(buffer),count);
-end;
-
-Function Sys_Write(f:longint;buffer:pchar;count:longint):longint;
-
-begin
- sys_write:=do_syscall(syscall_nr_write,F,longint(buffer),count);
-end;
-
-Function Sys_Unlink(Filename:pchar):longint;
-
-begin
-  sys_unlink:=do_syscall(syscall_nr_unlink,longint(Filename));
-end;
-
-Function Sys_Rename(Oldname,Newname:pchar):longint;
-
-begin
-  sys_rename:=do_syscall(syscall_nr_rename,longint(oldname),longint(newname));
-end;
-
-Function Sys_Stat(Filename:pchar;var Buffer: stat):longint;
-{
-   We need this for getcwd
-}
-
-begin
- sys_stat:=do_syscall(syscall_nr_stat,longint(filename),longint(@buffer));
-end;
-
-Function Sys_Symlink(oldname,newname:pchar):longint;
-{
-  We need this for erase
-}
-
-begin
- sys_symlink:=do_syscall(syscall_nr_symlink,longint(oldname),longint(newname));
-end;
-
-
-Function Sys_ReadLink(name,linkname:pchar;maxlen:longint):longint;
-
-begin
-  sys_readlink:=do_syscall(syscall_nr_readlink, longint(name),longint(linkname),maxlen);
-end;
-
-
-
-{*****************************************************************************
-               --- Directory:Directory related calls ---
-*****************************************************************************}
-
-Function Sys_Chdir(Filename:pchar):longint;
-
-begin
- sys_chdir:=do_syscall(syscall_nr_chdir,longint(filename));
-end;
-
-Function Sys_Mkdir(Filename:pchar;mode:longint):longint;
-
-begin {Mode is 16-bit on F-BSD}
-  sys_mkdir:=do_syscall(syscall_nr_mkdir,longint(filename),mode );
-end;
-
-Function Sys_Rmdir(Filename:pchar):longint;
-
-begin
- sys_rmdir:=do_syscall(syscall_nr_rmdir,longint(filename));
-end;
-
-{$ifndef NewReaddir}
-
-const DIRBLKSIZ=1024;
-
-
-{ we need this for getcwd, NOT touched for BSD version }
-Function OpenDir(f:pchar):pdir;
-
-var
-  fd:longint;
-  st:stat;
-  ptr:pdir;
-begin
-  opendir:=nil;
-  if sys_stat(f,st)<0 then
-   exit;
-{ Is it a dir ? }
-  if not((st.mode and $f000)=$4000)then
-   begin
-     errno:=Esysenotdir;
-     exit
-   end;
-{ Open it}
-  fd:=sys_open(f,OPEN_RDONLY,438);
-  if fd<0 then
-   exit;
-  new(ptr);
-  if ptr=nil then
-   exit;
-  Getmem(ptr^.buf,2*DIRBLKSIZ);
-  if ptr^.buf=nil then
-   exit;
-  ptr^.fd:=fd;
-  ptr^.loc:=-1;
-  ptr^.rewind:=longint(ptr^.buf);
-  ptr^.size:=0;
-//  ptr^.dd_max:=sizeof(ptr^.buf^);
-  opendir:=ptr;
-end;
-
-function CloseDir(p:pdir):integer;
-begin
-  closedir:=sys_close(p^.fd);
-  Freemem(p^.buf);
-  dispose(p);
-end;
-
-
-Function Sys_ReadDir(p:pdir):pdirent;
-{Different from Linux, Readdir on BSD is based on Getdents, due to the
-missing of the readdir syscall.
-Getdents requires the buffer to be larger than the blocksize.
-This usually the sectorsize =512 bytes, but maybe tapedrives and harddisks
-with blockmode have this higher?}
-
-function readbuffer:longint;
-
-var retval :longint;
-
-begin
-   retval:=do_syscall(syscall_nr_getdents,longint(p^.fd),longint(@p^.buf^),DIRBLKSIZ {sizeof(getdentsbuffer)});
-   p^.rewind:=longint(p^.buf);
-   if retval=0 then
-    begin
-     p^.rewind:=0;
-     p^.loc:=0;
-    end
-   else
-    P^.loc:=retval;
- readbuffer:=retval;
-end;
-
-var
-    l              : pdirent;
-    novalid        : boolean;
-
-begin
- if (p^.buf=nil) or (p^.loc=0) THEN
-  exit(nil);
- if p^.loc=cardinal(-1) then         {First readdir on this pdir. Initial fill of buffer}
-  begin
-   if readbuffer()=0 Then    {nothing to be read}
-    exit(nil)
-  end;
- l:=nil;
- repeat
-  novalid:=false;
-  if (pdirent(p^.rewind)^.reclen<>0) then
-   begin {valid direntry?}
-    if pdirent(P^.rewind)^.ino<>0 then
-     l:=pdirent(p^.rewind);
-    inc(p^.rewind,pdirent(p^.rewind)^.reclen);
-    if p^.rewind>=(cardinal(p^.buf)+dirblksiz) then
-     novalid:=true;
-   end
-  else
-   novalid:=true;
-  if novalid then
-   begin {block entirely searched or reclen=0}
-    if p^.loc<>0 THEN             {blocks left?}
-     if readbuffer()<>0 then        {succesful read?}
-      novalid:=false;
-   end;
- until (l<>nil) or novalid;
- If novalid then
-  l:=nil;
- Sys_ReadDir:=l;
-end;
-
-{$endif}
-
-{*****************************************************************************
-        --- Process:Process & program handling - related calls ---
-*****************************************************************************}
-
-
-Function sys_GetPid:LongInt;
-{
-  Get Process ID.
-}
-
-begin
- sys_GetPID:=do_syscall(syscall_nr_getpid);
-end;
-
-Procedure Sys_Exit(ExitCode:longint);
-
-begin
-  do_syscall(syscall_nr_exit,exitcode);
-end;
-{
-  Change action of process upon receipt of a signal.
-  Signum specifies the signal (all except SigKill and SigStop).
-  If Act is non-nil, it is used to specify the new action.
-  If OldAct is non-nil the previous action is saved there.
-}
-
-
-
-Procedure SigAction(Signum:longint;Act,OldAct:PSigActionRec );
-{
-  Change action of process upon receipt of a signal.
-  Signum specifies the signal (all except SigKill and SigStop).
-  If Act is non-nil, it is used to specify the new action.
-  If OldAct is non-nil the previous action is saved there.
-}
-
-begin
-  do_syscall(syscall_nr_sigaction,longint(signum),longint(act),longint(oldact));
- {$ifdef linuxunit}
-  LinuxError:=Errno;
- {$endif}
-end;
-
-(*=================== MOVED from syslinux.inc ========================*)
-Function Sys_FTruncate(Handle,Pos:longint):longint;  //moved from sysunix.inc Do_Truncate
-begin
-  Sys_FTruncate:=do_syscall(syscall_nr___syscall, syscall_nr_ftruncate,0,handle,0,pos,0);
-end;
-
-Function Sys_fstat(fd : longint;var Info:stat):Longint; // This was missing here, instead an fstat call was included in Do_FileSize
-begin
-  Sys_FStat:=do_SysCall(syscall_nr_fstat,fd,longint(@info));
-end;
-
-{$ifdef NewReaddir}
-{$I readdir.inc}
-{$endif}
-
-
-{
-  Interface to Unix ioctl call.
-  Performs various operations on the filedescriptor Handle.
-  Ndx describes the operation to perform.
-  Data points to data needed for the Ndx function. The structure of this
-  data is function-dependent.
-}
-Function Sys_IOCtl(Handle,Ndx: Longint;Data: Pointer):LongInt;  // This was missing here, instead hardcoded in Do_IsDevice
-begin
-  Sys_IOCtl:=do_SysCall(syscall_nr_ioctl,handle,Ndx,longint(data));
-end;
-
-Function Sys_mmap(adr,len,prot,flags,fdes,off:longint):longint; // moved from sysunix.inc, used in sbrk
-begin
-  Sys_mmap:=fpmmap(Adr,Len,Prot,Flags,fdes,off);
-end;
 
 
 {
   $Log$
-  Revision 1.7  2003-10-17 20:57:10  olle
+  Revision 1.8  2004-01-04 01:11:28  marco
+   * a new qod port of the freebsd rtl. To be refined in the coming days.
+
+  Revision 1.7  2003/10/17 20:57:10  olle
     * Changed m68k to cpum68k, i386 to cpui386
 
   Revision 1.6  2003/08/21 22:22:11  olle

+ 10 - 2
rtl/netbsd/sysconst.inc

@@ -15,7 +15,12 @@
 
 {BSD version, only the blocks with BSD in the comment are updated}
 
-Const
+const
+  { For getting/setting priority }
+  Prio_Process = 0;
+  Prio_PGrp    = 1;
+  Prio_User    = 2;
+
   { Things for LSEEK call, same in linux and BSD }
   Seek_set = 0;
   Seek_Cur = 1;
@@ -99,7 +104,10 @@ type
 
 {
   $Log$
-  Revision 1.3  2003-01-21 15:39:45  marco
+  Revision 1.4  2004-01-04 01:11:28  marco
+   * a new qod port of the freebsd rtl. To be refined in the coming days.
+
+  Revision 1.3  2003/01/21 15:39:45  marco
    * NetBSD first rtl. Still not 100%, but close
 
   Revision 1.2  2003/01/17 22:13:47  marco

+ 4 - 122
rtl/netbsd/systypes.inc

@@ -14,97 +14,6 @@
  **********************************************************************}
 type
 
-{
- Linux system calls take arguments as follows :
-
-   i386/m68k:
-
-   %eax/%d0 : System call number
-   %ebx/%d1 : first argument
-   %ecx/%d2 : second argument
-   %edx/%d3 : third argumens
-   %esi/%d3 : fourth argument
-   %edi/%d4 : fifth argument
-
-  That is why we define a special type, with only these arguments
-  To make it processor independent, we don't give any system dependent
-  names, but the rather abstract reg1,reg2 etc;
-
-  SysCallRegs=record
-    reg1,reg2,reg3,reg4,reg5,reg6 : longint;
-  end;
-  PSysCallRegs=^SysCallRegs;
-  TSysCallRegs=SysCallRegs;
-}
-{ The following are records for system calls BSD updated }
-  dirent = packed record
-    ino    : cardinal;		{ This is not inode number, but "a number
-				  unique for each file on a filesystem"}
-    reclen : word;
-    d_type,
-    namlen : byte;
-    name   : array [0..255] of char;
-  end;
-
-  pdirent =^dirent;
-  TDirEnt = dirent;
-
-    TDir= packed record {BSD libc record.}
-            fd    : longint;    { file descriptor associated with directory }
-            loc,                { offset in current buffer }
-            size  : cardinal;   { amount of data returned by getdirentries}
-            buf   : pdirent;    { data buffer, actually a pchar}
-            len   : longint;    { size of data buffer 	}
-            seek,               { magic cookie returned by getdirentries}
-            rewind: cardinal;   { magic cookie for rewinding}
-            flags : longint;    { flags for readdir }
-            end;
-
-(* Linux kernel record
-    TDir = packed record
-            fd     : longint;
-            loc    : longint;
-            size   : integer;
-            buf    : pdirent;
-   {The following are used in libc, but NOT in the linux kernel sources ??}
-            nextoff: longint;
-            dd_max : integer; {size of buf. Irrelevant, as buf is of type dirent}
-            lock   : pointer;
-            dummy  : array[0..1023] of char;
-            end; *)
-
-  PDir =^TDir;
-
-{$packrecords C}
-type
- dev_t	= cardinal; // taken from sysunix.getdir to avoid ifdef's.
-
- Stat =record {BSD version}
-        dev,                            { inode's device }
-        ino        :  cardinal;         { inode's number }
-        mode, 				{ inode protection mode }
-        nlink	   :  longint;             { number of hard links }
-        uid,				{ user ID of the file's owner }
-        gid,				{ group ID of the file's group }
-        dev_t	   :  cardinal;		{ device type }
-	atime,                          { time of last access }
-	atime_nsec,         		{ nsec of last access }
-	mtime,	           		{ time of last data modification }
-	mtime_nsec,         		{ nsec of last data modification }
-	ctime,            		{ time of last file status change }
-	ctime_nsec : longint;      	{ nsec of last file status change }
-	size,           		{ file size, in bytes }
-	blocks     : Int64;		{ blocks allocated for file }
-	blksze,         		{ optimal blocksize for I/O }
-	flags,          		{ user defined flags for file }
-	filegen    : cardinal;		{ file generation number }
-//	lspare	   : longint;
-	qspare     : array[0..1] of int64;
-       end;
-
-  PStat=^Stat;
-  TStat=Stat;
-
   TStatfs = packed record
     spare2,	       { place holder}
     bsize,	       { fundamental block size}
@@ -125,40 +34,13 @@ type
   end;
   PStatFS=^TStatFS;
 
-  fdSet=array[0..7] of longint;{=256 bits}
-  pfdset=^fdset;
-  TFDSet=fdset;
-
-  timeval = packed record
-    sec,usec:longint;
-  end;
-  ptimeval=^timeval;
-  TTimeVal=timeval;
-
-  timespec = packed record
-    tv_sec,tv_nsec:longint;
-  end;
-
-  timezone = packed record
-    minuteswest,dsttime:longint;
-  end;
-  ptimezone =^timezone;
-  TTimeZone = timezone;
-
-  utsname = packed record
-    sysname,
-    nodename,
-    release,
-    version,
-    machine,
-    domainname : Array[0..64] of char;
-  end;
-  PUTSName=^UTSName;
-  TUTSName=UTSName;
 
 {
   $Log$
-  Revision 1.3  2003-01-21 15:39:45  marco
+  Revision 1.4  2004-01-04 01:11:28  marco
+   * a new qod port of the freebsd rtl. To be refined in the coming days.
+
+  Revision 1.3  2003/01/21 15:39:45  marco
    * NetBSD first rtl. Still not 100%, but close
 
   Revision 1.2  2003/01/17 22:13:47  marco

+ 261 - 238
rtl/netbsd/termios.inc

@@ -1,3 +1,18 @@
+{  
+   $Id$
+   This file is part of the Free Pascal run time library.
+   (c) 2000-2003 by Marco van de Voort
+   member of the Free Pascal development team.
+
+   See the file COPYING.FPC, included in this distribution,
+   for details about the copyright.
+  
+   Termios header for FreeBSD
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY;without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+}
 
 CONST
 
@@ -6,29 +21,29 @@ CONST
  *
  * Index into c_cc[] character array.
  *
- *	Name	     Subscript	Enabled by
+ *      Name         Subscript  Enabled by
  }
- VEOF		=0;	
- VEOL		=1;	
- VEOL2		=2;	
- VERASE		=3;	
- VWERASE 	=4;	
- VKILL		=5;	
- VREPRINT 	=6;	
-{		=7;	   spare 1 }
- VINTR		=8;	
- VQUIT		=9;	
- VSUSP		=10;	
- VDSUSP		=11;	
- VSTART		=12;	
- VSTOP		=13;	
- VLNEXT		=14;	
- VDISCARD	=15;	
- VMIN		=16;	
- VTIME		=17;	
- VSTATUS	=18;	
-{		=19	   spare 2 }
- NCCS		=20;
+ VEOF           =0;
+ VEOL           =1;
+ VEOL2          =2;
+ VERASE         =3;
+ VWERASE        =4;
+ VKILL          =5;
+ VREPRINT       =6;
+{               =7;        spare 1 }
+ VINTR          =8;
+ VQUIT          =9;
+ VSUSP          =10;
+ VDSUSP         =11;
+ VSTART         =12;
+ VSTOP          =13;
+ VLNEXT         =14;
+ VDISCARD       =15;
+ VMIN           =16;
+ VTIME          =17;
+ VSTATUS        =18;
+{               =19        spare 2 }
+ NCCS           =20;
 
 Type
   winsize = packed record
@@ -61,55 +76,55 @@ CONST
  POSIX_VDISABLE=Chr($ff);
 {
 
-#define	CCEQ(val, c)	((c) == (val) ? (val) != _POSIX_VDISABLE : 0)
+#define CCEQ(val, c)    ((c) == (val) ? (val) != _POSIX_VDISABLE : 0)
 }
 
 { * Input flags - software input processing}
 
-       	IGNBRK		=       $1;	{ ignore BREAK condition }
-       	BRKINT		=       $2;	{ map BREAK to SIGINTR }
-       	IGNPAR		=       $4;	{ ignore (discard) parity errors }
-       	PARMRK		=       $8;	{ mark parity and framing errors }
-       	INPCK		=      $10;	{ enable checking of parity errors }
-       	ISTRIP		=      $20;	{ strip 8th bit off chars }
-       	INLCR		=      $40;	{ map NL into CR }
-       	IGNCR		=      $80;	{ ignore CR }
-       	ICRNL		=     $100;	{ map CR to NL (ala CRMOD) }
-       	IXON		=     $200;	{ enable output flow control }
-       	IXOFF		=     $400;	{ enable input flow control }
-       	IXANY		=     $800;	{ any char will restart after stop }
-        IMAXBEL		=    $2000;	{ ring bell on input queue full }
+        IGNBRK          =       $1;     { ignore BREAK condition }
+        BRKINT          =       $2;     { map BREAK to SIGINTR }
+        IGNPAR          =       $4;     { ignore (discard) parity errors }
+        PARMRK          =       $8;     { mark parity and framing errors }
+        INPCK           =      $10;     { enable checking of parity errors }
+        ISTRIP          =      $20;     { strip 8th bit off chars }
+        INLCR           =      $40;     { map NL into CR }
+        IGNCR           =      $80;     { ignore CR }
+        ICRNL           =     $100;     { map CR to NL (ala CRMOD) }
+        IXON            =     $200;     { enable output flow control }
+        IXOFF           =     $400;     { enable input flow control }
+        IXANY           =     $800;     { any char will restart after stop }
+        IMAXBEL         =    $2000;     { ring bell on input queue full }
 
 {
  * Output flags - software output processing
 }
-       	OPOST		=       $1;	{ enable following output processing }
-        ONLCR		=       $2;	{ map NL to CR-NL (ala CRMOD) }
-        OXTABS		=       $4;	{ expand tabs to spaces }
-        ONOEOT		=       $8;	{ discard EOT's (^D) on output) }
+        OPOST           =       $1;     { enable following output processing }
+        ONLCR           =       $2;     { map NL to CR-NL (ala CRMOD) }
+        OXTABS          =       $4;     { expand tabs to spaces }
+        ONOEOT          =       $8;     { discard EOT's (^D) on output) }
 
 {
  * Control flags - hardware control of terminal
 }
-       	CIGNORE		=       $1;	{ ignore control flags }
-        CSIZE		=     $300;	{ character size mask }
-        CS5		=       $0;	    { 5 bits (pseudo) }
-        CS6		=     $100;	    { 6 bits }
-        CS7		=     $200;	    { 7 bits }
-        CS8		=     $300;	    { 8 bits }
-        CSTOPB		=     $400;	{ send 2 stop bits }
-        CREAD		=     $800;	{ enable receiver }
-        PARENB		=    $1000;	{ parity enable }
-        PARODD		=    $2000;	{ odd parity, else even }
-        HUPCL		=    $4000;	{ hang up on last close }
-        CLOCAL		=    $8000;	{ ignore modem status lines }
-        CCTS_OFLOW	=   $10000;	{ CTS flow control of output }
-        CRTS_IFLOW	=   $20000;	{ RTS flow control of input }
-        CRTSCTS		=   (CCTS_OFLOW or CRTS_IFLOW);
-       	CDTR_IFLOW	=   $40000;	{ DTR flow control of input }
-        CDSR_OFLOW	=   $80000;	{ DSR flow control of output }
-       	CCAR_OFLOW	=  $100000;	{ DCD flow control of output }
-       	MDMBUF		=  $100000;	{ old name for CCAR_OFLOW }
+        CIGNORE         =       $1;     { ignore control flags }
+        CSIZE           =     $300;     { character size mask }
+        CS5             =       $0;         { 5 bits (pseudo) }
+        CS6             =     $100;         { 6 bits }
+        CS7             =     $200;         { 7 bits }
+        CS8             =     $300;         { 8 bits }
+        CSTOPB          =     $400;     { send 2 stop bits }
+        CREAD           =     $800;     { enable receiver }
+        PARENB          =    $1000;     { parity enable }
+        PARODD          =    $2000;     { odd parity, else even }
+        HUPCL           =    $4000;     { hang up on last close }
+        CLOCAL          =    $8000;     { ignore modem status lines }
+        CCTS_OFLOW      =   $10000;     { CTS flow control of output }
+        CRTS_IFLOW      =   $20000;     { RTS flow control of input }
+        CRTSCTS         =   (CCTS_OFLOW or CRTS_IFLOW);
+        CDTR_IFLOW      =   $40000;     { DTR flow control of input }
+        CDSR_OFLOW      =   $80000;     { DSR flow control of output }
+        CCAR_OFLOW      =  $100000;     { DCD flow control of output }
+        MDMBUF          =  $100000;     { old name for CCAR_OFLOW }
 
 {
  * "Local" flags - dumping ground for other state
@@ -119,23 +134,23 @@ CONST
  * input flag.
  }
 
-       	ECHOKE		=       $1;	{ visual erase for line kill }
-       	ECHOE		=       $2;	{ visually erase chars }
-       	ECHOK		=       $4;	{ echo NL after line kill }
-        ECHO		=       $8;	{ enable echoing }
-       	ECHONL		=      $10;	{ echo NL even if ECHO is off }
-       	ECHOPRT		=      $20;	{ visual erase mode for hardcopy }
-        ECHOCTL  	=      $40;	{ echo control chars as ^(Char) }
-       	ISIG		=      $80;	{ enable signals INTR, QUIT, [D]SUSP }
-       	ICANON		=     $100;	{ canonicalize input lines }
-        ALTWERASE	=     $200;	{ use alternate WERASE algorithm }
-       	IEXTEN		=     $400;	{ enable DISCARD and LNEXT }
+        ECHOKE          =       $1;     { visual erase for line kill }
+        ECHOE           =       $2;     { visually erase chars }
+        ECHOK           =       $4;     { echo NL after line kill }
+        ECHO            =       $8;     { enable echoing }
+        ECHONL          =      $10;     { echo NL even if ECHO is off }
+        ECHOPRT         =      $20;     { visual erase mode for hardcopy }
+        ECHOCTL         =      $40;     { echo control chars as ^(Char) }
+        ISIG            =      $80;     { enable signals INTR, QUIT, [D]SUSP }
+        ICANON          =     $100;     { canonicalize input lines }
+        ALTWERASE       =     $200;     { use alternate WERASE algorithm }
+        IEXTEN          =     $400;     { enable DISCARD and LNEXT }
         EXTPROC         =     $800;      { external processing }
-        TOSTOP		=  $400000;	{ stop background jobs from output }
-        FLUSHO		=  $800000;	{ output being flushed (state) }
-       	NOKERNINFO	= $2000000;	{ no kernel output from VSTATUS }
-        PENDIN		=$20000000;	{ XXX retype pending input (state) }
-       	NOFLSH		=$80000000;	{ don't flush after interrupt }
+        TOSTOP          =  $400000;     { stop background jobs from output }
+        FLUSHO          =  $800000;     { output being flushed (state) }
+        NOKERNINFO      = $2000000;     { no kernel output from VSTATUS }
+        PENDIN          =$20000000;     { XXX retype pending input (state) }
+        NOFLSH          =$80000000;     { don't flush after interrupt }
 
 
 
@@ -145,66 +160,66 @@ CONST
 
 CONST
 
-       	TCSANOW		=0;		{ make change immediate }
-       	TCSADRAIN	=1;		{ drain output, then change }
-       	TCSAFLUSH	=2;		{ drain output, flush input }
-        TCSASOFT	=$10;		{ flag - don't alter h.w. state }
+        TCSANOW         =0;             { make change immediate }
+        TCSADRAIN       =1;             { drain output, then change }
+        TCSAFLUSH       =2;             { drain output, flush input }
+        TCSASOFT        =$10;           { flag - don't alter h.w. state }
 
 {
  * Standard speeds
 }
-        B0	=     0;
-        B50	=    50;
-        B75	=    75;
-        B110	=   110;
-        B134	=   134;
-        B150	=   150;
-        B200	=   200;
-        B300	=   300;
-        B600	=   600;
-        B1200	=  1200;
-       	B1800	=  1800;
-        B2400	=  2400;
-        B4800	=  4800;
-        B9600	=  9600;
-        B19200	= 19200;
-        B38400	= 38400;
-        B7200	=  7200;
-        B14400	= 14400;
-        B28800	= 28800;
-        B57600	= 57600;
-        B76800	= 76800;
-        B115200	=115200;
-        B230400	=230400;
-        EXTA	= 19200;
-        EXTB	= 38400;
-
-       	TCIFLUSH	=1;
-       	TCOFLUSH	=2;
-        TCIOFLUSH	=3;
-       	TCOOFF		=1;
-       	TCOON		=2;
-        TCIOFF		=3;
-        TCION		=4;
-
-(*
+        B0      =     0;
+        B50     =    50;
+        B75     =    75;
+        B110    =   110;
+        B134    =   134;
+        B150    =   150;
+        B200    =   200;
+        B300    =   300;
+        B600    =   600;
+        B1200   =  1200;
+        B1800   =  1800;
+        B2400   =  2400;
+        B4800   =  4800;
+        B9600   =  9600;
+        B19200  = 19200;
+        B38400  = 38400;
+        B7200   =  7200;
+        B14400  = 14400;
+        B28800  = 28800;
+        B57600  = 57600;
+        B76800  = 76800;
+        B115200 =115200;
+        B230400 =230400;
+        EXTA    = 19200;
+        EXTB    = 38400;
+
+        TCIFLUSH        =1;
+        TCOFLUSH        =2;
+        TCIOFLUSH       =3;
+        TCOOFF          =1;
+        TCOON           =2;
+        TCIOFF          =3;
+        TCION           =4;
+
+{
 #include <sys/cdefs.h>
 
 __BEGIN_DECLS
-speed_t	cfgetispeed __P((const struct termios * ));
-speed_t	cfgetospeed __P((const struct termios * ));
-int	cfsetispeed __P((struct termios *, speed_t));
-int	cfsetospeed __P((struct termios *, speed_t));
-int	tcgetattr __P((int, struct termios * ));
-int	tcsetattr __P((int, int, const struct termios * ));
-int	tcdrain __P((int));
-int	tcflow __P((int, int));
-int	tcflush __P((int, int));
-int	tcsendbreak __P((int, int));
+speed_t cfgetispeed __P((const struct termios *));
+speed_t cfgetospeed __P((const struct termios *));
+int     cfsetispeed __P((struct termios *, speed_t));
+int     cfsetospeed __P((struct termios *, speed_t));
+int     tcgetattr __P((int, struct termios *));
+int     tcsetattr __P((int, int, const struct termios *));
+int     tcdrain __P((int));
+int     tcflow __P((int, int));
+int     tcflush __P((int, int));
+int     tcsendbreak __P((int, int));
 
 #ifndef _POSIX_SOURCE
-void	cfmakeraw __P((struct termios * ));
-int	cfsetspeed __P((struct termios *, speed_t));
+void    cfmakeraw __P((struct termios *));
+int     cfsetspeed __P((struct termios *, speed_t));
 #endif { !_POSIX_SOURCE }
 __END_DECLS
 
@@ -213,139 +228,147 @@ __END_DECLS
 
 
 struct winsize {
-	unsigned short	ws_row;		{ rows, in characters }
-	unsigned short	ws_col;		{ columns, in characters }
-	unsigned short	ws_xpixel;	{ horizontal size, pixels }
-	unsigned short	ws_ypixel;	{ vertical size, pixels }
+        unsigned short  ws_row;         { rows, in characters }
+        unsigned short  ws_col;         { columns, in characters }
+        unsigned short  ws_xpixel;      { horizontal size, pixels }
+        unsigned short  ws_ypixel;      { vertical size, pixels }
 };
 
-*)
+}
        IOCTLREAD        = $40000000;
        IOCTLWRITE       = $80000000;
-       IOCTLVOID	= $20000000;
-
-      	TIOCMODG	= IOCTLREAD+$47400+ 3;	{ get modem control state }
-      	TIOCMODS	= IOCTLWRITE+$47400+ 4;	{ set modem control state }
-      		TIOCM_LE	=$0001;		{ line enable }
-      		TIOCM_DTR	=$0002;		{ data terminal ready }
-      		TIOCM_RTS	=$0004;		{ request to send }
-      		TIOCM_ST	=$0010;		{ secondary transmit }
-      		TIOCM_SR	=$0020;		{ secondary receive }
-      		TIOCM_CTS	=$0040;		{ clear to send }
-      		TIOCM_CAR	=$0100;		{ carrier detect }
-      		TIOCM_CD	=TIOCM_CAR;
-      		TIOCM_RNG	=$0200; 	{ ring }
-      		TIOCM_RI	=TIOCM_RNG;
-      		TIOCM_DSR	=$0400;		{ data set ready }
-						{ 8-10 compat }
-      	TIOCEXCL	 =IOCTLVOID+$7400+ 13;		{ set exclusive use of tty }
-      	TIOCNXCL	 =IOCTLVOID+$7400+ 14;		{ reset exclusive use of tty }
-						{ 15 unused }
-      	TIOCFLUSH 	 =IOCTLWRITE+$47400+ 16;	{ flush buffers }
-						{ 17-18 compat }
-      	TIOCGETA	 =IOCTLREAD+$2C7400+ 19; { get termios struct }
-      	TIOCSETA	 =IOCTLWRITE+$2C7400+ 20; { set termios struct }
-      	TIOCSETAW	 =IOCTLWRITE+$2C7400+ 21; { drain output, set }
-      	TIOCSETAF	 =IOCTLWRITE+$2C7400+ 22; { drn out, fls in, set }
-      	TIOCGETD	 =IOCTLREAD+$47400+ 26;	{ get line discipline }
-      	TIOCSETD	 =IOCTLWRITE+$47400+ 27;	{ set line discipline }
-						{ 127-124 compat }
-      	TIOCSBRK	 =IOCTLVOID+$7400+ 123;		{ set break bit }
-      	TIOCCBRK	 =IOCTLVOID+$7400+ 122;		{ clear break bit }
-      	TIOCSDTR	 =IOCTLVOID+$7400+ 121;		{ set data terminal ready }
-      	TIOCCDTR	 =IOCTLVOID+$7400+ 120;		{ clear data terminal ready }
-      	TIOCGPGRP	 =IOCTLREAD+$47400+ 119;	{ get pgrp of tty }
-      	TIOCSPGRP	 =IOCTLWRITE+$47400+ 118;	{ set pgrp of tty }
-						{ 117-116 compat }
-      	TIOCOUTQ	 =IOCTLREAD+$47400+ 115;	{ output queue size }
-      	TIOCSTI		 =IOCTLWRITE+$17400+ 114;	{ simulate terminal input }
-      	TIOCNOTTY	 =IOCTLVOID+$7400+ 113;		{ void tty association }
-      	TIOCPKT		 =IOCTLWRITE+$47400+ 112;	{ pty: set/clear packet mode }
-      		TIOCPKT_DATA		=$00;	{ data packet }
-      		TIOCPKT_FLUSHREAD	=$01;	{ flush packet }
-      		TIOCPKT_FLUSHWRITE	=$02;	{ flush packet }
-      		TIOCPKT_STOP		=$04;	{ stop output }
-      		TIOCPKT_START		=$08;	{ start output }
-      		TIOCPKT_NOSTOP		=$10;	{ no more ^S, ^Q }
-      		TIOCPKT_DOSTOP		=$20;	{ now do ^S ^Q }
-      		TIOCPKT_IOCTL		=$40;	{ state change of pty driver }
-      	TIOCSTOP	 =IOCTLVOID+$7400+ 111;		{ stop output, like ^S }
-      	TIOCSTART	 =IOCTLVOID+$7400+ 110;		{ start output, like ^Q }
-      	TIOCMSET	 =IOCTLWRITE+$47400+ 109;	{ set all modem bits }
-      	TIOCMBIS	 =IOCTLWRITE+$47400+ 108;	{ bis modem bits }
-      	TIOCMBIC	 =IOCTLWRITE+$47400+ 107;	{ bic modem bits }
-      	TIOCMGET	 =IOCTLREAD+$47400+ 106;	{ get all modem bits }
-      	TIOCREMOTE	 =IOCTLWRITE+$47400+ 105;	{ remote input editing }
-      	TIOCGWINSZ	 =IOCTLREAD+$87400+ 104;	{ get window size }
-      	TIOCSWINSZ	 =IOCTLWRITE+$87400+ 103;	{ set window size }
-      	TIOCUCNTL	 =IOCTLWRITE+$47400+ 102;	{ pty: set/clr usr cntl mode }
-      	TIOCSTAT	 =IOCTLVOID+$7400+ 101;		{ simulate ^T status message }
-  //    		   UIOCCMD(n)	_IO('u', n)	{ usr cntl op "n" }
-      	TIOCCONS	 =IOCTLWRITE+$47400+ 98;	{ become virtual console }
-      	TIOCSCTTY	 =IOCTLVOID+$7400+ 97;		{ become controlling tty }
-      	TIOCEXT		 =IOCTLWRITE+$47400+ 96;	{ pty: external processing }
-      	TIOCSIG		 =IOCTLVOID+$7400+ 95;		{ pty: generate signal }
-      	TIOCDRAIN	 =IOCTLVOID+$7400+ 94;		{ wait till output drained }
-      	TIOCMSDTRWAIT	 =IOCTLWRITE+$47400+ 91;	{ modem: set wait on close }
-      	TIOCMGDTRWAIT	 =IOCTLREAD+$47400+ 90;	{ modem: get wait on close }
-      	TIOCTIMESTAMP	 =IOCTLREAD+$87400+ 89; 	{ enable/get timestamp
-						 * of last input event }
-      	TIOCDCDTIMESTAMP =IOCTLREAD+$87400+ 88;	{ enable/get timestamp
-						 * of last DCd rise }
-      	TIOCSDRAINWAIT	 =IOCTLWRITE+$47400+ 87;	{ set ttywait timeout }
-       	TIOCGDRAINWAIT	 =IOCTLREAD+$47400+ 86;	{ get ttywait timeout }
-
-      	TTYDISC		 =0;		{ termios tty line discipline }
-      	SLIPDISC	 =4; 		{ serial IP discipline }
-      	PPPDISC		 =5;		{ PPP discipline }
-      	NETGRAPHDISC	 =6;		{ Netgraph tty node discipline }
+       IOCTLVOID        = $20000000;
+
+        TIOCMODG        = IOCTLREAD+$47400+ 3;  { get modem control state }
+        TIOCMODS        = IOCTLWRITE+$47400+ 4; { set modem control state }
+                TIOCM_LE        =$0001;         { line enable }
+                TIOCM_DTR       =$0002;         { data terminal ready }
+                TIOCM_RTS       =$0004;         { request to send }
+                TIOCM_ST        =$0010;         { secondary transmit }
+                TIOCM_SR        =$0020;         { secondary receive }
+                TIOCM_CTS       =$0040;         { clear to send }
+                TIOCM_CAR       =$0100;         { carrier detect }
+                TIOCM_CD        =TIOCM_CAR;
+                TIOCM_RNG       =$0200;         { ring }
+                TIOCM_RI        =TIOCM_RNG;
+                TIOCM_DSR       =$0400;         { data set ready }
+                                                { 8-10 compat }
+        TIOCEXCL         =IOCTLVOID+$7400+ 13;          { set exclusive use of tty }
+        TIOCNXCL         =IOCTLVOID+$7400+ 14;          { reset exclusive use of tty }
+                                                { 15 unused }
+        TIOCFLUSH        =IOCTLWRITE+$47400+ 16;        { flush buffers }
+                                                { 17-18 compat }
+        TIOCGETA         =IOCTLREAD+$2C7400+ 19; { get termios struct }
+        TIOCSETA         =IOCTLWRITE+$2C7400+ 20; { set termios struct }
+        TIOCSETAW        =IOCTLWRITE+$2C7400+ 21; { drain output, set }
+        TIOCSETAF        =IOCTLWRITE+$2C7400+ 22; { drn out, fls in, set }
+        TIOCGETD         =IOCTLREAD+$47400+ 26; { get line discipline }
+        TIOCSETD         =IOCTLWRITE+$47400+ 27;        { set line discipline }
+                                                { 127-124 compat }
+        TIOCSBRK         =IOCTLVOID+$7400+ 123;         { set break bit }
+        TIOCCBRK         =IOCTLVOID+$7400+ 122;         { clear break bit }
+        TIOCSDTR         =IOCTLVOID+$7400+ 121;         { set data terminal ready }
+        TIOCCDTR         =IOCTLVOID+$7400+ 120;         { clear data terminal ready }
+        TIOCGPGRP        =IOCTLREAD+$47400+ 119;        { get pgrp of tty }
+        TIOCSPGRP        =IOCTLWRITE+$47400+ 118;       { set pgrp of tty }
+                                                { 117-116 compat }
+        TIOCOUTQ         =IOCTLREAD+$47400+ 115;        { output queue size }
+        TIOCSTI          =IOCTLWRITE+$17400+ 114;       { simulate terminal input }
+        TIOCNOTTY        =IOCTLVOID+$7400+ 113;         { void tty association }
+        TIOCPKT          =IOCTLWRITE+$47400+ 112;       { pty: set/clear packet mode }
+                TIOCPKT_DATA            =$00;   { data packet }
+                TIOCPKT_FLUSHREAD       =$01;   { flush packet }
+                TIOCPKT_FLUSHWRITE      =$02;   { flush packet }
+                TIOCPKT_STOP            =$04;   { stop output }
+                TIOCPKT_START           =$08;   { start output }
+                TIOCPKT_NOSTOP          =$10;   { no more ^S, ^Q }
+                TIOCPKT_DOSTOP          =$20;   { now do ^S ^Q }
+                TIOCPKT_IOCTL           =$40;   { state change of pty driver }
+        TIOCSTOP         =IOCTLVOID+$7400+ 111;         { stop output, like ^S }
+        TIOCSTART        =IOCTLVOID+$7400+ 110;         { start output, like ^Q }
+        TIOCMSET         =IOCTLWRITE+$47400+ 109;       { set all modem bits }
+        TIOCMBIS         =IOCTLWRITE+$47400+ 108;       { bis modem bits }
+        TIOCMBIC         =IOCTLWRITE+$47400+ 107;       { bic modem bits }
+        TIOCMGET         =IOCTLREAD+$47400+ 106;        { get all modem bits }
+        TIOCREMOTE       =IOCTLWRITE+$47400+ 105;       { remote input editing }
+        TIOCGWINSZ       =IOCTLREAD+$87400+ 104;        { get window size }
+        TIOCSWINSZ       =IOCTLWRITE+$87400+ 103;       { set window size }
+        TIOCUCNTL        =IOCTLWRITE+$47400+ 102;       { pty: set/clr usr cntl mode }
+        TIOCSTAT         =IOCTLVOID+$7400+ 101;         { simulate ^T status message }
+  //                       UIOCCMD(n)   _IO('u', n)     { usr cntl op "n" }
+        TIOCCONS         =IOCTLWRITE+$47400+ 98;        { become virtual console }
+        TIOCSCTTY        =IOCTLVOID+$7400+ 97;          { become controlling tty }
+        TIOCEXT          =IOCTLWRITE+$47400+ 96;        { pty: external processing }
+        TIOCSIG          =IOCTLVOID+$7400+ 95;          { pty: generate signal }
+        TIOCDRAIN        =IOCTLVOID+$7400+ 94;          { wait till output drained }
+        TIOCMSDTRWAIT    =IOCTLWRITE+$47400+ 91;        { modem: set wait on close }
+        TIOCMGDTRWAIT    =IOCTLREAD+$47400+ 90; { modem: get wait on close }
+        TIOCTIMESTAMP    =IOCTLREAD+$87400+ 89;         { enable/get timestamp
+                                                 * of last input event }
+        TIOCDCDTIMESTAMP =IOCTLREAD+$87400+ 88; { enable/get timestamp
+                                                 * of last DCd rise }
+        TIOCSDRAINWAIT   =IOCTLWRITE+$47400+ 87;        { set ttywait timeout }
+        TIOCGDRAINWAIT   =IOCTLREAD+$47400+ 86; { get ttywait timeout }
+
+        TTYDISC          =0;            { termios tty line discipline }
+        SLIPDISC         =4;            { serial IP discipline }
+        PPPDISC          =5;            { PPP discipline }
+        NETGRAPHDISC     =6;            { Netgraph tty node discipline }
 
 
 {
  * Defaults on "first" open.
  }
-      	TTYDEF_IFLAG	 =(BRKINT	or ICRNL	or IMAXBEL or IXON or IXANY);
-       TTYDEF_OFLAG	 =(OPOST or ONLCR);
-       TTYDEF_LFLAG	 =(ECHO or ICANON or ISIG or IEXTEN or ECHOE or ECHOKE or ECHOCTL);
-      	TTYDEF_CFLAG	 =(CREAD or CS8 or HUPCL);
-       TTYDEF_SPEED	 =(B9600);
+        TTYDEF_IFLAG     =(BRKINT       or ICRNL        or IMAXBEL or IXON or IXANY);
+       TTYDEF_OFLAG      =(OPOST or ONLCR);
+       TTYDEF_LFLAG      =(ECHO or ICANON or ISIG or IEXTEN or ECHOE or ECHOKE or ECHOCTL);
+        TTYDEF_CFLAG     =(CREAD or CS8 or HUPCL);
+       TTYDEF_SPEED      =(B9600);
 
 
 
 {
  * Control Character Defaults
  }
-        CtrlMask	= $1f;	{\037}
-      	CEOF		=chr( ORD('d') and CtrlMask);
-      	CEOL		=chr( $ff and CtrlMask);{ XXX avoid _POSIX_VDISABLE }
-      	CERASE		=chr( $7F and CtrlMask);
-      	CINTR		=chr(ORD('c') and CtrlMask);
-      	CSTATUS		=chr(ORD('t') and CtrlMask);
-      	CKILL		=chr(ORD('u') and CtrlMask);
-      	CMIN		=chr(1);
-      	CQUIT		=chr(034  and CtrlMask);	{ FS, ^\ }
-      	CSUSP		=chr(ORD('z') and CtrlMask);
-      	CTIME		=chr(0);
-      	CDSUSP		=chr(ORD('y') and CtrlMask);
-      	CSTART		=chr(ORD('q') and CtrlMask);
-      	CSTOP		=chr(ORD('s') and CtrlMask);
-      	CLNEXT		=chr(ORD('v') and CtrlMask);
-      	CDISCARD 	=chr(ORD('o') and CtrlMask);
-      	CWERASE 	=chr(ORD('w') and CtrlMask);
-      	CREPRINT 	=chr(ORD('r') and CtrlMask);
-      	CEOT		=CEOF;
+        CtrlMask        = $1f;  {\037}
+        CEOF            =chr( ORD('d') and CtrlMask);
+        CEOL            =chr( $ff and CtrlMask);{ XXX avoid _POSIX_VDISABLE }
+        CERASE          =chr( $7F and CtrlMask);
+        CINTR           =chr(ORD('c') and CtrlMask);
+        CSTATUS         =chr(ORD('t') and CtrlMask);
+        CKILL           =chr(ORD('u') and CtrlMask);
+        CMIN            =chr(1);
+        CQUIT           =chr(034  and CtrlMask);        { FS, ^\ }
+        CSUSP           =chr(ORD('z') and CtrlMask);
+        CTIME           =chr(0);
+        CDSUSP          =chr(ORD('y') and CtrlMask);
+        CSTART          =chr(ORD('q') and CtrlMask);
+        CSTOP           =chr(ORD('s') and CtrlMask);
+        CLNEXT          =chr(ORD('v') and CtrlMask);
+        CDISCARD        =chr(ORD('o') and CtrlMask);
+        CWERASE         =chr(ORD('w') and CtrlMask);
+        CREPRINT        =chr(ORD('r') and CtrlMask);
+        CEOT            =CEOF;
 { compat }
-      	CBRK		=CEOL;
-        CRPRNT		=CREPRINT;
-      	CFLUSH		=CDISCARD;
+        CBRK            =CEOL;
+        CRPRNT          =CREPRINT;
+        CFLUSH          =CDISCARD;
 
 
 {
  *        TTYDEFCHARS to include an array of default control characters.
 }
     ttydefchars : array[0..NCCS-1] OF char =(
-	CEOF,	CEOL,	CEOL,	CERASE, CWERASE, CKILL, CREPRINT,
-	POSIX_VDISABLE, CINTR,	CQUIT,	CSUSP,	CDSUSP,	CSTART,	CSTOP,	CLNEXT,
-	CDISCARD, CMIN,	CTIME,  CSTATUS, POSIX_VDISABLE);
+        CEOF,   CEOL,   CEOL,   CERASE, CWERASE, CKILL, CREPRINT,
+        POSIX_VDISABLE, CINTR,  CQUIT,  CSUSP,  CDSUSP, CSTART, CSTOP,  CLNEXT,
+        CDISCARD, CMIN, CTIME,  CSTATUS, POSIX_VDISABLE);
 
+{
+  $Log$
+  Revision 1.3  2004-01-04 01:11:28  marco
+   * a new qod port of the freebsd rtl. To be refined in the coming days.
+
+  Revision 1.4  2004/01/03 12:18:29  marco
+   * a lot of copyright notices and CVS logs added and fixed
 
+}

+ 376 - 48
rtl/netbsd/tthread.inc

@@ -1,19 +1,21 @@
-{
-    $Id$
-    This file is part of the Free Component Library (FCL)
-    Copyright (c) 1999-2000 by Peter Vreman
+{  
+   $Id$
+   This file is part of the Free Pascal run time library.
+   (c) 2000-2003 by Marco van de Voort
+   member of the Free Pascal development team.
 
-    Linux TThread implementation
+   See the file COPYING.FPC, included in this distribution,
+   for details about the copyright.
 
-    See the file COPYING.FPC, included in this distribution,
-    for details about the copyright.
+   TThread implementation old (1.0) and new (pthreads) style
 
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY;without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+}
 
- **********************************************************************}
 
+{$IFDEF VER1_0} // leaving the old implementation in for now...
 type
   PThreadRec=^TThreadRec;
   TThreadRec=record
@@ -32,7 +34,7 @@ Const
 function ThreadSelf:TThread;
 var
   hp : PThreadRec;
-  sp : longint;
+  sp : Pointer;
 begin
   sp:=SPtr;
   hp:=ThreadRoot;
@@ -52,15 +54,14 @@ end;
 
 //function SIGCHLDHandler(Sig: longint): longint; cdecl;//this is std linux C declaration as function
 procedure SIGCHLDHandler(Sig: longint); cdecl;
+
 begin
-  waitpid(-1, nil, WNOHANG);
+  fpwaitpid(-1, nil, WNOHANG);
 end;
 
-Const sigzero : sigset_t = (0,0,0,0); //Do not block all signals ??. Don't need if SA_NOMASK in flags
-
 procedure InitThreads;
 var
-  Act, OldAct: PSigActionRec;
+  Act, OldAct: Baseunix.PSigActionRec;
 begin
   ThreadRoot:=nil;
   ThreadsInited:=true;
@@ -73,20 +74,10 @@ begin
   GetMem(Act, SizeOf(SigActionRec));
   GetMem(OldAct, SizeOf(SigActionRec));
 
-  {$ifdef ver1_0}
-  Act^.handler.sh := @SIGCHLDHandler;
-  {$else}
-  Act^.sa_handler := @SIGCHLDHandler;
-  {$endif}
-  
+  Act^.sa_handler := TSigAction(@SIGCHLDHandler);
   Act^.sa_flags := SA_NOCLDSTOP {or SA_NOMASK or SA_RESTART};
-  
-  {$ifdef VER1_0}
-   Act^.sa_mask[0] := 0; //Do not block all signals ??. Don't need if SA_NOMASK in flags
-  {$else}
-   Act^.sa_mask := sigzero;
-  {$endif} 
-  SigAction(SIGCHLD, Act, OldAct);
+  Fillchar(Act^.sa_mask,sizeof(Act^.sa_mask),0); //Do not block all signals ??. Don't need if SA_NOMASK in flags
+  FpSigAction(SIGCHLD, Act, OldAct);
 
   FreeMem(Act, SizeOf(SigActionRec));
   FreeMem(OldAct, SizeOf(SigActionRec));
@@ -158,6 +149,8 @@ var
   FreeThread: Boolean;
   Thread : TThread absolute args;
 begin
+  while Thread.FHandle = 0 do fpsleep(1);
+  if Thread.FSuspended then Thread.suspend();
   try
     Thread.Execute;
   except
@@ -169,7 +162,7 @@ begin
   Thread.DoTerminate;
   if FreeThread then
     Thread.Free;
-  ExitProcess(Result);
+  fpexit(Result);
 end;
 
 
@@ -183,12 +176,12 @@ begin
   Flags := CLONE_VM + CLONE_FS + CLONE_FILES + CLONE_SIGHAND + SIGCHLD;
   { Setup 16k of stack }
   FStackSize:=16384;
-  Getmem(pointer(FStackPointer),FStackSize);
+  Getmem(FStackPointer,FStackSize);
   inc(FStackPointer,FStackSize);
   FCallExitProcess:=false;
   { Clone }
-  FHandle:= Clone(@ThreadProc,pointer(FStackPointer),Flags,self);
-  if FSuspended then Suspend;
+  FHandle:= Clone(@ThreadProc,FStackPointer,Flags,self);
+//  if FSuspended then Suspend;
   FThreadID := FHandle;
   IsMultiThread := TRUE;
   FFatalException := nil;
@@ -203,9 +196,9 @@ begin
      WaitFor;
    end;
   if FHandle <> -1 then
-    Kill(FHandle, SIGKILL);
+    fpkill(FHandle, SIGKILL);
   dec(FStackPointer,FStackSize);
-  Freemem(pointer(FStackPointer),FStackSize);
+  Freemem(FStackPointer);
   FFatalException.Free;
   FFatalException := nil;
   inherited Destroy;
@@ -236,7 +229,7 @@ var
   P: Integer;
   I: TThreadPriority;
 begin
-  P := {$ifdef ver1_0}Linux{$else}Unix{$endif}.GetPriority(Prio_Process,FHandle);
+  P := fpGetPriority(Prio_Process,FHandle);
   Result := tpNormal;
   for I := Low(TThreadPriority) to High(TThreadPriority) do
     if Priorities[I] = P then
@@ -246,7 +239,7 @@ end;
 
 procedure TThread.SetPriority(Value: TThreadPriority);
 begin
-  {$ifdef ver1_0}Linux{$else}Unix{$endif}.SetPriority(Prio_Process,FHandle, Priorities[Value]);
+  fpSetPriority(Prio_Process,FHandle,Priorities[Value]);
 end;
 
 
@@ -272,14 +265,14 @@ end;
 
 procedure TThread.Suspend;
 begin
-  Kill(FHandle, SIGSTOP);
   FSuspended := true;
+  fpKill(FHandle, SIGSTOP);
 end;
 
 
 procedure TThread.Resume;
 begin
-  Kill(FHandle, SIGCONT);
+  fpKill(FHandle, SIGCONT);
   FSuspended := False;
 end;
 
@@ -294,27 +287,362 @@ var
   status : longint;
 begin
   if FThreadID = MainThreadID then
-   WaitPid(0,@status,0)
+    fpwaitpid(0,@status,0)
   else
-   WaitPid(FHandle,@status,0);
+    fpwaitpid(FHandle,@status,0);
   Result:=status;
 end;
+{$ELSE}
+
+{
+  What follows, is a short description on my implementation of TThread.
+  Most information can also be found by reading the source and accompanying
+  comments.
+  
+  A thread is created using BeginThread, which in turn calls
+  pthread_create. So the threads here are always posix threads.
+  Posix doesn't define anything for suspending threads as this is
+  inherintly unsafe. Just don't suspend threads at points they cannot
+  control. Therefore, I didn't implement .Suspend() if its called from
+  outside the threads execution flow (except on Linux _without_ NPTL).
+  
+  The implementation for .suspend uses a semaphore, which is initialized
+  at thread creation. If the thread tries to suspend itself, we simply
+  let it wait on the semaphore until it is unblocked by someone else
+  who calls .Resume.
+
+  If a thread is supposed to be suspended (from outside its own path of
+  execution) on a system where the symbol LINUX is defined, two things
+  are possible.
+  1) the system has the LinuxThreads pthread implementation
+  2) the system has NPTL as the pthread implementation.
+  
+  In the first case, each thread is a process on its own, which as far as
+  know actually violates posix with respect to signal handling.
+  But we can detect this case, because getpid(2) will
+  return a different PID for each thread. In that case, sending SIGSTOP
+  to the PID associated with a thread will actually stop that thread
+  only.
+  In the second case, this is not possible. But getpid(2) returns the same
+  PID across all threads, which is detected, and TThread.Suspend() does
+  nothing in that case. This should probably be changed, but I know of
+  no way to suspend a thread when using NPTL.
+  
+  If the symbol LINUX is not defined, then the unimplemented
+  function SuspendThread is called.
+  
+  Johannes Berg <[email protected]>, Sunday, November 16 2003
+}
+
+// ========== semaphore stuff ==========
+{
+  I don't like this. It eats up 2 filedescriptors for each thread,
+  and those are a limited resource. If you have a server programm
+  handling client connections (one per thread) it will not be able
+  to handle many if we use 2 fds already for internal structures.
+  However, right now I don't see a better option unless some sem_*
+  functions are added to systhrds.
+  I encapsulated all used functions here to make it easier to
+  change them completely.
+}
+
+function SemaphoreInit: Pointer;
+begin
+  SemaphoreInit := GetMem(SizeOf(TFilDes));
+  fppipe(PFilDes(SemaphoreInit)^);
+end;
+
+procedure SemaphoreWait(const FSem: Pointer);
+var
+  b: byte;
+begin
+  fpread(PFilDes(FSem)^[0], b, 1);
+end;
+
+procedure SemaphorePost(const FSem: Pointer);
+begin
+  fpwrite(PFilDes(FSem)^[1], #0, 1);
+end;
+
+procedure SemaphoreDestroy(const FSem: Pointer);
+begin
+  fpclose(PFilDes(FSem)^[0]);
+  fpclose(PFilDes(FSem)^[1]);
+  FreeMemory(FSem);
+end;
+
+// =========== semaphore end ===========
+
+var
+  ThreadsInited: boolean = false;
+{$IFDEF LINUX}
+  GMainPID: LongInt = 0;
+{$ENDIF}
+const
+  // stupid, considering its not even implemented...
+  Priorities: array [TThreadPriority] of Integer =
+   (-20,-19,-10,0,9,18,19);
+
+procedure InitThreads;
+begin
+  if not ThreadsInited then begin
+    ThreadsInited := true;
+    {$IFDEF LINUX}
+    GMainPid := fpgetpid();
+    {$ENDIF}
+  end;
+end;
+
+procedure DoneThreads;
+begin
+  ThreadsInited := false;
+end;
+
+{ ok, so this is a hack, but it works nicely. Just never use
+  a multiline argument with WRITE_DEBUG! }
+{$MACRO ON}
+{$IFDEF DEBUG_MT}
+{$define WRITE_DEBUG := writeln} // actually write something
+{$ELSE}
+{$define WRITE_DEBUG := //}      // just comment out those lines
+{$ENDIF}
+
+function ThreadFunc(parameter: Pointer): LongInt; cdecl;
+var
+  LThread: TThread;
+  c: char;
+begin
+  WRITE_DEBUG('ThreadFunc is here...');
+  LThread := TThread(parameter);
+  {$IFDEF LINUX}
+  // save the PID of the "thread"
+  // this is different from the PID of the main thread if
+  // the LinuxThreads implementation is used
+  LThread.FPid := fpgetpid();
+  {$ENDIF}
+  WRITE_DEBUG('thread initing, parameter = ', LongInt(LThread));
+  try
+    if LThread.FInitialSuspended then begin
+      SemaphoreWait(LThread.FSem);
+      if not LThread.FInitialSuspended then begin
+        WRITE_DEBUG('going into LThread.Execute');
+        LThread.Execute;
+      end;
+    end else begin
+      WRITE_DEBUG('going into LThread.Execute');
+      LThread.Execute;
+    end;
+  except
+    on e: exception do begin
+      WRITE_DEBUG('got exception: ',e.message);
+      LThread.FFatalException :=  TObject(AcquireExceptionObject);
+      // not sure if we should really do this...
+      // but .Destroy was called, so why not try FreeOnTerminate?
+      if e is EThreadDestroyCalled then LThread.FFreeOnTerminate := true;
+    end;
+  end;
+  WRITE_DEBUG('thread done running');
+  Result := LThread.FReturnValue;
+  WRITE_DEBUG('Result is ',Result);
+  LThread.FFinished := True;
+  LThread.DoTerminate;
+  if LThread.FreeOnTerminate then begin
+    WRITE_DEBUG('Thread should be freed');
+    LThread.Free;
+    WRITE_DEBUG('Thread freed');
+  end;
+  WRITE_DEBUG('thread func exiting');
+end;
+
+{ TThread }
+constructor TThread.Create(CreateSuspended: Boolean);
+begin
+  // lets just hope that the user doesn't create a thread
+  // via BeginThread and creates the first TThread Object in there!
+  InitThreads;
+  inherited Create;
+  FSem := SemaphoreInit;
+  FSuspended := CreateSuspended;
+  FSuspendedExternal := false;
+  FInitialSuspended := CreateSuspended;
+  FFatalException := nil;
+  WRITE_DEBUG('creating thread, self = ',longint(self));
+  FHandle:= BeginThread(@ThreadFunc, Pointer(Self), FThreadID);
+  WRITE_DEBUG('TThread.Create done');
+end;
+
+
+destructor TThread.Destroy;
+begin
+  if FThreadID = GetCurrentThreadID then begin
+    raise EThreadDestroyCalled.Create('A thread cannot destroy itself except by setting FreeOnTerminate and leaving!');
+  end;
+  // if someone calls .Free on a thread with
+  // FreeOnTerminate, then don't crash!
+  FFreeOnTerminate := false;
+  if not FFinished and not FSuspended then begin
+    Terminate;
+    WaitFor;
+  end;
+  if (FInitialSuspended) then begin
+    // thread was created suspended but never woken up.
+    SemaphorePost(FSem);
+    WaitFor;
+  end;
+  FFatalException.Free;
+  FFatalException := nil;
+  SemaphoreDestroy(FSem);
+  inherited Destroy;
+end;
+
+procedure TThread.SetSuspended(Value: Boolean);
+begin
+  if Value <> FSuspended then
+    if Value then
+      Suspend
+    else
+      Resume;
+end;
+
+procedure TThread.Suspend;
+begin
+  if not FSuspended then begin
+    if FThreadID = GetCurrentThreadID then begin
+      FSuspended := true;
+      SemaphoreWait(FSem);
+    end else begin
+      FSuspendedExternal := true;
+{$IFDEF LINUX}
+      // naughty hack if the user doesn't have Linux with NPTL...
+      // in that case, the PID of threads will not be identical
+      // to the other threads, which means that our thread is a normal
+      // process that we can suspend via SIGSTOP...
+      // this violates POSIX, but is the way it works on the
+      // LinuxThreads pthread implementation. Not with NPTL, but in that case
+      // getpid(2) also behaves properly and returns the same PID for
+      // all threads. Thats actually (FINALLY!) native thread support :-)
+      if FPid <> GMainPID then begin
+        FSuspended := true;
+        fpkill(FPid, SIGSTOP);
+      end;
+{$ELSE}
+      SuspendThread(FHandle);
+{$ENDIF}
+    end;
+  end;
+end;
+
+
+procedure TThread.Resume;
+begin
+  if (not FSuspendedExternal) then begin
+    if FSuspended then begin
+      SemaphorePost(FSem);
+      FInitialSuspended := false;
+      FSuspended := False;
+    end;
+  end else begin
+{$IFDEF LINUX}
+    // see .Suspend
+    if FPid <> GMainPID then begin
+      fpkill(FPid, SIGCONT);
+      FSuspended := False;
+    end;
+{$ELSE}
+    ResumeThread(FHandle);
+{$ENDIF}
+    FSuspendedExternal := false;
+  end;
+end;
+
+
+procedure TThread.Terminate;
+begin
+  FTerminated := True;
+end;
+
+function TThread.WaitFor: Integer;
+begin
+  WRITE_DEBUG('waiting for thread ',FHandle);
+  WaitFor := WaitForThreadTerminate(FHandle, 0);
+  WRITE_DEBUG('thread terminated');
+end;
+
+procedure TThread.CallOnTerminate;
+begin
+  // no need to check if FOnTerminate <> nil, because
+  // thats already done in DoTerminate
+  FOnTerminate(self);
+end;
+
+procedure TThread.DoTerminate;
+begin
+  if Assigned(FOnTerminate) then
+    Synchronize(@CallOnTerminate);
+end;
+
+function TThread.GetPriority: TThreadPriority;
+var
+  P: Integer;
+  I: TThreadPriority;
+begin
+  P := ThreadGetPriority(FHandle);
+  Result := tpNormal;
+  for I := Low(TThreadPriority) to High(TThreadPriority) do
+    if Priorities[I] = P then
+      Result := I;
+end;
+
+procedure TThread.Synchronize(Method: TThreadMethod);
+begin
+{$TODO someone with more clue of the GUI stuff will have to do this}
+end;
+
+procedure TThread.SetPriority(Value: TThreadPriority);
+begin
+  ThreadSetPriority(FHandle, Priorities[Value]);
+end;
+{$ENDIF}
 
 {
   $Log$
-  Revision 1.1  2003-10-06 21:01:06  peter
+  Revision 1.2  2004-01-04 01:11:28  marco
+   * a new qod port of the freebsd rtl. To be refined in the coming days.
+
+  Revision 1.8  2004/01/03 12:18:29  marco
+   * a lot of copyright notices and CVS logs added and fixed
+
+  Revision 1.7  2003/11/22 11:04:08  marco
+   * Johill: suspend fix
+
+  Revision 1.6  2003/11/19 10:12:02  marco
+   * more cleanups
+
+  Revision 1.5  2003/11/17 10:05:51  marco
+   * threads for FreeBSD. Not working tho
+
+  Revision 1.4  2003/11/17 08:27:49  marco
+   * pthreads based ttread from Johannes Berg
+
+  Revision 1.3  2003/11/10 16:54:28  marco
+   * new oldlinux unit. 1_0 defines killed in some former FCL parts.
+
+  Revision 1.2  2003/11/03 09:42:28  marco
+   * Peter's Cardinal<->Longint fixes patch
+
+  Revision 1.1  2003/10/06 21:01:06  peter
     * moved classes unit to rtl
 
-  Revision 1.6  2003/10/06 17:06:55  florian
+  Revision 1.9  2003/10/06 17:06:55  florian
     * applied Johannes Berg's patch for exception handling in threads
 
-  Revision 1.5  2003/01/31 14:49:56  pierre
-   * adapt 1.0 to change in signal.inc
+  Revision 1.8  2003/09/20 15:10:30  marco
+   * small fixes. fcl now compiles
 
-  Revision 1.4  2003/01/24 21:13:31  marco
-   * More bugs, but now gmake all works.
+  Revision 1.7  2002/12/18 20:44:36  peter
+    * use fillchar to clear sigset
 
-  Revision 1.3  2002/09/07 15:15:27  peter
+  Revision 1.6  2002/09/07 15:15:27  peter
     * old logs removed and tabs fixed
 
 }

+ 29 - 12
rtl/netbsd/unixsock.inc

@@ -1,4 +1,19 @@
-{ $Id$ }
+{  
+   $Id$
+   This file is part of the Free Pascal run time library.
+   (c) 2000-2003 by Marco van de Voort
+   member of the Free Pascal development team.
+
+   See the file COPYING.FPC, included in this distribution,
+   for details about the copyright.
+   
+   socket call implementations for FreeBSD
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY;without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+}
+
 
 {******************************************************************************
                           Basic Socket Functions
@@ -11,7 +26,7 @@ end;
 
 Function CloseSocket (Sock:Longint):Longint;
 begin
-  if fdClose (Sock) then
+  if fpclose(Sock)=0 then
     CloseSocket := 0 else
     CloseSocket := -1;
 end;
@@ -197,20 +212,22 @@ end;
 
 {
  $Log$
- Revision 1.3  2003-03-23 17:47:15  armin
- * CloseSocket added
+ Revision 1.4  2004-01-04 01:11:28  marco
+  * a new qod port of the freebsd rtl. To be refined in the coming days.
 
- Revision 1.2  2003/01/21 15:39:45  marco
-  * NetBSD first rtl. Still not 100%, but close
+ Revision 1.9  2004/01/03 12:18:29  marco
+  * a lot of copyright notices and CVS logs added and fixed
 
- Revision 1.1.2.3  2002/09/20 07:06:15  pierre
-  *avoid $Id to be treated as a directive
+ Revision 1.8  2003/09/15 07:09:58  marco
+  * small fixes, round 1
 
- Revision 1.1.2.2  2002/03/04 07:13:49  marco
-  * Something that was forgotten.
+ Revision 1.7  2003/03/23 17:47:15  armin
+ * CloseSocket added
 
- Revision 1.1.2.4  2002/02/05 07:47:46  marco
-  * Fixed typo
+ Revision 1.6  2002/09/07 16:01:18  peter
+   * old logs removed and tabs fixed
 
+ Revision 1.5  2002/02/05 07:54:34  marco
+  * Fixed typo
 
 }

+ 163 - 617
rtl/netbsd/unixsysc.inc

@@ -13,22 +13,7 @@
 
 **********************************************************************}
 
-Function Fork:longint;
 {
-  This function issues the 'fork' System call. the program is duplicated in memory
-  and Execution continues in parent and child process.
-  In the parent process, fork returns the PID of the child. In the child process,
-  zero is returned.
-  A negative value indicates that an error has occurred, the error is returned in
-  LinuxError.
-}
-
-Begin
- fork:=Do_syscall(SysCall_nr_fork);
- LinuxError:=ErrNo;
-End;
-
-(*
 function clone(func:TCloneFunc;sp:pointer;flags:longint;args:pointer):longint;
 {NOT IMPLEMENTED YET UNDER BSD}
 begin // perhaps it is better to implement the hack from solaris then this msg
@@ -37,7 +22,7 @@ END;
 
   if (pointer(func)=nil) or (sp=nil) then
    begin
-     LinuxError:=ESysEInval;
+     Lfpseterrno(EsysEInval);
      exit(-1);
    end;
   asm
@@ -75,320 +60,33 @@ END;
         movl    %eax,__RESULT
   end;
 end;
- *)
-
-Procedure Execve(path:pathstr;args:ppchar;ep:ppchar);
-{
-  Replaces the current program by the program specified in path,
-  arguments in args are passed to Execve.
-  environment specified in ep is passed on.
-}
-
-Begin
-  path:=path+#0;
-  do_syscall(syscall_nr_Execve,longint(@path[1]),longint(Args),longint(ep));
- LinuxError:=ErrNo;
-End;
-
-Function Umask(Mask:Integer):integer;
-{
-  Sets file creation mask to (Mask and 0777 (octal) ), and returns the
-  previous value.
-}
-begin
- UMask:=Do_syscall(syscall_nr_umask,mask);
- LinuxError:=0;
-end;
-
-Procedure Nice(N:integer);
-{
-  Set process priority. A positive N means a lower priority.
-  A negative N decreases priority.
-
-Doesn't exist in BSD. Linux emu uses setpriority in a construct as below:
-}
-
-begin
-  SetPriority(Prio_Process,0,N);
-end;
-
-Procedure Execve(path:pchar;args:ppchar;ep:ppchar);
-{
-  Replaces the current program by the program specified in path,
-  arguments in args are passed to Execve.
-  environment specified in ep is passed on.
-}
-
-{
-  Replaces the current program by the program specified in path,
-  arguments in args are passed to Execve.
-  environment specified in ep is passed on.
-}
-
-Begin
-  do_syscall(syscall_nr_Execve,longint(path),longint(Args),longint(ep));
- LinuxError:=ErrNo;
-End;
-
-Procedure ExitProcess(val:longint);
-
-begin
- do_syscall(Syscall_nr_exit,val);
- LinuxError:=ErrNo;
-end;
-
-Function WaitPid(Pid:longint;Status:pointer;Options:longint):Longint;
-{
-  Waits until a child with PID Pid exits, or returns if it is exited already.
-  Any resources used by the child are freed.
-  The exit status is reported in the adress referred to by Status. It should
-  be a longint.
-}
-
-begin
- WaitPID:=do_syscall(syscall_nr_WaitPID,PID,longint(Status),options,0);
- LinuxError:=ErrNo;
-end;
-
-Function GetPriority(Which,Who:longint):longint;
-{
-  Get Priority of process, process group, or user.
-   Which : selects what kind of priority is used.
-           can be one of the following predefined Constants :
-              Prio_User.
-              Prio_PGrp.
-              Prio_Process.
-   Who : depending on which, this is , respectively :
-              Uid
-              Pid
-              Process Group id
-   Errors are reported in linuxerror _only_. (priority can be negative)
-}
-begin
-  errno:=0;
-  if (which<prio_process) or (which>prio_user) then
-   begin
-     { We can save an interrupt here }
-     getpriority:=0;
-     linuxerror:=ESyseinval;
-   end
-  else
-   begin
-     GetPriority:=do_syscall(syscall_nr_GetPriority,which,who);
-     LinuxError:=ErrNo;
-   end;
-end;
-
-Procedure SetPriority(Which,Who,What:longint);
-{
- Set Priority of process, process group, or user.
-   Which : selects what kind of priority is used.
-           can be one of the following predefined Constants :
-              Prio_User.
-              Prio_PGrp.
-              Prio_Process.
-   Who : depending on value of which, this is, respectively :
-              Uid
-              Pid
-              Process Group id
-   what : A number between -20 and 20. -20 is most favorable, 20 least.
-          0 is the default.
-}
-begin
-  errno:=0;
-  if ((which<prio_process) or (which>prio_user)) or ((what<-20) or (what>20)) then
-   linuxerror:=ESyseinval  { We can save an interrupt here }
-  else
-   begin
-     do_syscall(Syscall_nr_Setpriority,which,who,what);
-     LinuxError:=ErrNo;
-   end;
-end;
-
-
-Function GetPid:LongInt;
-{
-  Get Process ID.
-}
-
-begin
- GetPID:=do_syscall(Syscall_nr_GetPID);
- LinuxError:=errno;
-end;
-
-Function GetPPid:LongInt;
-{
-  Get Process ID of parent process.
-}
-
-
-begin
-  GetPPid:=do_syscall(Syscall_nr_GetPPid);
-  LinuxError:=errno;
-end;
-
-Function GetUid:Longint;
-{
-  Get User ID.
-}
-
-begin
-  GetUID:=do_syscall(Syscall_nr_GetUID);
-  LinuxError:=ErrNo;
-end;
-
-Function GetEUid:Longint;
-{
-  Get _effective_ User ID.
-}
-
-begin
-  GetEUID:=do_syscall(Syscall_nr_GetEUID);
-  LinuxError:=ErrNo;
-end;
-
-
-Function GetGid:Longint;
-{
-  Get Group ID.
-}
-
-begin
-  GetGID:=do_syscall(Syscall_nr_getgid);
-  LinuxError:=ErrNo;
-end;
-
-
-Function GetEGid:Longint;
-{
-  Get _effective_ Group ID.
-}
-
-begin
- GetEGID:=do_syscall(syscall_nr_getegid);
- LinuxError:=ErrNo;
-end;
-
-Procedure GetTimeOfDay(var tv:timeval);
-{
-  Get the number of seconds since 00:00, January 1 1970, GMT
-  the time NOT corrected any way
-}
-
-var  tz : timezone;
-
-begin
- do_syscall(syscall_nr_gettimeofday,longint(@tv),longint(@tz));
- LinuxError:=Errno;
-end;
-
-Function GetTimeOfDay: longint;
-{
-  Get the number of seconds since 00:00, January 1 1970, GMT
-  the time NOT corrected any way
-}
-begin
-  GetTimeOfDay:=Sys_time;
-  LinuxError:=Errno;
-end;
-
-Function fdTruncate(fd,size:longint):boolean;
-
-begin
- fdtruncate:=do_syscall(syscall_nr_ftruncate,fd,size,0)=0;
- LinuxError:=Errno;
-end;
-
-Function  fdFlush (fd : Longint) : Boolean;
-
-begin
-  fdflush:=do_syscall(syscall_nr_fsync,fd)=0;
-  LinuxError:=Errno;
-end;
-
-{$ifndef newreaddir}
-function sys_fcntl(Fd:longint;Cmd:longint;Arg:Longint):longint;
-
-begin
- sys_fcntl:=do_syscall(syscall_nr_fcntl,fd,cmd,arg);
- LinuxError:=Errno;
-end;
-{$endif}
-
-Function Chmod(path:pathstr;Newmode:longint):Boolean;
-{
-  Changes the permissions of a file.
-}
-
-begin
-  path:=path+#0;
-  chmod:=do_syscall(syscall_nr_chmod,longint(@path[1]),newmode)=0;
-  LinuxError:=Errno;
-end;
-
-Function Chown(path:pathstr;NewUid,NewGid:longint):boolean;
-{
-  Change the owner and group of a file.
-  A user can only change the group to a group of which he is a member.
-  The super-user can change uid and gid of any file.
 }
 
-begin
-  path:=path+#0;
-  ChOwn:=do_syscall(syscall_nr_chown,longint(@path[1]),newuid,newgid)=0;
- LinuxError:=Errno;
-end;
-
-Function Utime(path:pathstr;utim:utimebuf):boolean;
-
-begin
-  UTime:=do_syscall(syscall_nr_utimes,longint(@path[1]),longint(@utim))=0;
-  LinuxError:=Errno;
-end;
-
-Function  Flock (fd,mode : longint) : boolean;
+{$ifndef FPC_USE_LIBC}
+Function  fsync (fd : cint) : cint;
 
 begin
- Flock:=do_syscall(syscall_nr_flock,fd,mode)=0;
- LinuxError:=Errno;
+  fsync:=do_syscall(syscall_nr_fsync,fd);
 end;
 
-Function Lstat(Filename: PathStr;var Info:stat):Boolean;
-{
-  Get all information on a link (the link itself), and return it in info.
-}
+Function  Flock (fd,mode : longint) : cint;
 
 begin
- FileName:=FileName+#0;
- LStat:=do_syscall(syscall_nr_lstat,longint(@filename[1]),longint(@info))=0;
- LinuxError:=Errno;
+ Flock:=do_syscall(syscall_nr_flock,fd,mode);
 end;
 
-Function Fstat(Fd:Longint;var Info:stat):Boolean;
-{
-  Get all information on a file descriptor, and return it in info.
-}
-
-begin
- FStat:=do_syscall(syscall_nr_fstat,fd,longint(@info))=0;
- LinuxError:=Errno;
-end;
-
-Function StatFs(Path:Pathstr;Var Info:tstatfs):Boolean;
-
+Function fStatFS(Fd:Longint;Var Info:tstatfs):cint;
 {
   Get all information on a fileSystem, and return it in Info.
-  Path is the name of a file/directory on the fileSystem you wish to
-  investigate.
+  Fd is the file descriptor of a file/directory on the fileSystem
+  you wish to investigate.
 }
 
 begin
-  path:=path+#0;
-  StatFS:=Do_Syscall(syscall_nr_statfs,longint(@path[1]),longint(@info))=0;
-  LinuxError:=Errno;
+ fStatFS:=do_syscall(syscall_nr_fstatfs,fd,longint(@info));
 end;
 
-Function StatFS(Fd:Longint;Var Info:tstatfs):Boolean;
+Function StatFS(path:pchar;Var Info:tstatfs):cint;
 {
   Get all information on a fileSystem, and return it in Info.
   Fd is the file descriptor of a file/directory on the fileSystem
@@ -396,111 +94,40 @@ Function StatFS(Fd:Longint;Var Info:tstatfs):Boolean;
 }
 
 begin
- StatFS:=do_syscall(syscall_nr_fstatfs,fd,longint(@info))=0;
- LinuxError:=Errno;
-end;
-
-Function Link(OldPath,NewPath:pathstr):boolean;
-{
-  Proceduces a hard link from new to old.
-  In effect, new will be the same file as old.
-}
-begin
-  oldpath:=oldpath+#0;
-  newpath:=newpath+#0;
-  Link:=Do_Syscall(syscall_nr_link,longint(@oldpath[1]),longint(@newpath[1]))=0;
- LinuxError:=Errno;
-end;
-
-(*
-Function SymLink(OldPath,newPath:pathstr):boolean;
-{
-  Proceduces a soft link from new to old.
-}
-
-begin
-  oldpath:=oldpath+#0;
-  newpath:=newpath+#0;
-  SymLink:=Do_Syscall(syscall_nr_symlink,longint(@oldpath[1]),longint(@newpath[1]))=0;
-  LinuxError:=Errno;
+ StatFS:=do_syscall(syscall_nr_statfs,longint(path),longint(@info));
 end;
-*)
 
-Function Access(Path:Pathstr ;mode:longint):boolean;
-{
-  Test users access rights on the specified file.
-  Mode is a mask xosisting of one or more of R_OK, W_OK, X_OK, F_OK.
-  R,W,X stand for read,write and Execute access, simultaneously.
-  F_OK checks whether the test would be allowed on the file.
-  i.e. It checks the search permissions in all directory components
-  of the path.
-  The test is done with the real user-ID, instead of the effective.
-  If access is denied, or an error occurred, false is returned.
-  If access is granted, true is returned.
-  Errors other than no access,are reported in linuxerror.
-}
-
-begin
-  path:=path+#0;
- Access:=do_syscall(syscall_nr_access,longint(@path[1]),mode)=0;
- LinuxError:=Errno;
-end;
-
-Function  Dup(oldfile:longint;var newfile:longint):Boolean;
-{
-  Copies the filedescriptor oldfile to newfile
-}
-
-begin
- newfile:=Do_syscall(syscall_nr_dup,oldfile);
- LinuxError:=Errno;
- Dup:=(LinuxError=0);
-end;
-
-
-Function Dup2(oldfile,newfile:longint):Boolean;
-{
-  Copies the filedescriptor oldfile to newfile
-}
-
-begin
- do_syscall(syscall_nr_dup2,oldfile,newfile);
- LinuxError:=Errno;
- Dup2:=(LinuxError=0);
-end;
-
-
-Function Select(N:longint;readfds,writefds,exceptfds:PFDSet;TimeOut:PTimeVal):longint;
-{
-  Select checks whether the file descriptor sets in readfs/writefs/exceptfs
-  have changed.
-}
-
-begin
- Select:=do_syscall(syscall_nr_select,n,longint(readfds),longint(writefds),longint(exceptfds),longint(timeout));
- LinuxError:=Errno;
-end;
-
-
-Function AssignPipe(var pipe_in,pipe_out:longint):boolean;
+// needs oldfpccall;
+Function intAssignPipe(var pipe_in,pipe_out:longint;var errn:cint):cint; {$ifndef ver1_0} oldfpccall;{$endif} 
 {
   Sets up a pair of file variables, which act as a pipe. The first one can
   be read from, the second one can be written to.
   If the operation was unsuccesful, linuxerror is set.
 }
-var
-  pip  : tpipe;
 
 begin
- do_syscall(syscall_nr_pipe,longint(@pip));
- LinuxError:=Errno;
- pipe_in:=pip[0];
- pipe_out:=pip[1];
- AssignPipe:=(LinuxError=0);
+ asm
+   mov $42,%eax
+   int $0x80
+   jb .Lerror
+   mov pipe_in,%ebx
+   mov %eax,(%ebx)
+   mov pipe_out,%ebx
+   mov $0,%eax
+   mov %edx,(%ebx)
+   mov %eax,%ebx
+   jmp .Lexit
+.Lerror:
+   mov %eax,%ebx
+   mov $-1,%eax
+.Lexit:
+   mov Errn,%edx
+   mov %ebx,(%edx)
+ end;
 end;
 
 
-Function PClose(Var F:text) :longint;
+Function PClose(Var F:text) :cint;
 var
   pl  : ^longint;
   res : longint;
@@ -509,274 +136,193 @@ begin
   do_syscall(syscall_nr_close,Textrec(F).Handle);
 { closed our side, Now wait for the other - this appears to be needed ?? }
   pl:=@(textrec(f).userdata[2]);
-  waitpid(pl^,@res,0);
+  fpwaitpid(pl^,@res,0);
   pclose:=res shr 8;
 end;
 
-Function PClose(Var F:file) : longint;
+Function PClose(Var F:file) : cint;
 var
-  pl : ^longint;
-  res : longint;
+  pl : ^cint;
+  res : cint;
 
 begin
   do_syscall(syscall_nr_close,filerec(F).Handle);
 { closed our side, Now wait for the other - this appears to be needed ?? }
   pl:=@(filerec(f).userdata[2]);
-  waitpid(pl^,@res,0);
+  fpwaitpid(pl^,@res,0);
   pclose:=res shr 8;
 end;
 
-
-Function mkFifo(pathname:string;mode:longint):boolean;
+function MUnMap (P : Pointer; Size : size_t) : cint;
 
 begin
-  pathname:=pathname+#0;
-  mkfifo:=do_syscall(syscall_nr_mknod,longint(@pathname[1]),mode or STAT_IFIFO,0)=0;
-  LinuxError:=Errno;
+  MUnMap:=do_syscall(syscall_nr_munmap,longint(P),Size);
 end;
+{$else}
 
-
-Function Kill(Pid:longint;Sig:longint):integer;
-{
-  Send signal 'sig' to a process, or a group of processes.
-  If Pid >  0 then the signal is sent to pid
-     pid=-1                         to all processes except process 1
-     pid < -1                         to process group -pid
-  Return value is zero, except for case three, where the return value
-  is the number of processes to which the signal was sent.
-}
+Function PClose(Var F:file) : cint;
+var
+  pl : ^cint;
+  res : cint;
 
 begin
- kill:=do_syscall(syscall_nr_kill,pid,sig);
- if kill<0 THEN
-  Kill:=0;
- LinuxError:=Errno;
+  fpclose(filerec(F).Handle);
+{ closed our side, Now wait for the other - this appears to be needed ?? }
+  pl:=@(filerec(f).userdata[2]);
+  fpwaitpid(pl^,@res,0);
+  pclose:=res shr 8;
 end;
 
-Procedure SigProcMask(How:longint;SSet,OldSSet:PSigSet);
-{
-  Change the list of currently blocked signals.
-  How determines which signals will be blocked :
-   SigBlock   : Add SSet to the current list of blocked signals
-   SigUnBlock : Remove the signals in SSet from the list of blocked signals.
-   SigSetMask : Set the list of blocked signals to SSet
-  if OldSSet is non-null, the old set will be saved there.
-}
+Function PClose(Var F:text) :cint;
+var
+  pl  : ^longint;
+  res : longint;
 
 begin
-  do_syscall(syscall_nr_sigprocmask,longint(how),longint(sset),longint(oldsset));
- LinuxError:=Errno;
-end;
-
-Function SigPending:SigSet;
-{
-  Allows examination of pending signals. The signal mask of pending
-  signals is set in SSet
-}
-Var
-  dummy : Sigset;
-begin
-  do_syscall(syscall_nr_sigpending,longint(@dummy));
-  LinuxError:=Errno;
-  sigpending:=dummy;
+  fpclose(Textrec(F).Handle);
+{ closed our side, Now wait for the other - this appears to be needed ?? }
+  pl:=@(textrec(f).userdata[2]);
+  fpwaitpid(pl^,@res,0);
+  pclose:=res shr 8;
 end;
 
-Procedure SigSuspend(Mask:Sigset);
+{$endif}
+// can't have oldfpccall here, linux doesn't need it.
+Function AssignPipe(var pipe_in,pipe_out:cint):cint; [public, alias : 'FPC_SYSC_ASSIGNPIPE'];
 {
- Set the signal mask with Mask, and suspend the program until a signal
- is received.
+  Sets up a pair of file variables, which act as a pipe. The first one can
+  be read from, the second one can be written to.
+  If the operation was unsuccesful, linuxerror is set.
 }
-
-begin
-  do_syscall(syscall_nr_sigsuspend,longint(@mask));
-  LinuxError:=Errno;
-end;
-
-Function NanoSleep(const req : timespec;var rem : timespec) : longint;
+var
+  ret  : longint;
+  errn : cint;
+  {$ifdef FPC_USE_LIBC}
+   fdis : array[0..1] of cint;
+  {$endif}
 begin
-  NanoSleep:=Do_SysCall(syscall_nr_nanosleep,longint(@req),longint(@rem));
-  LinuxError:=Errno;
+{$ifndef FPC_USE_LIBC}
+ ret:=intAssignPipe(pipe_in,pipe_out,errn);
+ if ret=-1 Then
+  fpseterrno(errn);
+{$ELSE}
+ fdis[0]:=pipe_in;
+ fdis[1]:=pipe_out;
+ ret:=pipe(fdis);
+ pipe_in:=fdis[0];
+ pipe_out:=fdis[1];
+{$ENDIF}
+ AssignPipe:=ret;
 end;
 
 
-
-Function IOCtl(Handle,Ndx: Longint;Data: Pointer):boolean;
 {
-  Interface to Unix ioctl call.
-  Performs various operations on the filedescriptor Handle.
-  Ndx describes the operation to perform.
-  Data points to data needed for the Ndx function. The structure of this
-  data is function-dependent.
-}
+function  intClone(func:TCloneFunc;sp:pointer;flags:longint;args:pointer):longint; {$ifndef ver1_0} oldfpccall; {$endif}
+ 
 
+var lerrno : Longint;
+    errset : Boolean;
+    Res    : Longint;	
 begin
-  IOCtl:=Do_Syscall(syscall_nr_ioctl,handle,ndx,longint(data))=0;
-  LinuxError:=Errno;
+  errset:=false;
+  Res:=0;
+asm
+        pushl   %esi
+        movl    12(%ebp), %esi  // get stack addr
+        subl    $4, %esi
+        movl    20(%ebp), %eax  // get __arg
+        movl    %eax, (%esi)
+        subl    $4, %esi
+        movl    8(%ebp), %eax   // get __fn
+        movl    %eax, (%esi)
+        pushl   16(%ebp)
+        pushl   %esi
+        mov     syscall_nr_rfork, %eax
+        int     $0x80                  // call actualsyscall
+        jb      .L2
+        test    %edx, %edx
+        jz      .L1
+        movl    %esi,%esp
+        popl    %eax
+        call    %eax
+        addl    $8, %esp
+        call    halt            // Does not return
+.L2:
+        mov     %eax,LErrNo
+        mov     $true,Errset
+	mov	$-1,%eax
+//        jmp     .L1
+.L1:
+        addl    $8, %esp
+        popl    %esi
+	mov	%eax,Res
 end;
-
-function MMap(const m:tmmapargs):longint;
-
-begin
-  {Last argument (offset) is actually 64-bit under BSD. Therefore extra 0}
- MMap:=fpmmap(m.address,m.size,m.prot,m.flags,m.fd,m.offset);
- LinuxError:=Errno;
+  If ErrSet Then
+   fpSetErrno(LErrno);
+  intClone:=Res; 
 end;
 
-function MUnMap (P : Pointer; Size : Longint) : Boolean;
 
-begin
-  MUnMap:=do_syscall(syscall_nr_munmap,longint(P),Size)=0;
-  LinuxError:=Errno;
-end;
 
-function signal(signum:longint;Handler:signalhandler):signalhandler;
+function  Clone(func:TCloneFunc;sp:pointer;flags:longint;args:pointer):longint; 
 
-var sa,osa : sigactionrec;
-
-begin
-     sa.sa_handler:=handler;
-     FillChar(sa.sa_mask,sizeof(sigset),#0);
-     sa.sa_flags := 0;
-     (*
-     if (sigintr and signum) =0 then
-       {restart behaviour needs libc}
-       sa.sa_flags :=sa.sa_flags or SA_RESTART;
-      *)
-     sigaction(signum,@sa,@osa);
-     if ErrNo<>0 then
-      signal:=NIL
-     else
-      signal:=osa.sa_handler;
-     LinuxError:=Errno;
-
-end;
-
-
-function  Clone(func:TCloneFunc;sp:pointer;flags:longint;args:pointer):longint;
-{$ifndef FPC_HAS_NO_SYSCALL_NR_RFORK}
-assembler;
-asm
-	pushl	%esi
-	movl	12(%ebp), %esi	// get stack addr
-	subl	$4, %esi
-	movl	20(%ebp), %eax	// get __arg
-	movl	%eax, (%esi)
-	subl	$4, %esi
-	movl	8(%ebp), %eax	// get __fn
-	movl	%eax, (%esi)
-	pushl	16(%ebp)
-	pushl	%esi
-	mov	syscall_nr_rfork, %eax
-	int     $0x80                  // call actualsyscall
-	jb 	.L2
-	test    %edx, %edx
-	jz	.L1
-	movl	%esi,%esp
-	popl	%eax
-	call	%eax
-	addl	$8, %esp
-        call	halt		// Does not return
-.L2:	
-	mov	%eax,ErrNo
-	mov	$-1,%eax
-	jmp     .L1
-//	jmp	PIC_PLT(HIDENAME(cerror))
-.L1:
-	addl	$8, %esp
-	popl	%esi
-end;
-{$else FPC_HAS_NO_SYSCALL_NR_RFORK}
 begin
-  RunError(218);
-  Clone:=-1;
+  Clone:=
+	intclone(tclonefunc(func),sp,flags,args);
 end;
-{$endif FPC_HAS_NO_SYSCALL_NR_RFORK}
-
-{$packrecords C}
-
-TYPE uint=CARDINAL;
+}
 
-CONST
-        I386_GET_LDT	=0;
-        I386_SET_LDT	=1;
-				{ I386_IOPL }
-        I386_GET_IOPERM	=3;
-        I386_SET_IOPERM	=4;
-				{ xxxxx }
-        I386_VM86	=6;
 
 {
-type i386_ldt_args = record
-	int	start : longint;
-	union	descriptor *descs;
-	int	num;
-	end;
-}
-type
- i386_ioperm_args = record
-	start	 : uint;
-	length   : uint;
-	enable	 : longint;
-	end;
+  $Log$
+  Revision 1.5  2004-01-04 01:11:28  marco
+   * a new qod port of the freebsd rtl. To be refined in the coming days.
 
+  Revision 1.18  2004/01/01 17:07:21  marco
+   * few small freebsd fixes backported from debugging linux
 
-    i386_vm86_args = record
-	sub_op   : longint;		{ sub-operation to perform }
-	sub_args : pchar;		{ args }
-	end;
+  Revision 1.17  2003/12/30 12:32:30  marco
+  *** empty log message ***
 
-   sysarch_args     = record
-     		     	op    : longint;
-   			parms : pchar;
-   		       end;
+  Revision 1.16  2003/11/19 17:11:40  marco
+   * termio unit
 
-{
-int i386_get_ldt __P((int, union descriptor *, int));
-int i386_set_ldt __P((int, union descriptor *, int));
-int i386_get_ioperm __P((unsigned int, unsigned int *, int *));
-int i386_set_ioperm __P((unsigned int, unsigned int, int));
-int i386_vm86 __P((int, void *));
-int i386_set_watch __P((int watchnum, unsigned int watchaddr, int size,
-                        int access, struct dbreg * d));
-int i386_clr_watch __P((int watchnum, struct dbreg * d));
-}
+  Revision 1.15  2003/11/19 10:12:02  marco
+   * more cleanups
 
-Function IOPerm(From,Num:CARDINAL;Value:Longint):boolean;
+  Revision 1.14  2003/11/17 10:05:51  marco
+   * threads for FreeBSD. Not working tho
 
-var sg : i386_ioperm_args;
-    sa : sysarch_args;
+  Revision 1.13  2003/11/14 16:21:59  marco
+   * linuxerror elimination
 
-begin
-  sg.start:=From;
-  sg.length:=Num;
-  sg.enable:=value;
-  sa.op:=i386_SET_IOPERM;
-  sa.parms:=@sg;
-  IOPerm:=do_syscall(syscall_nr_sysarch,longint(@sa))=0;
-  LinuxError:=ErrNo;
-end;
+  Revision 1.12  2003/11/09 12:00:16  marco
+   * pipe fix
 
-{
-  $Log$
-  Revision 1.4  2004-01-02 22:51:46  marco
-   * simple bugfix for tpipe
+  Revision 1.11  2003/09/20 12:38:29  marco
+   * FCL now compiles for FreeBSD with new 1.1. Now Linux.
+
+  Revision 1.10  2003/09/15 20:08:49  marco
+   * small fixes. FreeBSD now cycles
 
-  Revision 1.3  2003/05/31 16:57:22  marco
-   * works via system unit call now, because of powerpc
+  Revision 1.9  2003/09/15 07:09:58  marco
+   * small fixes, round 1
 
-  Revision 1.2  2003/01/21 15:39:45  marco
-   * NetBSD first rtl. Still not 100%, but close
+  Revision 1.8  2003/09/14 20:15:01  marco
+   * Unix reform stage two. Remove all calls from Unix that exist in Baseunix.
 
-  Revision 1.1.2.3  2002/09/26 08:13:08  marco
-   * Fix from Lazarus
+  Revision 1.7  2003/01/05 19:02:29  marco
+   * Should now work with baseunx. (gmake all works)
 
-  Revision 1.1.2.2  2002/09/20 07:04:15  pierre
-   * avoid compiler warning and comment level 2 warning
+  Revision 1.6  2002/10/18 12:19:59  marco
+   * Fixes to get the generic *BSD RTL compiling again + fixes for thread
+     support. Still problems left in fexpand. (inoutres?) Therefore fixed
+     sysposix not yet commited
 
-  Revision 1.1.2.1  2001/08/10 11:07:17  pierre
-   New NetBSD files taken and adapted from FreeBSD
+  Revision 1.5  2002/09/07 16:01:18  peter
+    * old logs removed and tabs fixed
 
-  Revision 1.1.2.3  2001/06/02 00:25:30  peter
-    * moved some unix files to target dependent dirs
+  Revision 1.4  2002/05/06 09:35:09  marco
+   * Some stuff from 1.0.x ported
 
 }