Explorar el Código

Merged revisions 2690,2705,2707,2731-2732,2734,2756,2801,2832,2884-2885,2888,2897,2909,2930,2944,2961,2969,3024-3026,3040 via svnmerge from
http://[email protected]/svn/fpc/trunk

........
r2690 | marco | 2006-02-26 14:58:27 +0100 (Sun, 26 Feb 2006) | 2 lines

* wince x86_64 added

........
r2705 | daniel | 2006-02-28 00:18:35 +0100 (Tue, 28 Feb 2006) | 3 lines

+ Add pread/pwrite system calls
* Optimize video using pwrite

........
r2707 | daniel | 2006-02-28 11:46:36 +0100 (Tue, 28 Feb 2006) | 2 lines

* Only update what is modified

........
r2731 | marco | 2006-03-04 13:40:45 +0100 (Sat, 04 Mar 2006) | 3 lines

* commit of the syscall based linux support for pwrite/writev, still under
{$ifdef linux}. This to fix x86_64 breakage.

........
r2732 | vincents | 2006-03-04 14:34:07 +0100 (Sat, 04 Mar 2006) | 1 line

fixed typo
........
r2734 | marco | 2006-03-04 15:21:42 +0100 (Sat, 04 Mar 2006) | 2 lines

* pwrite/writev for *BSD + FPC_USE_LIBC. Requires IOVEC et al to be defined in ostypes.inc

........
r2756 | marco | 2006-03-05 14:28:27 +0100 (Sun, 05 Mar 2006) | 2 lines

* a few type aliases added, capitalisation fixed

........
r2801 | Almindor | 2006-03-07 18:39:28 +0100 (Tue, 07 Mar 2006) | 2 lines

Adds winsock2 support

........
r2832 | peter | 2006-03-10 15:21:12 +0100 (Fri, 10 Mar 2006) | 2 lines

* Win32Check compatibility

........
r2884 | Almindor | 2006-03-12 14:03:33 +0100 (Sun, 12 Mar 2006) | 2 lines

* linux-i386 uses new_select now too

........
r2885 | Almindor | 2006-03-12 14:25:02 +0100 (Sun, 12 Mar 2006) | 2 lines

* Simplified and fixed (previous mistake..) select/newselect

........
r2888 | marco | 2006-03-12 17:24:46 +0100 (Sun, 12 Mar 2006) | 2 lines

* ugly workaround to avoid range check warnings. (4811, 4723)

........
r2897 | vincents | 2006-03-12 22:30:06 +0100 (Sun, 12 Mar 2006) | 1 line

* write caller address, even if no caller frame was found
........
r2909 | Almindor | 2006-03-13 15:26:28 +0100 (Mon, 13 Mar 2006) | 2 lines

* adds comments to to-be-obsolete syscalls for future review

........
r2930 | jonas | 2006-03-15 23:00:58 +0100 (Wed, 15 Mar 2006) | 2 lines

* shell() now also uses vfork() instead of fork() on Darwin

........
r2944 | marco | 2006-03-17 21:17:15 +0100 (Fri, 17 Mar 2006) | 2 lines

* fix for bug #4900. Probably result of tlargeinteger changing to int64, breaking alignment/padding

........
r2961 | Almindor | 2006-03-19 10:46:58 +0100 (Sun, 19 Mar 2006) | 2 lines

* experimental usage of fpgetcwd in osdir.inc

........
r2969 | Almindor | 2006-03-19 18:10:04 +0100 (Sun, 19 Mar 2006) | 2 lines

* adds fpgetcwd support to sysdir.inc and fixes compilation

........
r3024 | jonas | 2006-03-24 22:08:51 +0100 (Fri, 24 Mar 2006) | 3 lines

* fixed potential buffer overflow in fpc_Write_Text_Char/
fpc_Write_Text_WideChar (bug 4919)

........
r3025 | jonas | 2006-03-24 23:19:47 +0100 (Fri, 24 Mar 2006) | 2 lines

* fixed typo (invalid type case -> invalid type cast)

........
r3026 | jonas | 2006-03-24 23:47:15 +0100 (Fri, 24 Mar 2006) | 5 lines

* removed duplicate EVariant class from varutils and incorporated
its implementation details in the EVariant class of sysutils
+ added conversions of variant error codes to exception messages
(together these fix tw4704)

........
r3040 | Almindor | 2006-03-26 19:31:32 +0200 (Sun, 26 Mar 2006) | 2 lines

* removes useless "uses winsock" from sockets.pp in win32

........

git-svn-id: branches/fixes_2_0@3087 -

peter hace 19 años
padre
commit
a7f8f5338d

+ 4 - 0
.gitattributes

@@ -3651,6 +3651,7 @@ rtl/inc/threadh.inc svneol=native#text/plain
 rtl/inc/threadvr.inc svneol=native#text/plain
 rtl/inc/typefile.inc svneol=native#text/plain
 rtl/inc/ucomplex.pp svneol=native#text/plain
+rtl/inc/varerror.inc -text
 rtl/inc/variant.inc svneol=native#text/plain
 rtl/inc/varianth.inc svneol=native#text/plain
 rtl/inc/variants.pp svneol=native#text/plain
@@ -4229,6 +4230,7 @@ rtl/unix/dos.pp svneol=native#text/plain
 rtl/unix/dynlibs.inc svneol=native#text/plain
 rtl/unix/errors.pp svneol=native#text/plain
 rtl/unix/genfdset.inc svneol=native#text/plain
+rtl/unix/genfunch.inc svneol=native#text/plain
 rtl/unix/genfuncs.inc svneol=native#text/plain
 rtl/unix/gensigset.inc svneol=native#text/plain
 rtl/unix/initc.pp svneol=native#text/plain
@@ -4321,6 +4323,7 @@ rtl/win32/wininc/unidef.inc svneol=native#text/plain
 rtl/win32/wininc/unidef.sed -text
 rtl/win32/wininc/unifun.inc svneol=native#text/plain
 rtl/win32/winsock.pp svneol=native#text/plain
+rtl/win32/winsock2.pp svneol=native#text/plain
 rtl/win32/winsysut.pp svneol=native#text/plain
 rtl/win32/wprt0.as -text
 rtl/win32/wprt0_10.as -text
@@ -6442,6 +6445,7 @@ tests/webtbs/tw4640.pp svneol=native#text/plain
 tests/webtbs/tw4669.pp svneol=native#text/plain
 tests/webtbs/tw4675.pp svneol=native#text/plain
 tests/webtbs/tw4700.pp svneol=native#text/plain
+tests/webtbs/tw4707.pp -text
 tests/webtbs/tw4763.pp svneol=native#text/plain
 tests/webtbs/tw4768.pp -text
 tests/webtbs/tw4778.pp svneol=native#text/plain

+ 50 - 0
rtl/bsd/bunxsysc.inc

@@ -533,3 +533,53 @@ begin
  fpsymlink:=do_syscall(syscall_nr_symlink,TSysParam(oldname),TSysParam(newname));
 end;
 
+function Fppread(fd: cint; buf: pchar; nbytes : size_t; offset:Toff): ssize_t; [public, alias : 'FPC_SYSC_PREAD'];
+
+begin
+  
+ 	{$ifdef CPU64}
+	    Fppread:=do_syscall(syscall_nr_pread,Fd,TSysParam(buf),nbytes,TSysParam(OffSet});
+	{$else}
+           Fppread:=do_syscall(syscall_nr_pread,Fd,TSysParam(buf),nbytes,
+           {$ifdef 64bitfs}
+	     {$ifdef FPC_BIG_ENDIAN}    hi(offset),lo(offset){$endif}
+	     {$ifdef FPC_LITTLE_ENDIAN} lo(offset),hi(offset){$endif}
+           {$else}
+	     {$ifdef FPC_BIG_ENDIAN}    0,lo(offset){$endif}
+	     {$ifdef FPC_LITTLE_ENDIAN} lo(offset),0{$endif}
+	   {$endif}
+            );
+        {$endif}
+end;
+
+function Fppwrite(fd: cint;buf:pchar; nbytes : size_t; offset:Toff): ssize_t; [public, alias : 'FPC_SYSC_PWRITE'];
+
+begin
+ 	{$ifdef CPU64}
+           Fppwrite:=do_syscall(syscall_nr_pwrite,Fd,TSysParam(buf),nbytes,TSysParam(OffSet});
+	{$else}
+           Fppwrite:=do_syscall(syscall_nr_pwrite,Fd,TSysParam(buf),nbytes,
+	  // ,0  = possible alignment here.
+           {$ifdef 64bitfs}
+	     {$ifdef FPC_BIG_ENDIAN}    hi(offset),lo(offset){$endif}
+	     {$ifdef FPC_LITTLE_ENDIAN} lo(offset),hi(offset){$endif}
+           {$else}
+	     {$ifdef FPC_BIG_ENDIAN}    0,lo(offset){$endif}
+	     {$ifdef FPC_LITTLE_ENDIAN} lo(offset),0{$endif}
+	   {$endif}
+            );
+        {$endif}
+end;
+
+function Fpreadv(fd: cint; const iov : piovec; iovcnt : cint):ssize_t; [public, alias : 'FPC_SYSC_READV'];
+
+begin
+  Fpreadv:=do_syscall(syscall_nr_readv,Fd,TSysParam(iov),iovcnt);
+end;
+
+function Fpwritev(fd: cint; const iov : piovec; iovcnt : cint):ssize_t;  [public, alias : 'FPC_SYSC_WRITEV'];
+
+begin
+  Fpwritev:=do_syscall(syscall_nr_writev,Fd,TSysParam(iov),iovcnt);
+end;
+

+ 1 - 1
rtl/common/fpmkunit.pp

@@ -14,7 +14,7 @@ Type
   TFileTypes = set of TFileType;
 
   TOS = (Amiga,Atari,Darwin,FreeBSD,Go32v2,Linux,MacOS,MorphOS,NetBSD,
-         Netware,NetwLibc,OpenBSD,OS2,PalmOS,Solaris,Win32,Emx);
+         Netware,NetwLibc,OpenBSD,OS2,PalmOS,Solaris,Win32,wince,Emx);
   TOSes = Set of TOS;
   
   TCPU = (Arm,I386,PPC,SPARC,X86_64,m68k);

+ 9 - 8
rtl/freebsd/sysnr.inc

@@ -88,8 +88,6 @@ const
  syscall_nr_getpriority                 =100;
  syscall_nr_setsockopt                  =105;
  syscall_nr_gettimeofday                =116;
- syscall_nr_readv                       =120;
- syscall_nr_writev                      =121;
 
  syscall_nr_fchown                      =123;
  syscall_nr_fchmod                      =124;
@@ -112,8 +110,7 @@ const
  syscall_nr_uname                       =164;
 
  syscall_nr_rtprio                      =166;
- syscall_nr_pread                       =173;
- syscall_nr_pwrite                      =174;
+
  syscall_nr_ntp_adjtime                 =176;
  syscall_nr_setegid                     =182;
  syscall_nr_seteuid                     =183;
@@ -228,7 +225,11 @@ syscall_nr_getdirentries                =196;
 
 }
 
-{More or less checked BSD syscalls}
+{More or less checked/in use FreeBSD syscalls}
+ syscall_nr_readv                       =120;
+ syscall_nr_writev                      =121;
+ syscall_nr_pread                       =173;
+ syscall_nr_pwrite                      =174;
  syscall_nr_semsys                      =169;
  syscall_nr_msgsys                      =170;
  syscall_nr_shmsys                      =171;
@@ -260,7 +261,7 @@ syscall_nr_getdirentries                =196;
  syscall_nr_flock                       = 131;
  syscall_nr_fork                        =   2;
  syscall_nr_fstat                       = 189;
- syscall_nr_fstatfs                     = 158;
+ syscall_nr_fstatfs                     = 158;  // COMPAT4x
  syscall_nr_fsync                       =  95;
  syscall_nr_ftruncate                   = 201;
  syscall_nr_getdents                    = 272;
@@ -295,14 +296,14 @@ syscall_nr_getdirentries                =196;
  syscall_nr_setpriority                 =  96;
  syscall_nr_setsockopt                  = 105;
  syscall_nr_shutdown                    = 134;
- syscall_nr_sigaction                   = 342;
+ syscall_nr_sigaction                   = 342;  // COMPAT4x
  syscall_nr_sigpending                  = 343;
  syscall_nr_sigprocmask                 = 340;
  syscall_nr_sigsuspend                  = 341;
  syscall_nr_socket                      =  97;
  syscall_nr_socketpair                  = 135;
  syscall_nr_stat                        = 188;
- syscall_nr_statfs                      = 157;
+ syscall_nr_statfs                      = 157;  // COMPAT4x
  syscall_nr_symlink                     =  57;
  syscall_nr_umask                       =  60;
  syscall_nr_unlink                      =  10;

+ 3 - 2
rtl/inc/system.inc

@@ -773,10 +773,11 @@ Begin
      Begin
        caller_addr := get_caller_addr(bp);
        caller_frame := get_caller_frame(bp);
-       if (caller_addr=nil) or
-          (caller_frame=nil) then
+       if (caller_addr=nil) then
          break;
        Writeln(f,BackTraceStrFunc(caller_addr));
+       if (caller_frame=nil) then
+         break;
        Inc(i);
        If ((i>max_frame_dump) and is_dev) or (i>256) Then
          break;

+ 2 - 2
rtl/inc/text.inc

@@ -720,7 +720,7 @@ Begin
    end;
   If Len>1 Then
     fpc_WriteBlanks(t,Len-1);
-  If TextRec(t).BufPos+1>=TextRec(t).BufSize Then
+  If TextRec(t).BufPos>=TextRec(t).BufSize Then
     FileFunc(TextRec(t).InOutFunc)(TextRec(t));
   TextRec(t).Bufptr^[TextRec(t).BufPos]:=c;
   Inc(TextRec(t).BufPos);
@@ -743,7 +743,7 @@ Begin
    end;
   If Len>1 Then
     fpc_WriteBlanks(t,Len-1);
-  If TextRec(t).BufPos+1>=TextRec(t).BufSize Then
+  If TextRec(t).BufPos>=TextRec(t).BufSize Then
     FileFunc(TextRec(t).InOutFunc)(TextRec(t));
   ch:=c;
   TextRec(t).Bufptr^[TextRec(t).BufPos]:=ch;

+ 33 - 0
rtl/inc/varerror.inc

@@ -0,0 +1,33 @@
+{
+    This file is part of the Free Pascal run time library.
+    Copyright (c) 2006 by the Free Pascal development team
+
+    This include file contains the implementation for variants
+    support in FPC as far as it is part of the system unit
+
+    See the file COPYING.FPC, included in this distribution,
+    for details about the copyright.
+
+    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.
+
+
+ **********************************************************************}
+
+// Names match the ones in Borland varutils unit.
+
+const
+  VAR_OK            = HRESULT($00000000);
+  VAR_PARAMNOTFOUND = HRESULT($80020004);
+  VAR_TYPEMISMATCH  = HRESULT($80020005);
+  VAR_BADVARTYPE    = HRESULT($80020008);
+  VAR_EXCEPTION     = HRESULT($80020009);
+  VAR_OVERFLOW      = HRESULT($8002000A);
+  VAR_BADINDEX      = HRESULT($8002000B);
+  VAR_ARRAYISLOCKED = HRESULT($8002000D);
+  VAR_NOTIMPL       = HRESULT($80004001);
+  VAR_OUTOFMEMORY   = HRESULT($8007000E);
+  VAR_INVALIDARG    = HRESULT($80070057);
+  VAR_UNEXPECTED    = HRESULT($8000FFFF);
+

+ 52 - 32
rtl/linux/bunxsysc.inc

@@ -381,49 +381,20 @@ begin
   fptimes:=Do_syscall(syscall_nr_times,TSysParam(@buffer));
 end;
 
-function pfpgetcwd(path : pchar; siz:tsize):pchar;  [public, alias : 'FPC_SYSC_GETCWD'];
-
-begin
-  pfpgetcwd:=pchar(Do_Syscall(Syscall_nr_getcwd,TSysParam(Path),TSysParam(siz)));
-end;
-
 Function fpSelect(N:cint;readfds,writefds,exceptfds:pfdSet;TimeOut:PTimeVal):cint;
 {
   Select checks whether the file descriptor sets in readfs/writefs/exceptfs
   have changed.
 }
 
-{$ifdef cpui386}
-Var
-  SelectArray : Array[1..5] of TSysParam;
-{$endif}
-
 begin
-{$ifdef cpui386}
-  {$define bunxfunc_fpselect_implemented}
-  SelectArray[1]:=n;
-  SelectArray[2]:=TSysParam(Readfds);
-  Selectarray[3]:=TSysParam(Writefds);
-  selectarray[4]:=TSysParam(exceptfds);
-  Selectarray[5]:=TSysParam(TimeOut);
-  fpSelect:=do_syscall(syscall_nr_select,TSysParam(@selectarray));
-{$endif cpui386}
 {$ifdef cpux86_64}
   {$define bunxfunc_fpselect_implemented}
   fpSelect:=do_syscall(syscall_nr_select,n,tsysparam(readfds),tsysparam(writefds),tsysparam(exceptfds),tsysparam(timeout));
-{$endif cpux86_64}
-{$ifdef cpuarm}
-  {$define bunxfunc_fpselect_implemented}
-  fpSelect:=do_syscall(syscall_nr__newselect,n,tsysparam(readfds),tsysparam(writefds),tsysparam(exceptfds),tsysparam(timeout));
-{$endif cpuarm}
-{$ifdef cpupowerpc}
-  {$define bunxfunc_fpselect_implemented}
-  fpSelect:=do_syscall(syscall_nr__newselect,n,tsysparam(readfds),tsysparam(writefds),tsysparam(exceptfds),tsysparam(timeout));
-{$endif cpupowerpc}
-{$ifdef cpusparc}
+{$else}
   {$define bunxfunc_fpselect_implemented}
   fpSelect:=do_syscall(syscall_nr__newselect,n,tsysparam(readfds),tsysparam(writefds),tsysparam(exceptfds),tsysparam(timeout));
-{$endif cpusparc}
+{$endif}
 {$ifndef bunxfunc_fpselect_implemented}
   {$error Implement fpselect}
 {$endif bunxfunc_fpselect_implemented}
@@ -527,7 +498,56 @@ Function fpSymlink(oldname,newname:pchar):cint;
 }
 
 begin
- fpsymlink:=do_syscall(syscall_nr_symlink,TSysParam(oldname),TSysParam(newname));
+  fpsymlink:=do_syscall(syscall_nr_symlink,TSysParam(oldname),TSysParam(newname));
 end;
 
+function Fppread(fd: cint; buf: pchar; nbytes : size_t; offset:Toff): ssize_t; [public, alias : 'FPC_SYSC_PREAD'];
+
+begin
+  
+ 	{$ifdef CPU64}
+	    Fppread:=do_syscall(syscall_nr_pread64,Fd,TSysParam(buf),nbytes,TSysParam(OffSet));
+	{$else}
+           Fppread:=do_syscall(syscall_nr_pread,Fd,TSysParam(buf),nbytes,
+           {$ifdef 64bitfs}
+	     {$ifdef FPC_BIG_ENDIAN}    hi(offset),lo(offset){$endif}
+	     {$ifdef FPC_LITTLE_ENDIAN} lo(offset),hi(offset){$endif}
+           {$else}
+	     {$ifdef FPC_BIG_ENDIAN}    0,lo(offset){$endif}
+	     {$ifdef FPC_LITTLE_ENDIAN} lo(offset),0{$endif}
+	   {$endif}
+            );
+        {$endif}
+end;
+
+function Fppwrite(fd: cint;buf:pchar; nbytes : size_t; offset:Toff): ssize_t; [public, alias : 'FPC_SYSC_PWRITE'];
+
+begin
+ 	{$ifdef CPU64}
+           Fppwrite:=do_syscall(syscall_nr_pwrite64,Fd,TSysParam(buf),nbytes,TSysParam(OffSet));
+	{$else}
+           Fppwrite:=do_syscall(syscall_nr_pwrite,Fd,TSysParam(buf),nbytes,
+	  // ,0  = possible alignment here.
+           {$ifdef 64bitfs}
+	     {$ifdef FPC_BIG_ENDIAN}    hi(offset),lo(offset){$endif}
+	     {$ifdef FPC_LITTLE_ENDIAN} lo(offset),hi(offset){$endif}
+           {$else}
+	     {$ifdef FPC_BIG_ENDIAN}    0,lo(offset){$endif}
+	     {$ifdef FPC_LITTLE_ENDIAN} lo(offset),0{$endif}
+	   {$endif}
+            );
+        {$endif}
+end;
+
+function Fpreadv(fd: cint; const iov : piovec; iovcnt : cint):ssize_t; [public, alias : 'FPC_SYSC_READV'];
+
+begin
+  Fpreadv:=do_syscall(syscall_nr_readv,Fd,TSysParam(iov),iovcnt);
+end;
+
+function Fpwritev(fd: cint; const iov : piovec; iovcnt : cint):ssize_t;  [public, alias : 'FPC_SYSC_WRITEV'];
+
+begin
+  Fpwritev:=do_syscall(syscall_nr_writev,Fd,TSysParam(iov),iovcnt);
+end;
 

+ 3 - 3
rtl/linux/linux.pp

@@ -64,7 +64,7 @@ Const
 type
   TCloneFunc=function(args:pointer):longint;cdecl;
 
-  EPoll_Data = record
+  EPoll_Data = Record
     case integer of
       0: (ptr: pointer);
       1: (fd: cint);
@@ -74,7 +74,7 @@ type
   TEPoll_Data =  Epoll_Data;
   PEPoll_Data = ^Epoll_Data;
 
-  EPoll_Event = record
+  EPoll_Event = Record
     Events: cuint32;
     Data  : TEpoll_Data;
   end;
@@ -189,7 +189,7 @@ end;
 
 function epoll_ctl(epfd, op, fd: cint; event: pepoll_event): cint;
 begin
-  epoll_ctl := do_syscall(syscall_nr_epoll_ctl, tsysparam(epfd), 
+  epoll_ctl := do_syscall(syscall_nr_epoll_ctl, tsysparam(epfd),
     tsysparam(op), tsysparam(fd), tsysparam(event));
 end;
 

+ 17 - 2
rtl/linux/ossysc.inc

@@ -61,7 +61,19 @@ function Fpwrite(fd: cint;buf:pchar; nbytes : size_t): ssize_t; [public, alias :
 begin
  Fpwrite:=do_syscall(syscall_nr_write,Fd,TSysParam(buf),nbytes);
 end;
+{
+function Fppread(fd: cint; buf: pchar; nbytes : size_t; offset:Toff): ssize_t; [public, alias : 'FPC_SYSC_PREAD'];
+
+begin
+  Fpread:=do_syscall(syscall_nr_pread,Fd,TSysParam(buf),nbytes,offset);
+end;
+
+function Fppwrite(fd: cint;buf:pchar; nbytes : size_t; offset:Toff): ssize_t; [public, alias : 'FPC_SYSC_PWRITE'];
 
+begin
+ Fpwrite:=do_syscall(syscall_nr_pwrite,Fd,TSysParam(buf),nbytes,offset);
+end;
+}
 function Fpunlink(path: pchar): cint; [public, alias : 'FPC_SYSC_UNLINK'];
 
 begin
@@ -463,8 +475,11 @@ begin
   FpNanoSleep:=Do_SysCall(syscall_nr_nanosleep,TSysParam(req),TSysParam(rem));
 end;
 
-// The following belongs here, but this should be researched more.
-// function Fpgetcwd(pt:pchar; _size:size_t):pchar;[public, alias :'FPC_SYSC_GETCWD'];
+function fpgetcwd(path : pchar; siz:tsize):pchar;  [public, alias : 'FPC_SYSC_GETCWD'];
+
+begin
+  fpgetcwd:=pchar(Do_Syscall(Syscall_nr_getcwd,TSysParam(Path),TSysParam(siz)));
+end;
 
 function fpgettimeofday(tp: ptimeval;tzp:ptimezone):cint; [public, alias: 'FPC_SYSC_GETTIMEOFDAY'];
 

+ 0 - 6
rtl/objpas/cvarutil.inc

@@ -30,12 +30,6 @@ begin
   Raise Exception.Create(SNoInterfaces);
 end;
 
-Constructor EVariantError.CreateCode (Code : longint);
-
-begin
-  ErrCode:=Code;
-end;
-
 Procedure VariantTypeMismatch;
 
 begin

+ 1 - 1
rtl/objpas/sysconst.pp

@@ -67,7 +67,7 @@ resourcestring
   SInvalidInteger        = '"%s" is an invalid integer';
   SInvalidOp             = 'Invalid floating point operation';
   SInvalidPointer        = 'Invalid pointer operation';
-  SInvalidVarCast        = 'Invalid variant type case';
+  SInvalidVarCast        = 'Invalid variant type cast';
   SInvalidVarNullOp      = 'Invalid NULL variant operation';
   SInvalidVarOp          = 'Invalid variant operation';
   SInvalidVarOpWithHResultWithPrefix = 'Invalid variant operation (%s%.8x)'+LineEnding+'%s';

+ 4 - 1
rtl/objpas/sysutils/sysutilh.inc

@@ -118,7 +118,10 @@ type
    EInvalidPointer  = Class(EHeapMemoryError);
    EOutOfMemory     = Class(EHeapMemoryError);
    EInvalidCast = Class(Exception);
-   EVariantError = Class(Exception);
+   EVariantError = Class(Exception)
+     ErrCode : longint;
+     Constructor CreateCode(Code : Longint);
+   end;
 
    EAccessViolation = Class(EExternal);
    EBusError = Class(EAccessViolation);

+ 36 - 0
rtl/objpas/sysutils/sysutils.inc

@@ -15,6 +15,9 @@
   { Read filename handling functions implementation }
   {$i fina.inc}
 
+  { variant error codes }
+  {$i varerror.inc}
+
     Function FileSearch (Const Name, DirList : String) : String;
     Var
       I : longint;
@@ -189,6 +192,39 @@
     end;
 
 
+    Constructor EVariantError.CreateCode (Code : longint);
+    begin
+       case Code of
+         VAR_OK:
+           Create(SNoError);
+         VAR_PARAMNOTFOUND:
+           Create(SVarParamNotFound);
+         VAR_TYPEMISMATCH:
+           Create(SInvalidVarCast);
+         VAR_BADVARTYPE:
+           Create(SVarBadType);
+         VAR_OVERFLOW:
+           Create(SVarOverflow);
+         VAR_BADINDEX:
+           Create(SVarArrayBounds);
+         VAR_ARRAYISLOCKED:
+           Create(SVarArrayLocked);
+         VAR_NOTIMPL:
+           Create(SVarNotImplemented);
+         VAR_OUTOFMEMORY:
+           Create(SVarOutOfMemory);
+         VAR_INVALIDARG:
+           Create(SVarInvalid);
+         VAR_UNEXPECTED,
+         VAR_EXCEPTION:
+           Create(SVarUnexpected);
+         else
+           CreateFmt(SUnknownErrorCode,[Code]);
+       end;
+       ErrCode:=Code;
+    end;
+
+
 {$ifopt S+}
 {$define STACKCHECK_WAS_ON}
 {$S-}

+ 1 - 20
rtl/objpas/varutilh.inc

@@ -16,12 +16,6 @@
  **********************************************************************}
 
 
-Type
-  EVarianterror = Class(Exception)
-    ErrCode : longint;
-    Constructor CreateCode(Code : Longint);
-  end;
-
 { Variant functions }
 function VariantChangeTypeEx(var VargDest: TVarData; const VargSrc: TVarData; LCID: Integer; Flags: Word; VarType: Word): HRESULT; stdcall;
 function VariantClear(var Varg: TVarData): HRESULT; stdcall;
@@ -75,22 +69,9 @@ Procedure DumpVariant(Const VArgSrc : TVarData);
 Procedure DumpVariant(Var F : Text; Const VArgSrc : TVarData);
 
 
+{$i varerror.inc}
 // Names match the ones in Borland varutils unit.
-
 const
-  VAR_OK            = HRESULT($00000000);
-  VAR_PARAMNOTFOUND = HRESULT($80020004);
-  VAR_TYPEMISMATCH  = HRESULT($80020005);
-  VAR_BADVARTYPE    = HRESULT($80020008);
-  VAR_EXCEPTION     = HRESULT($80020009);
-  VAR_OVERFLOW      = HRESULT($8002000A);
-  VAR_BADINDEX      = HRESULT($8002000B);
-  VAR_ARRAYISLOCKED = HRESULT($8002000D);
-  VAR_NOTIMPL       = HRESULT($80004001);
-  VAR_OUTOFMEMORY   = HRESULT($8007000E);
-  VAR_INVALIDARG    = HRESULT($80070057);
-  VAR_UNEXPECTED    = HRESULT($8000FFFF);
-
   ARR_NONE          = $0000;
   ARR_FIXEDSIZE     = $0010;
   ARR_OLESTR        = $0100;

+ 2 - 1
rtl/unix/baseunix.pp

@@ -45,6 +45,7 @@ Uses UnixType;
 
 {$i bunxovlh.inc}
 
+{$i genfunch.inc}
 
 implementation
 
@@ -59,7 +60,7 @@ Uses Sysctl;
 {$ifndef FPC_USE_LIBC}
   {$i syscallh.inc}       // do_syscall declarations themselves
   {$i sysnr.inc}          // syscall numbers.
-  {$i bsyscall.inc}  			// cpu specific syscalls
+  {$i bsyscall.inc}       // cpu specific syscalls
   {$i bunxsysc.inc}       // syscalls in system unit.
   {$i settimeo.inc}
 {$endif}

+ 6 - 1
rtl/unix/bunxh.inc

@@ -79,7 +79,12 @@ Type TGrpArr = Array [0..0] of TGid;            { C style array workarounds}
     Function  FpClose      (fd : cInt): cInt;  external name 'FPC_SYSC_CLOSE';
 
     Function  FpRead       (fd : cInt; buf: pChar; nbytes : TSize): TSsize; external name 'FPC_SYSC_READ';
-    Function  FpWrite      (fd : cInt; buf:pChar; nbytes : TSize): TSsize; external name 'FPC_SYSC_WRITE';
+    Function  FpPRead      (fd : cInt; buf: pChar; nbytes : TSize; offset:Toff): TSsize;
+    function  FpReadV	   (fd: cint; const iov : piovec; iovcnt : cint):TSSize;
+    Function  FpWrite      (fd : cInt; buf:pChar; nbytes : TSize): TSsize;  external name 'FPC_SYSC_WRITE';
+    Function  FpPWrite     (fd : cInt; buf:pChar; nbytes : TSize; offset:Toff): TSSize;
+    function  FpWriteV	   (fd: cint; const iov : piovec; iovcnt : cint):TSSize; 
+
     Function  FpLseek      (fd : cInt; offset : TOff; whence : cInt): TOff; external name 'FPC_SYSC_LSEEK';
     Function  FpTime       (var tloc : TTime): TTime; external name 'FPC_SYSC_TIME';
     Function  FpFtruncate  (fd : cInt; flength : TOff): cInt;  external name 'FPC_SYSC_FTRUNCATE';

+ 14 - 0
rtl/unix/bunxovl.inc

@@ -175,6 +175,20 @@ begin
  FpWrite:=FpWrite(fd,pchar(@buf),nbytes);
 end;
 
+{$ifdef linux}
+function  FppRead           (fd : cInt;var buf; nbytes : TSize; offset:Toff): TSsize; {$ifdef VER2_0}inline;{$endif}
+
+begin
+  FppRead:=FppRead(fd,pchar(@buf),nbytes,offset);
+end;
+
+function  FppWrite          (fd : cInt;const buf; nbytes : TSize; offset:Toff): TSsize; {$ifdef VER2_0}inline;{$endif}
+
+begin
+  FppWrite:=FppWrite(fd,pchar(@buf),nbytes,offset);
+end;
+{$endif}
+
 Function  FpOpen    (path : pChar; flags : cInt):cInt; {$ifdef VER2_0}inline;{$endif}
 
 begin

+ 4 - 0
rtl/unix/bunxovlh.inc

@@ -48,6 +48,10 @@ Function  FPFStat   (var F:File;Var Info:stat):Boolean; inline;
 Function  FpSignal  (signum:longint;Handler:signalhandler):signalhandler;
 Function  FpRead    (fd : cInt; var buf; nbytes : TSize): TSsize; inline;
 Function  FpWrite   (fd : cInt; const buf; nbytes : TSize): TSsize; inline;
+{$ifdef linux}
+function  FppRead   (fd : cInt; var buf; nbytes : TSize; offset:Toff): TSsize; inline;
+function  FppWrite  (fd : cInt; const buf; nbytes : TSize; offset:Toff): TSsize; inline;
+{$endif}
 Function  FpDup     (var oldfile,newfile:text):cint;
 Function  FpDup     (var oldfile,newfile:file):cint;
 Function  FpDup2    (var oldfile,newfile:text):cint;

+ 21 - 0
rtl/unix/genfunch.inc

@@ -0,0 +1,21 @@
+{
+    This file is part of the Free Pascal run time library.
+    Copyright (c) 2002 by Marco van de Voort.
+
+    A few general purpose routines. General purpose enough for *BSD
+     and Linux at least.
+
+    See the file COPYING.FPC, included in this distribution,
+    for details about the copyright.
+
+    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.
+
+ **********************************************************************}
+
+function CreateShellArgV(const prog:string):ppchar;
+
+function CreateShellArgV(const prog:Ansistring):ppchar;
+
+procedure FreeShellArgV(p:ppchar);

+ 26 - 28
rtl/unix/keyboard.pp

@@ -201,23 +201,22 @@ var oldesc0,oldesc1,oldesc2,oldesc4,oldesc8:word;
 
 procedure prepare_patching;
 
-var e:^chgentry;
-    entry : kbentry;
+var entry : kbentry;
     i:longint;
 
 begin
   for i:=low(kbdchange) to high(kbdchange) do
-   begin
-     e:=@kbdchange[i];
-     entry.kb_table:=e^.tab;
-     entry.kb_index:=e^.idx;
-     fpIoctl(stdinputhandle,KDGKBENT,@entry);
-     e^.oldval:=entry.kb_value;
-     entry.kb_table:=e^.oldtab;
-     entry.kb_index:=e^.oldidx;
-     fpioctl(stdinputhandle,KDGKBENT,@entry);
-     e^.newval:=entry.kb_value;
-   end;
+   with kbdchange[i] do
+     begin
+       entry.kb_table:=tab;
+       entry.kb_index:=idx;
+       fpIoctl(stdinputhandle,KDGKBENT,@entry);
+       oldval:=entry.kb_value;
+       entry.kb_table:=oldtab;
+       entry.kb_index:=oldidx;
+       fpioctl(stdinputhandle,KDGKBENT,@entry);
+       newval:=entry.kb_value;
+     end;
   {Save old escape code.}
   entry.kb_index:=1;
   entry.kb_table:=0;
@@ -239,7 +238,6 @@ end;
 
 procedure PatchKeyboard;
 var
-  e : ^chgentry;
   entry : kbentry;
   sentry : kbsentry;
   i:longint;
@@ -248,13 +246,13 @@ begin
   meta:=K_ESCPREFIX;
   fpIoctl(stdinputhandle,KDSKBMETA,@meta);
   for i:=low(kbdchange) to high(kbdchange) do
-   begin
-     e:=@kbdchange[i];
-     entry.kb_table:=e^.tab;
-     entry.kb_index:=e^.idx;
-     entry.kb_value:=e^.newval;
-     fpioctl(stdinputhandle,KDSKBENT,@entry);
-   end;
+    with kbdchange[i] do
+      begin
+        entry.kb_table:=tab;
+        entry.kb_index:=idx;
+        entry.kb_value:=newval;
+        fpioctl(stdinputhandle,KDSKBENT,@entry);
+      end;
 
   {Map kernel escape key code to symbol F32.}
   entry.kb_index:=1;
@@ -286,13 +284,13 @@ begin
   if oldmeta in [K_ESCPREFIX,K_METABIT] then
     fpioctl(stdinputhandle,KDSKBMETA,@oldmeta);
   for i:=low(kbdchange) to high(kbdchange) do
-   begin
-     e:=@kbdchange[i];
-     entry.kb_table:=e^.tab;
-     entry.kb_index:=e^.idx;
-     entry.kb_value:=e^.oldval;
-     fpioctl(stdinputhandle,KDSKBENT,@entry);
-   end;
+    with kbdchange[i] do
+      begin
+        entry.kb_table:=tab;
+        entry.kb_index:=idx;
+        entry.kb_value:=oldval;
+        fpioctl(stdinputhandle,KDSKBENT,@entry);
+      end;
 
   entry.kb_index:=1;
   entry.kb_table:=0;

+ 5 - 0
rtl/unix/oscdeclh.inc

@@ -106,3 +106,8 @@ Type TGrpArr = Array [0..0] of TGid;            { C style array workarounds}
     Function  fpLstat       (path:pchar;Info:pstat):cint;     cdecl; external clib name 'lstat';
     function  FpStat      (path: pchar; var buf : stat): cint; cdecl; external clib name 'stat';
 {$endif linux}
+
+    Function  FpPRead      (fd : cInt; buf: pChar; nbytes : TSize; offset:Toff): TSsize;   cdecl; external clib name 'pread';
+    function  FpReadV	   (fd: cint; const iov : piovec; iovcnt : cint):TSSize;  cdecl; external clib name 'readv';
+    Function  FpPWrite     (fd : cInt; buf:pChar; nbytes : TSize; offset:Toff): TSSize;  cdecl; external clib name 'pwrite';
+    function  FpWriteV	   (fd: cint; const iov : piovec; iovcnt : cint):TSSize;  cdecl; external clib name 'writev';

+ 1 - 1
rtl/unix/sysdir.inc

@@ -73,7 +73,7 @@ Begin
    InOutRes:=3;
 End;
 
-{ // $define usegetcwd}
+{$define usegetcwd}
 
 procedure getdir(drivenr : byte;var dir : shortstring);
 var

+ 19 - 8
rtl/unix/unix.pp

@@ -384,6 +384,9 @@ End;
 // execvP has the searchpath as array of ansistring ( const char *search_path)
 
 {$define FPC_USE_FPEXEC}
+{$if defined(FPC_USE_FPEXEC) and not defined(USE_VFORK)}
+{$define SHELL_USE_FPEXEC}
+{$endif}
 Function Shell(const Command:String):cint;
 {
   Executes the shell, and passes it the string Command. (Through /bin/sh -c)
@@ -399,19 +402,23 @@ Function Shell(const Command:String):cint;
 - The Old CreateShellArg gives back pointers to a local var
 }
 var
-{$ifndef FPC_USE_FPEXEC}
+{$ifndef SHELL_USE_FPEXEC}
   p      : ppchar;
 {$endif}
   pid    : cint;
 begin
- {$ifndef FPC_USE_FPEXEC}
+ {$ifndef SHELL_USE_FPEXEC}
   p:=CreateShellArgv(command);
 {$endif}
+{$ifdef USE_VFORK}
+  pid:=fpvfork;
+{$else USE_VFORK}
   pid:=fpfork;
+{$endif USE_VFORK}
   if pid=0 then // We are in the Child
    begin
      {This is the child.}
-     {$ifndef FPC_USE_FPEXEC}
+     {$ifndef SHELL_USE_FPEXEC}
        fpExecve(p^,p,envp);
      {$else}
       fpexecl('/bin/sh',['-c',Command]);
@@ -422,7 +429,7 @@ begin
    Shell:=WaitProcess(pid)
   else // no success
    Shell:=-1; // indicate an error
-  {$ifndef FPC_USE_FPEXEC}
+  {$ifndef SHELL_USE_FPEXEC}
   FreeShellArgV(p);
   {$endif}
 end;
@@ -432,18 +439,22 @@ Function Shell(const Command:AnsiString):cint;
   AnsiString version of Shell
 }
 var
-{$ifndef FPC_USE_FPEXEC}
+{$ifndef SHELL_USE_FPEXEC}
   p     : ppchar;
 {$endif}
   pid   : cint;
 begin { Changes as above }
-{$ifndef FPC_USE_FPEXEC}
+{$ifndef SHELL_USE_FPEXEC}
   p:=CreateShellArgv(command);
 {$endif}
+{$ifdef USE_VFORK}
+  pid:=fpvfork;
+{$else USE_VFORK}
   pid:=fpfork;
+{$endif USE_VFORK}
   if pid=0 then // We are in the Child
    begin
-    {$ifdef FPC_USE_FPEXEC}
+    {$ifdef SHELL_USE_FPEXEC}
       fpexecl('/bin/sh',['-c',Command]);
     {$else}
      fpExecve(p^,p,envp);
@@ -454,7 +465,7 @@ begin { Changes as above }
    Shell:=WaitProcess(pid)
   else // no success
    Shell:=-1;
- {$ifndef FPC_USE_FPEXEC}
+ {$ifndef SHELL_USE_FPEXEC}
   FreeShellArgV(p);
  {$ENDIF}
 end;

+ 74 - 33
rtl/unix/video.pp

@@ -16,6 +16,7 @@
 unit Video;
 
 {$I-}
+{$GOTO on}
 
 {*****************************************************************************}
                                    interface
@@ -96,7 +97,7 @@ const term_codes_ansi:Ttermcodes= {Linux escape sequences are equal to ansi sequ
       term_codes_vt100:Ttermcodes=
         (#$0E,                                              {enter_alt_charset_mode}
          #$0F,                                              {exit_alt_charset_mode}
-         #$1B#$5B#$48#$1B#$5B#$4A#$24#$3C#$35#$30#$3E,      {clear_screen}
+         #$1B#$5B#$48#$1B#$5B#$4A{#$24#$3C#$35#$30#$3E},    {clear_screen}
          #$1B#$5B#$48,                                      {cursor_home}
          nil,                                               {cursor_normal}
          nil,                                               {cursor_visible}
@@ -107,8 +108,8 @@ const term_codes_ansi:Ttermcodes= {Linux escape sequences are equal to ansi sequ
          #$1B#$28#$42#$1B#$29#$30);                         {ena_acs}
 
       term_codes_vt220:Ttermcodes=
-        (#$1B#$28#$30#$24#$3C#$32#$3E,                      {enter_alt_charset_mode}
-         #$1B#$28#$42#$24#$3C#$34#$3E,                      {exit_alt_charset_mode}
+        (#$1B#$28#$30{#$24#$3C#$32#$3E},                    {enter_alt_charset_mode}
+         #$1B#$28#$42{#$24#$3C#$34#$3E},                    {exit_alt_charset_mode}
          #$1B#$5B#$48#$1B#$5B#$4A,                          {clear_screen}
          #$1B#$5B#$48,                                      {cursor_home}
          nil,                                               {cursor_normal}
@@ -272,7 +273,7 @@ end;
 
 function SendEscapeSeqNdx(Ndx:Ttermcode) : boolean;
 var
-  P,pdelay: PChar;
+  P{,pdelay}:PChar;
 begin
   SendEscapeSeqNdx:=false;
   if not assigned(cur_term_Strings) then
@@ -280,13 +281,13 @@ begin
   P:=cur_term_Strings^[Ndx];
   if assigned(p) then
    begin { Do not transmit the delays }
-     pdelay:=strpos(p,'$<');
+{     pdelay:=strpos(p,'$<');
      if assigned(pdelay) then
-       pdelay^:=#0;
+       pdelay^:=#0;}
      fpWrite(stdoutputhandle, P^, StrLen(P));
      SendEscapeSeqNdx:=true;
-     if assigned(pdelay) then
-       pdelay^:='$';
+{     if assigned(pdelay) then
+       pdelay^:='$';}
    end;
 end;
 
@@ -528,7 +529,7 @@ end;
 
 function GetTermString(ndx:Ttermcode):String;
 var
-   P,pdelay: PChar;
+   P{,pdelay}: PChar;
 begin
   GetTermString:='';
   if not assigned(cur_term_Strings) then
@@ -536,12 +537,12 @@ begin
   P:=cur_term_Strings^[Ndx];
   if assigned(p) then
    begin { Do not transmit the delays }
-     pdelay:=strpos(p,'$<');
+{     pdelay:=strpos(p,'$<');
      if assigned(pdelay) then
-       pdelay^:=#0;
+       pdelay^:=#0;}
      GetTermString:=StrPas(p);
-     if assigned(pdelay) then
-       pdelay^:='$';
+{     if assigned(pdelay) then
+       pdelay^:='$';}
    end;
 end;
 
@@ -662,6 +663,57 @@ begin
 //  SendEscapeSeq(#27'[?7h');
 end;
 
+{$ifdef linux}
+procedure update_vcsa(force:boolean);
+
+const max_updates=64;
+
+label update,update_all,equal_loop,unequal_loop;
+
+var position,update_count,i:word;
+    update_positions:array[0..max_updates-1] of word;
+    update_lengths:array[0..max_updates-1] of word;
+
+begin
+  if force then
+    goto update_all;
+
+  update_count:=0;
+  i:=0;
+
+equal_loop:
+  repeat
+    if videobuf^[i]<>oldvideobuf^[i] then
+      goto unequal_loop;
+    inc(i);
+  until i>videobufsize div 2;
+  goto update;
+
+unequal_loop:
+  if update_count>=max_updates then
+    goto update_all;
+  update_positions[update_count]:=i;
+  update_lengths[update_count]:=0;
+  inc(update_count);
+  repeat
+    if videobuf^[i]=oldvideobuf^[i] then
+      goto equal_loop;
+    inc(i);
+    inc(update_lengths[update_count-1]);
+  until i>videobufsize div 2;
+
+update:
+  for i:=1 to update_count do
+    begin
+      position:=update_positions[i-1];
+      fppwrite(ttyfd,videobuf^[position],update_lengths[i-1]*2,4+position*2);
+    end;
+  exit;
+update_all:
+  fppwrite(ttyfd,videobuf^,videobufsize,4);
+end;
+{$endif}
+
 var
   preInitVideoTio, postInitVideoTio: termio.termios;
   inputRaw, outputRaw: boolean;
@@ -851,10 +903,10 @@ begin
          ACSOut:=StrPas(cur_term_strings^[exit_alt_charset_mode]);
          if (ACSIn<>'') and (ACSOut<>'') then
            SendEscapeSeqNdx(ena_acs);
-         if pos('$<',ACSIn)>0 then
+{         if pos('$<',ACSIn)>0 then
            ACSIn:=Copy(ACSIn,1,Pos('$<',ACSIn)-1);
          if pos('$<',ACSOut)>0 then
-           ACSOut:=Copy(ACSOut,1,Pos('$<',ACSOut)-1);
+           ACSOut:=Copy(ACSOut,1,Pos('$<',ACSOut)-1);}
          If fpGetEnv('TERM')='xterm' then
            NoExtendedFrame := true;  {use of acs for xterm is ok}
        end
@@ -933,6 +985,7 @@ var
   i : longint;
   p1,p2 : plongint;
 begin
+(*
   if not force then
    begin
 {$ifdef cpui386}
@@ -969,20 +1022,13 @@ begin
   else
    DoUpdate:=true;
   if not DoUpdate then
-   exit;
+   exit;*)
 {$ifdef linux}
   if Console=ttylinux then
-   begin
-     fplSeek(TTYFd, 4, Seek_Set);
-     fpWrite(TTYFd, VideoBuf^,VideoBufSize);
-   end
+    update_vcsa(force)
   else
-   begin
-{$endif}
-     UpdateTTY(force);
-{$ifdef linux}
-   end;
 {$endif}
+    UpdateTTY(force);
   Move(VideoBuf^, OldVideoBuf^, VideoBufSize);
 end;
 
@@ -1003,19 +1049,14 @@ begin
 {$ifdef linux}
   if Console=ttylinux then
    begin
-     fplSeek(TTYFd, 2, Seek_Set);
      Pos[1]:=NewCursorX;
      Pos[2]:=NewCursorY;
-     fpWrite(TTYFd, Pos, 2);
+     fppwrite(ttyfd,pos,2,2);
    end
   else
-   begin
-{$endif}
-     { newcursorx,y and CursorX,Y are 0 based ! }
-     SendEscapeSeq(XY2Ansi(NewCursorX+1,NewCursorY+1,CursorX+1,CursorY+1));
-{$ifdef linux}
-   end;
 {$endif}
+    { newcursorx,y and CursorX,Y are 0 based ! }
+    SendEscapeSeq(XY2Ansi(NewCursorX+1,NewCursorY+1,CursorX+1,CursorY+1));
   CursorX:=NewCursorX;
   CursorY:=NewCursorY;
 end;

+ 62 - 41
rtl/win32/Makefile

@@ -1,8 +1,8 @@
 #
-# Don't edit, this file is generated by FPCMake Version 2.0.0 [2006/02/06]
+# Don't edit, this file is generated by FPCMake Version 2.0.0 [2006/03/10]
 #
 default: all
-MAKEFILETARGETS=i386-linux i386-go32v2 i386-win32 i386-os2 i386-freebsd i386-beos i386-netbsd i386-solaris i386-qnx i386-netware i386-openbsd i386-wdosx i386-emx i386-watcom i386-netwlibc i386-wince m68k-linux m68k-freebsd m68k-netbsd m68k-amiga m68k-atari m68k-openbsd m68k-palmos powerpc-linux powerpc-netbsd powerpc-macos powerpc-darwin powerpc-morphos sparc-linux sparc-netbsd sparc-solaris x86_64-linux x86_64-freebsd x86_64-win64 arm-linux arm-palmos arm-wince powerpc64-linux
+MAKEFILETARGETS=i386-linux i386-go32v2 i386-win32 i386-os2 i386-freebsd i386-beos i386-netbsd i386-solaris i386-qnx i386-netware i386-openbsd i386-wdosx i386-darwin i386-emx i386-watcom i386-netwlibc i386-wince m68k-linux m68k-freebsd m68k-netbsd m68k-amiga m68k-atari m68k-openbsd m68k-palmos powerpc-linux powerpc-netbsd powerpc-macos powerpc-darwin powerpc-morphos sparc-linux sparc-netbsd sparc-solaris x86_64-linux x86_64-freebsd x86_64-win64 arm-linux arm-palmos arm-wince powerpc64-linux
 BSDs = freebsd netbsd openbsd darwin
 UNIXs = linux $(BSDs) solaris qnx
 LIMIT83fs = go32v2 os2 emx watcom
@@ -253,118 +253,121 @@ OBJPASDIR=$(RTL)/objpas
 include $(WININC)/makefile.inc
 WINDOWS_SOURCE_FILES=$(addprefix $(WININC)/,$(addsuffix .inc,$(WINDOWS_FILES)))
 ifeq ($(FULL_TARGET),i386-linux)
-override TARGET_UNITS+=$(SYSTEMUNIT) ctypes objpas macpas strings lineinfo heaptrc matrix windows winsock initc cmem dynlibs signals dos crt objects messages rtlconsts sysconst sysutils math types strutils convutils dateutils varutils variants typinfo classes cpu mmx charset ucomplex getopts winevent sockets printer video mouse keyboard winsysut fpmkunit
+override TARGET_UNITS+=$(SYSTEMUNIT) ctypes objpas macpas strings lineinfo heaptrc matrix windows winsock winsock2 initc cmem dynlibs signals dos crt objects messages rtlconsts sysconst sysutils math types strutils convutils dateutils varutils variants typinfo classes cpu mmx charset ucomplex getopts winevent sockets printer video mouse keyboard winsysut fpmkunit
 endif
 ifeq ($(FULL_TARGET),i386-go32v2)
-override TARGET_UNITS+=$(SYSTEMUNIT) ctypes objpas macpas strings lineinfo heaptrc matrix windows winsock initc cmem dynlibs signals dos crt objects messages rtlconsts sysconst sysutils math types strutils convutils dateutils varutils variants typinfo classes cpu mmx charset ucomplex getopts winevent sockets printer video mouse keyboard winsysut fpmkunit
+override TARGET_UNITS+=$(SYSTEMUNIT) ctypes objpas macpas strings lineinfo heaptrc matrix windows winsock winsock2 initc cmem dynlibs signals dos crt objects messages rtlconsts sysconst sysutils math types strutils convutils dateutils varutils variants typinfo classes cpu mmx charset ucomplex getopts winevent sockets printer video mouse keyboard winsysut fpmkunit
 endif
 ifeq ($(FULL_TARGET),i386-win32)
-override TARGET_UNITS+=$(SYSTEMUNIT) ctypes objpas macpas strings lineinfo heaptrc matrix windows winsock initc cmem dynlibs signals dos crt objects messages rtlconsts sysconst sysutils math types strutils convutils dateutils varutils variants typinfo classes cpu mmx charset ucomplex getopts winevent sockets printer video mouse keyboard winsysut fpmkunit
+override TARGET_UNITS+=$(SYSTEMUNIT) ctypes objpas macpas strings lineinfo heaptrc matrix windows winsock winsock2 initc cmem dynlibs signals dos crt objects messages rtlconsts sysconst sysutils math types strutils convutils dateutils varutils variants typinfo classes cpu mmx charset ucomplex getopts winevent sockets printer video mouse keyboard winsysut fpmkunit
 endif
 ifeq ($(FULL_TARGET),i386-os2)
-override TARGET_UNITS+=$(SYSTEMUNIT) ctypes objpas macpas strings lineinfo heaptrc matrix windows winsock initc cmem dynlibs signals dos crt objects messages rtlconsts sysconst sysutils math types strutils convutils dateutils varutils variants typinfo classes cpu mmx charset ucomplex getopts winevent sockets printer video mouse keyboard winsysut fpmkunit
+override TARGET_UNITS+=$(SYSTEMUNIT) ctypes objpas macpas strings lineinfo heaptrc matrix windows winsock winsock2 initc cmem dynlibs signals dos crt objects messages rtlconsts sysconst sysutils math types strutils convutils dateutils varutils variants typinfo classes cpu mmx charset ucomplex getopts winevent sockets printer video mouse keyboard winsysut fpmkunit
 endif
 ifeq ($(FULL_TARGET),i386-freebsd)
-override TARGET_UNITS+=$(SYSTEMUNIT) ctypes objpas macpas strings lineinfo heaptrc matrix windows winsock initc cmem dynlibs signals dos crt objects messages rtlconsts sysconst sysutils math types strutils convutils dateutils varutils variants typinfo classes cpu mmx charset ucomplex getopts winevent sockets printer video mouse keyboard winsysut fpmkunit
+override TARGET_UNITS+=$(SYSTEMUNIT) ctypes objpas macpas strings lineinfo heaptrc matrix windows winsock winsock2 initc cmem dynlibs signals dos crt objects messages rtlconsts sysconst sysutils math types strutils convutils dateutils varutils variants typinfo classes cpu mmx charset ucomplex getopts winevent sockets printer video mouse keyboard winsysut fpmkunit
 endif
 ifeq ($(FULL_TARGET),i386-beos)
-override TARGET_UNITS+=$(SYSTEMUNIT) ctypes objpas macpas strings lineinfo heaptrc matrix windows winsock initc cmem dynlibs signals dos crt objects messages rtlconsts sysconst sysutils math types strutils convutils dateutils varutils variants typinfo classes cpu mmx charset ucomplex getopts winevent sockets printer video mouse keyboard winsysut fpmkunit
+override TARGET_UNITS+=$(SYSTEMUNIT) ctypes objpas macpas strings lineinfo heaptrc matrix windows winsock winsock2 initc cmem dynlibs signals dos crt objects messages rtlconsts sysconst sysutils math types strutils convutils dateutils varutils variants typinfo classes cpu mmx charset ucomplex getopts winevent sockets printer video mouse keyboard winsysut fpmkunit
 endif
 ifeq ($(FULL_TARGET),i386-netbsd)
-override TARGET_UNITS+=$(SYSTEMUNIT) ctypes objpas macpas strings lineinfo heaptrc matrix windows winsock initc cmem dynlibs signals dos crt objects messages rtlconsts sysconst sysutils math types strutils convutils dateutils varutils variants typinfo classes cpu mmx charset ucomplex getopts winevent sockets printer video mouse keyboard winsysut fpmkunit
+override TARGET_UNITS+=$(SYSTEMUNIT) ctypes objpas macpas strings lineinfo heaptrc matrix windows winsock winsock2 initc cmem dynlibs signals dos crt objects messages rtlconsts sysconst sysutils math types strutils convutils dateutils varutils variants typinfo classes cpu mmx charset ucomplex getopts winevent sockets printer video mouse keyboard winsysut fpmkunit
 endif
 ifeq ($(FULL_TARGET),i386-solaris)
-override TARGET_UNITS+=$(SYSTEMUNIT) ctypes objpas macpas strings lineinfo heaptrc matrix windows winsock initc cmem dynlibs signals dos crt objects messages rtlconsts sysconst sysutils math types strutils convutils dateutils varutils variants typinfo classes cpu mmx charset ucomplex getopts winevent sockets printer video mouse keyboard winsysut fpmkunit
+override TARGET_UNITS+=$(SYSTEMUNIT) ctypes objpas macpas strings lineinfo heaptrc matrix windows winsock winsock2 initc cmem dynlibs signals dos crt objects messages rtlconsts sysconst sysutils math types strutils convutils dateutils varutils variants typinfo classes cpu mmx charset ucomplex getopts winevent sockets printer video mouse keyboard winsysut fpmkunit
 endif
 ifeq ($(FULL_TARGET),i386-qnx)
-override TARGET_UNITS+=$(SYSTEMUNIT) ctypes objpas macpas strings lineinfo heaptrc matrix windows winsock initc cmem dynlibs signals dos crt objects messages rtlconsts sysconst sysutils math types strutils convutils dateutils varutils variants typinfo classes cpu mmx charset ucomplex getopts winevent sockets printer video mouse keyboard winsysut fpmkunit
+override TARGET_UNITS+=$(SYSTEMUNIT) ctypes objpas macpas strings lineinfo heaptrc matrix windows winsock winsock2 initc cmem dynlibs signals dos crt objects messages rtlconsts sysconst sysutils math types strutils convutils dateutils varutils variants typinfo classes cpu mmx charset ucomplex getopts winevent sockets printer video mouse keyboard winsysut fpmkunit
 endif
 ifeq ($(FULL_TARGET),i386-netware)
-override TARGET_UNITS+=$(SYSTEMUNIT) ctypes objpas macpas strings lineinfo heaptrc matrix windows winsock initc cmem dynlibs signals dos crt objects messages rtlconsts sysconst sysutils math types strutils convutils dateutils varutils variants typinfo classes cpu mmx charset ucomplex getopts winevent sockets printer video mouse keyboard winsysut fpmkunit
+override TARGET_UNITS+=$(SYSTEMUNIT) ctypes objpas macpas strings lineinfo heaptrc matrix windows winsock winsock2 initc cmem dynlibs signals dos crt objects messages rtlconsts sysconst sysutils math types strutils convutils dateutils varutils variants typinfo classes cpu mmx charset ucomplex getopts winevent sockets printer video mouse keyboard winsysut fpmkunit
 endif
 ifeq ($(FULL_TARGET),i386-openbsd)
-override TARGET_UNITS+=$(SYSTEMUNIT) ctypes objpas macpas strings lineinfo heaptrc matrix windows winsock initc cmem dynlibs signals dos crt objects messages rtlconsts sysconst sysutils math types strutils convutils dateutils varutils variants typinfo classes cpu mmx charset ucomplex getopts winevent sockets printer video mouse keyboard winsysut fpmkunit
+override TARGET_UNITS+=$(SYSTEMUNIT) ctypes objpas macpas strings lineinfo heaptrc matrix windows winsock winsock2 initc cmem dynlibs signals dos crt objects messages rtlconsts sysconst sysutils math types strutils convutils dateutils varutils variants typinfo classes cpu mmx charset ucomplex getopts winevent sockets printer video mouse keyboard winsysut fpmkunit
 endif
 ifeq ($(FULL_TARGET),i386-wdosx)
-override TARGET_UNITS+=$(SYSTEMUNIT) ctypes objpas macpas strings lineinfo heaptrc matrix windows winsock initc cmem dynlibs signals dos crt objects messages rtlconsts sysconst sysutils math types strutils convutils dateutils varutils variants typinfo classes cpu mmx charset ucomplex getopts winevent sockets printer video mouse keyboard winsysut fpmkunit
+override TARGET_UNITS+=$(SYSTEMUNIT) ctypes objpas macpas strings lineinfo heaptrc matrix windows winsock winsock2 initc cmem dynlibs signals dos crt objects messages rtlconsts sysconst sysutils math types strutils convutils dateutils varutils variants typinfo classes cpu mmx charset ucomplex getopts winevent sockets printer video mouse keyboard winsysut fpmkunit
+endif
+ifeq ($(FULL_TARGET),i386-darwin)
+override TARGET_UNITS+=$(SYSTEMUNIT) ctypes objpas macpas strings lineinfo heaptrc matrix windows winsock winsock2 initc cmem dynlibs signals dos crt objects messages rtlconsts sysconst sysutils math types strutils convutils dateutils varutils variants typinfo classes cpu mmx charset ucomplex getopts winevent sockets printer video mouse keyboard winsysut fpmkunit
 endif
 ifeq ($(FULL_TARGET),i386-emx)
-override TARGET_UNITS+=$(SYSTEMUNIT) ctypes objpas macpas strings lineinfo heaptrc matrix windows winsock initc cmem dynlibs signals dos crt objects messages rtlconsts sysconst sysutils math types strutils convutils dateutils varutils variants typinfo classes cpu mmx charset ucomplex getopts winevent sockets printer video mouse keyboard winsysut fpmkunit
+override TARGET_UNITS+=$(SYSTEMUNIT) ctypes objpas macpas strings lineinfo heaptrc matrix windows winsock winsock2 initc cmem dynlibs signals dos crt objects messages rtlconsts sysconst sysutils math types strutils convutils dateutils varutils variants typinfo classes cpu mmx charset ucomplex getopts winevent sockets printer video mouse keyboard winsysut fpmkunit
 endif
 ifeq ($(FULL_TARGET),i386-watcom)
-override TARGET_UNITS+=$(SYSTEMUNIT) ctypes objpas macpas strings lineinfo heaptrc matrix windows winsock initc cmem dynlibs signals dos crt objects messages rtlconsts sysconst sysutils math types strutils convutils dateutils varutils variants typinfo classes cpu mmx charset ucomplex getopts winevent sockets printer video mouse keyboard winsysut fpmkunit
+override TARGET_UNITS+=$(SYSTEMUNIT) ctypes objpas macpas strings lineinfo heaptrc matrix windows winsock winsock2 initc cmem dynlibs signals dos crt objects messages rtlconsts sysconst sysutils math types strutils convutils dateutils varutils variants typinfo classes cpu mmx charset ucomplex getopts winevent sockets printer video mouse keyboard winsysut fpmkunit
 endif
 ifeq ($(FULL_TARGET),i386-netwlibc)
-override TARGET_UNITS+=$(SYSTEMUNIT) ctypes objpas macpas strings lineinfo heaptrc matrix windows winsock initc cmem dynlibs signals dos crt objects messages rtlconsts sysconst sysutils math types strutils convutils dateutils varutils variants typinfo classes cpu mmx charset ucomplex getopts winevent sockets printer video mouse keyboard winsysut fpmkunit
+override TARGET_UNITS+=$(SYSTEMUNIT) ctypes objpas macpas strings lineinfo heaptrc matrix windows winsock winsock2 initc cmem dynlibs signals dos crt objects messages rtlconsts sysconst sysutils math types strutils convutils dateutils varutils variants typinfo classes cpu mmx charset ucomplex getopts winevent sockets printer video mouse keyboard winsysut fpmkunit
 endif
 ifeq ($(FULL_TARGET),i386-wince)
-override TARGET_UNITS+=$(SYSTEMUNIT) ctypes objpas macpas strings lineinfo heaptrc matrix windows winsock initc cmem dynlibs signals dos crt objects messages rtlconsts sysconst sysutils math types strutils convutils dateutils varutils variants typinfo classes cpu mmx charset ucomplex getopts winevent sockets printer video mouse keyboard winsysut fpmkunit
+override TARGET_UNITS+=$(SYSTEMUNIT) ctypes objpas macpas strings lineinfo heaptrc matrix windows winsock winsock2 initc cmem dynlibs signals dos crt objects messages rtlconsts sysconst sysutils math types strutils convutils dateutils varutils variants typinfo classes cpu mmx charset ucomplex getopts winevent sockets printer video mouse keyboard winsysut fpmkunit
 endif
 ifeq ($(FULL_TARGET),m68k-linux)
-override TARGET_UNITS+=$(SYSTEMUNIT) ctypes objpas macpas strings lineinfo heaptrc matrix windows winsock initc cmem dynlibs signals dos crt objects messages rtlconsts sysconst sysutils math types strutils convutils dateutils varutils variants typinfo classes cpu mmx charset ucomplex getopts winevent sockets printer video mouse keyboard winsysut fpmkunit
+override TARGET_UNITS+=$(SYSTEMUNIT) ctypes objpas macpas strings lineinfo heaptrc matrix windows winsock winsock2 initc cmem dynlibs signals dos crt objects messages rtlconsts sysconst sysutils math types strutils convutils dateutils varutils variants typinfo classes cpu mmx charset ucomplex getopts winevent sockets printer video mouse keyboard winsysut fpmkunit
 endif
 ifeq ($(FULL_TARGET),m68k-freebsd)
-override TARGET_UNITS+=$(SYSTEMUNIT) ctypes objpas macpas strings lineinfo heaptrc matrix windows winsock initc cmem dynlibs signals dos crt objects messages rtlconsts sysconst sysutils math types strutils convutils dateutils varutils variants typinfo classes cpu mmx charset ucomplex getopts winevent sockets printer video mouse keyboard winsysut fpmkunit
+override TARGET_UNITS+=$(SYSTEMUNIT) ctypes objpas macpas strings lineinfo heaptrc matrix windows winsock winsock2 initc cmem dynlibs signals dos crt objects messages rtlconsts sysconst sysutils math types strutils convutils dateutils varutils variants typinfo classes cpu mmx charset ucomplex getopts winevent sockets printer video mouse keyboard winsysut fpmkunit
 endif
 ifeq ($(FULL_TARGET),m68k-netbsd)
-override TARGET_UNITS+=$(SYSTEMUNIT) ctypes objpas macpas strings lineinfo heaptrc matrix windows winsock initc cmem dynlibs signals dos crt objects messages rtlconsts sysconst sysutils math types strutils convutils dateutils varutils variants typinfo classes cpu mmx charset ucomplex getopts winevent sockets printer video mouse keyboard winsysut fpmkunit
+override TARGET_UNITS+=$(SYSTEMUNIT) ctypes objpas macpas strings lineinfo heaptrc matrix windows winsock winsock2 initc cmem dynlibs signals dos crt objects messages rtlconsts sysconst sysutils math types strutils convutils dateutils varutils variants typinfo classes cpu mmx charset ucomplex getopts winevent sockets printer video mouse keyboard winsysut fpmkunit
 endif
 ifeq ($(FULL_TARGET),m68k-amiga)
-override TARGET_UNITS+=$(SYSTEMUNIT) ctypes objpas macpas strings lineinfo heaptrc matrix windows winsock initc cmem dynlibs signals dos crt objects messages rtlconsts sysconst sysutils math types strutils convutils dateutils varutils variants typinfo classes cpu mmx charset ucomplex getopts winevent sockets printer video mouse keyboard winsysut fpmkunit
+override TARGET_UNITS+=$(SYSTEMUNIT) ctypes objpas macpas strings lineinfo heaptrc matrix windows winsock winsock2 initc cmem dynlibs signals dos crt objects messages rtlconsts sysconst sysutils math types strutils convutils dateutils varutils variants typinfo classes cpu mmx charset ucomplex getopts winevent sockets printer video mouse keyboard winsysut fpmkunit
 endif
 ifeq ($(FULL_TARGET),m68k-atari)
-override TARGET_UNITS+=$(SYSTEMUNIT) ctypes objpas macpas strings lineinfo heaptrc matrix windows winsock initc cmem dynlibs signals dos crt objects messages rtlconsts sysconst sysutils math types strutils convutils dateutils varutils variants typinfo classes cpu mmx charset ucomplex getopts winevent sockets printer video mouse keyboard winsysut fpmkunit
+override TARGET_UNITS+=$(SYSTEMUNIT) ctypes objpas macpas strings lineinfo heaptrc matrix windows winsock winsock2 initc cmem dynlibs signals dos crt objects messages rtlconsts sysconst sysutils math types strutils convutils dateutils varutils variants typinfo classes cpu mmx charset ucomplex getopts winevent sockets printer video mouse keyboard winsysut fpmkunit
 endif
 ifeq ($(FULL_TARGET),m68k-openbsd)
-override TARGET_UNITS+=$(SYSTEMUNIT) ctypes objpas macpas strings lineinfo heaptrc matrix windows winsock initc cmem dynlibs signals dos crt objects messages rtlconsts sysconst sysutils math types strutils convutils dateutils varutils variants typinfo classes cpu mmx charset ucomplex getopts winevent sockets printer video mouse keyboard winsysut fpmkunit
+override TARGET_UNITS+=$(SYSTEMUNIT) ctypes objpas macpas strings lineinfo heaptrc matrix windows winsock winsock2 initc cmem dynlibs signals dos crt objects messages rtlconsts sysconst sysutils math types strutils convutils dateutils varutils variants typinfo classes cpu mmx charset ucomplex getopts winevent sockets printer video mouse keyboard winsysut fpmkunit
 endif
 ifeq ($(FULL_TARGET),m68k-palmos)
-override TARGET_UNITS+=$(SYSTEMUNIT) ctypes objpas macpas strings lineinfo heaptrc matrix windows winsock initc cmem dynlibs signals dos crt objects messages rtlconsts sysconst sysutils math types strutils convutils dateutils varutils variants typinfo classes cpu mmx charset ucomplex getopts winevent sockets printer video mouse keyboard winsysut fpmkunit
+override TARGET_UNITS+=$(SYSTEMUNIT) ctypes objpas macpas strings lineinfo heaptrc matrix windows winsock winsock2 initc cmem dynlibs signals dos crt objects messages rtlconsts sysconst sysutils math types strutils convutils dateutils varutils variants typinfo classes cpu mmx charset ucomplex getopts winevent sockets printer video mouse keyboard winsysut fpmkunit
 endif
 ifeq ($(FULL_TARGET),powerpc-linux)
-override TARGET_UNITS+=$(SYSTEMUNIT) ctypes objpas macpas strings lineinfo heaptrc matrix windows winsock initc cmem dynlibs signals dos crt objects messages rtlconsts sysconst sysutils math types strutils convutils dateutils varutils variants typinfo classes cpu mmx charset ucomplex getopts winevent sockets printer video mouse keyboard winsysut fpmkunit
+override TARGET_UNITS+=$(SYSTEMUNIT) ctypes objpas macpas strings lineinfo heaptrc matrix windows winsock winsock2 initc cmem dynlibs signals dos crt objects messages rtlconsts sysconst sysutils math types strutils convutils dateutils varutils variants typinfo classes cpu mmx charset ucomplex getopts winevent sockets printer video mouse keyboard winsysut fpmkunit
 endif
 ifeq ($(FULL_TARGET),powerpc-netbsd)
-override TARGET_UNITS+=$(SYSTEMUNIT) ctypes objpas macpas strings lineinfo heaptrc matrix windows winsock initc cmem dynlibs signals dos crt objects messages rtlconsts sysconst sysutils math types strutils convutils dateutils varutils variants typinfo classes cpu mmx charset ucomplex getopts winevent sockets printer video mouse keyboard winsysut fpmkunit
+override TARGET_UNITS+=$(SYSTEMUNIT) ctypes objpas macpas strings lineinfo heaptrc matrix windows winsock winsock2 initc cmem dynlibs signals dos crt objects messages rtlconsts sysconst sysutils math types strutils convutils dateutils varutils variants typinfo classes cpu mmx charset ucomplex getopts winevent sockets printer video mouse keyboard winsysut fpmkunit
 endif
 ifeq ($(FULL_TARGET),powerpc-macos)
-override TARGET_UNITS+=$(SYSTEMUNIT) ctypes objpas macpas strings lineinfo heaptrc matrix windows winsock initc cmem dynlibs signals dos crt objects messages rtlconsts sysconst sysutils math types strutils convutils dateutils varutils variants typinfo classes cpu mmx charset ucomplex getopts winevent sockets printer video mouse keyboard winsysut fpmkunit
+override TARGET_UNITS+=$(SYSTEMUNIT) ctypes objpas macpas strings lineinfo heaptrc matrix windows winsock winsock2 initc cmem dynlibs signals dos crt objects messages rtlconsts sysconst sysutils math types strutils convutils dateutils varutils variants typinfo classes cpu mmx charset ucomplex getopts winevent sockets printer video mouse keyboard winsysut fpmkunit
 endif
 ifeq ($(FULL_TARGET),powerpc-darwin)
-override TARGET_UNITS+=$(SYSTEMUNIT) ctypes objpas macpas strings lineinfo heaptrc matrix windows winsock initc cmem dynlibs signals dos crt objects messages rtlconsts sysconst sysutils math types strutils convutils dateutils varutils variants typinfo classes cpu mmx charset ucomplex getopts winevent sockets printer video mouse keyboard winsysut fpmkunit
+override TARGET_UNITS+=$(SYSTEMUNIT) ctypes objpas macpas strings lineinfo heaptrc matrix windows winsock winsock2 initc cmem dynlibs signals dos crt objects messages rtlconsts sysconst sysutils math types strutils convutils dateutils varutils variants typinfo classes cpu mmx charset ucomplex getopts winevent sockets printer video mouse keyboard winsysut fpmkunit
 endif
 ifeq ($(FULL_TARGET),powerpc-morphos)
-override TARGET_UNITS+=$(SYSTEMUNIT) ctypes objpas macpas strings lineinfo heaptrc matrix windows winsock initc cmem dynlibs signals dos crt objects messages rtlconsts sysconst sysutils math types strutils convutils dateutils varutils variants typinfo classes cpu mmx charset ucomplex getopts winevent sockets printer video mouse keyboard winsysut fpmkunit
+override TARGET_UNITS+=$(SYSTEMUNIT) ctypes objpas macpas strings lineinfo heaptrc matrix windows winsock winsock2 initc cmem dynlibs signals dos crt objects messages rtlconsts sysconst sysutils math types strutils convutils dateutils varutils variants typinfo classes cpu mmx charset ucomplex getopts winevent sockets printer video mouse keyboard winsysut fpmkunit
 endif
 ifeq ($(FULL_TARGET),sparc-linux)
-override TARGET_UNITS+=$(SYSTEMUNIT) ctypes objpas macpas strings lineinfo heaptrc matrix windows winsock initc cmem dynlibs signals dos crt objects messages rtlconsts sysconst sysutils math types strutils convutils dateutils varutils variants typinfo classes cpu mmx charset ucomplex getopts winevent sockets printer video mouse keyboard winsysut fpmkunit
+override TARGET_UNITS+=$(SYSTEMUNIT) ctypes objpas macpas strings lineinfo heaptrc matrix windows winsock winsock2 initc cmem dynlibs signals dos crt objects messages rtlconsts sysconst sysutils math types strutils convutils dateutils varutils variants typinfo classes cpu mmx charset ucomplex getopts winevent sockets printer video mouse keyboard winsysut fpmkunit
 endif
 ifeq ($(FULL_TARGET),sparc-netbsd)
-override TARGET_UNITS+=$(SYSTEMUNIT) ctypes objpas macpas strings lineinfo heaptrc matrix windows winsock initc cmem dynlibs signals dos crt objects messages rtlconsts sysconst sysutils math types strutils convutils dateutils varutils variants typinfo classes cpu mmx charset ucomplex getopts winevent sockets printer video mouse keyboard winsysut fpmkunit
+override TARGET_UNITS+=$(SYSTEMUNIT) ctypes objpas macpas strings lineinfo heaptrc matrix windows winsock winsock2 initc cmem dynlibs signals dos crt objects messages rtlconsts sysconst sysutils math types strutils convutils dateutils varutils variants typinfo classes cpu mmx charset ucomplex getopts winevent sockets printer video mouse keyboard winsysut fpmkunit
 endif
 ifeq ($(FULL_TARGET),sparc-solaris)
-override TARGET_UNITS+=$(SYSTEMUNIT) ctypes objpas macpas strings lineinfo heaptrc matrix windows winsock initc cmem dynlibs signals dos crt objects messages rtlconsts sysconst sysutils math types strutils convutils dateutils varutils variants typinfo classes cpu mmx charset ucomplex getopts winevent sockets printer video mouse keyboard winsysut fpmkunit
+override TARGET_UNITS+=$(SYSTEMUNIT) ctypes objpas macpas strings lineinfo heaptrc matrix windows winsock winsock2 initc cmem dynlibs signals dos crt objects messages rtlconsts sysconst sysutils math types strutils convutils dateutils varutils variants typinfo classes cpu mmx charset ucomplex getopts winevent sockets printer video mouse keyboard winsysut fpmkunit
 endif
 ifeq ($(FULL_TARGET),x86_64-linux)
-override TARGET_UNITS+=$(SYSTEMUNIT) ctypes objpas macpas strings lineinfo heaptrc matrix windows winsock initc cmem dynlibs signals dos crt objects messages rtlconsts sysconst sysutils math types strutils convutils dateutils varutils variants typinfo classes cpu mmx charset ucomplex getopts winevent sockets printer video mouse keyboard winsysut fpmkunit
+override TARGET_UNITS+=$(SYSTEMUNIT) ctypes objpas macpas strings lineinfo heaptrc matrix windows winsock winsock2 initc cmem dynlibs signals dos crt objects messages rtlconsts sysconst sysutils math types strutils convutils dateutils varutils variants typinfo classes cpu mmx charset ucomplex getopts winevent sockets printer video mouse keyboard winsysut fpmkunit
 endif
 ifeq ($(FULL_TARGET),x86_64-freebsd)
-override TARGET_UNITS+=$(SYSTEMUNIT) ctypes objpas macpas strings lineinfo heaptrc matrix windows winsock initc cmem dynlibs signals dos crt objects messages rtlconsts sysconst sysutils math types strutils convutils dateutils varutils variants typinfo classes cpu mmx charset ucomplex getopts winevent sockets printer video mouse keyboard winsysut fpmkunit
+override TARGET_UNITS+=$(SYSTEMUNIT) ctypes objpas macpas strings lineinfo heaptrc matrix windows winsock winsock2 initc cmem dynlibs signals dos crt objects messages rtlconsts sysconst sysutils math types strutils convutils dateutils varutils variants typinfo classes cpu mmx charset ucomplex getopts winevent sockets printer video mouse keyboard winsysut fpmkunit
 endif
 ifeq ($(FULL_TARGET),x86_64-win64)
-override TARGET_UNITS+=$(SYSTEMUNIT) ctypes objpas macpas strings lineinfo heaptrc matrix windows winsock initc cmem dynlibs signals dos crt objects messages rtlconsts sysconst sysutils math types strutils convutils dateutils varutils variants typinfo classes cpu mmx charset ucomplex getopts winevent sockets printer video mouse keyboard winsysut fpmkunit
+override TARGET_UNITS+=$(SYSTEMUNIT) ctypes objpas macpas strings lineinfo heaptrc matrix windows winsock winsock2 initc cmem dynlibs signals dos crt objects messages rtlconsts sysconst sysutils math types strutils convutils dateutils varutils variants typinfo classes cpu mmx charset ucomplex getopts winevent sockets printer video mouse keyboard winsysut fpmkunit
 endif
 ifeq ($(FULL_TARGET),arm-linux)
-override TARGET_UNITS+=$(SYSTEMUNIT) ctypes objpas macpas strings lineinfo heaptrc matrix windows winsock initc cmem dynlibs signals dos crt objects messages rtlconsts sysconst sysutils math types strutils convutils dateutils varutils variants typinfo classes cpu mmx charset ucomplex getopts winevent sockets printer video mouse keyboard winsysut fpmkunit
+override TARGET_UNITS+=$(SYSTEMUNIT) ctypes objpas macpas strings lineinfo heaptrc matrix windows winsock winsock2 initc cmem dynlibs signals dos crt objects messages rtlconsts sysconst sysutils math types strutils convutils dateutils varutils variants typinfo classes cpu mmx charset ucomplex getopts winevent sockets printer video mouse keyboard winsysut fpmkunit
 endif
 ifeq ($(FULL_TARGET),arm-palmos)
-override TARGET_UNITS+=$(SYSTEMUNIT) ctypes objpas macpas strings lineinfo heaptrc matrix windows winsock initc cmem dynlibs signals dos crt objects messages rtlconsts sysconst sysutils math types strutils convutils dateutils varutils variants typinfo classes cpu mmx charset ucomplex getopts winevent sockets printer video mouse keyboard winsysut fpmkunit
+override TARGET_UNITS+=$(SYSTEMUNIT) ctypes objpas macpas strings lineinfo heaptrc matrix windows winsock winsock2 initc cmem dynlibs signals dos crt objects messages rtlconsts sysconst sysutils math types strutils convutils dateutils varutils variants typinfo classes cpu mmx charset ucomplex getopts winevent sockets printer video mouse keyboard winsysut fpmkunit
 endif
 ifeq ($(FULL_TARGET),arm-wince)
-override TARGET_UNITS+=$(SYSTEMUNIT) ctypes objpas macpas strings lineinfo heaptrc matrix windows winsock initc cmem dynlibs signals dos crt objects messages rtlconsts sysconst sysutils math types strutils convutils dateutils varutils variants typinfo classes cpu mmx charset ucomplex getopts winevent sockets printer video mouse keyboard winsysut fpmkunit
+override TARGET_UNITS+=$(SYSTEMUNIT) ctypes objpas macpas strings lineinfo heaptrc matrix windows winsock winsock2 initc cmem dynlibs signals dos crt objects messages rtlconsts sysconst sysutils math types strutils convutils dateutils varutils variants typinfo classes cpu mmx charset ucomplex getopts winevent sockets printer video mouse keyboard winsysut fpmkunit
 endif
 ifeq ($(FULL_TARGET),powerpc64-linux)
-override TARGET_UNITS+=$(SYSTEMUNIT) ctypes objpas macpas strings lineinfo heaptrc matrix windows winsock initc cmem dynlibs signals dos crt objects messages rtlconsts sysconst sysutils math types strutils convutils dateutils varutils variants typinfo classes cpu mmx charset ucomplex getopts winevent sockets printer video mouse keyboard winsysut fpmkunit
+override TARGET_UNITS+=$(SYSTEMUNIT) ctypes objpas macpas strings lineinfo heaptrc matrix windows winsock winsock2 initc cmem dynlibs signals dos crt objects messages rtlconsts sysconst sysutils math types strutils convutils dateutils varutils variants typinfo classes cpu mmx charset ucomplex getopts winevent sockets printer video mouse keyboard winsysut fpmkunit
 endif
 ifeq ($(FULL_TARGET),i386-linux)
 override TARGET_LOADERS+=wprt0 wdllprt0 gprt0 wcygprt0
@@ -402,6 +405,9 @@ endif
 ifeq ($(FULL_TARGET),i386-wdosx)
 override TARGET_LOADERS+=wprt0 wdllprt0 gprt0 wcygprt0
 endif
+ifeq ($(FULL_TARGET),i386-darwin)
+override TARGET_LOADERS+=wprt0 wdllprt0 gprt0 wcygprt0
+endif
 ifeq ($(FULL_TARGET),i386-emx)
 override TARGET_LOADERS+=wprt0 wdllprt0 gprt0 wcygprt0
 endif
@@ -516,6 +522,9 @@ endif
 ifeq ($(FULL_TARGET),i386-wdosx)
 override TARGET_RSTS+=math varutils typinfo variants classes dateutils sysconst fpmkunit
 endif
+ifeq ($(FULL_TARGET),i386-darwin)
+override TARGET_RSTS+=math varutils typinfo variants classes dateutils sysconst fpmkunit
+endif
 ifeq ($(FULL_TARGET),i386-emx)
 override TARGET_RSTS+=math varutils typinfo variants classes dateutils sysconst fpmkunit
 endif
@@ -631,6 +640,9 @@ endif
 ifeq ($(FULL_TARGET),i386-wdosx)
 override COMPILER_INCLUDEDIR+=$(INC) $(PROCINC)
 endif
+ifeq ($(FULL_TARGET),i386-darwin)
+override COMPILER_INCLUDEDIR+=$(INC) $(PROCINC)
+endif
 ifeq ($(FULL_TARGET),i386-emx)
 override COMPILER_INCLUDEDIR+=$(INC) $(PROCINC)
 endif
@@ -745,6 +757,9 @@ endif
 ifeq ($(FULL_TARGET),i386-wdosx)
 override COMPILER_SOURCEDIR+=$(INC) $(PROCINC) $(COMMON)
 endif
+ifeq ($(FULL_TARGET),i386-darwin)
+override COMPILER_SOURCEDIR+=$(INC) $(PROCINC) $(COMMON)
+endif
 ifeq ($(FULL_TARGET),i386-emx)
 override COMPILER_SOURCEDIR+=$(INC) $(PROCINC) $(COMMON)
 endif
@@ -1463,12 +1478,17 @@ endif
 endif
 export ZIPPROG
 ifndef TARPROG
+TARPROG:=$(strip $(wildcard $(addsuffix /gtar$(SRCEXEEXT),$(SEARCHPATH))))
+ifeq ($(TARPROG),)
 TARPROG:=$(strip $(wildcard $(addsuffix /tar$(SRCEXEEXT),$(SEARCHPATH))))
 ifeq ($(TARPROG),)
 TARPROG= __missing_command_TARPROG
 else
 TARPROG:=$(firstword $(TARPROG))
 endif
+else
+TARPROG:=$(firstword $(TARPROG))
+endif
 endif
 export TARPROG
 ASNAME=$(BINUTILSPREFIX)as
@@ -2104,7 +2124,8 @@ messages$(PPUEXT): messages.pp $(WININC)/messages.inc $(SYSTEMUNIT)$(PPUEXT)
 	$(COMPILER) -I$(WININC) messages.pp
 opengl32$(PPUEXT) : opengl32.pp windows$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
 winsock$(PPUEXT) : winsock.pp windows$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
-sockets$(PPUEXT) : sockets.pp windows$(PPUEXT) winsock$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT) \
+winsock2$(PPUEXT) : winsock2.pp windows$(PPUEXT) system$(PPUEXT)
+sockets$(PPUEXT) : sockets.pp windows$(PPUEXT) winsock$(PPUEXT) winsock2$(PPUEXT) system$(PPUEXT) \
 		   $(INC)/sockets.inc $(INC)/socketsh.inc
 initc$(PPUEXT) : initc.pp $(SYSTEMUNIT)$(PPUEXT)
 dynlibs$(PPUEXT) : $(INC)/dynlibs.pp windows$(PPUEXT)

+ 4 - 2
rtl/win32/Makefile.fpc

@@ -9,7 +9,7 @@ main=rtl
 loaders=wprt0 wdllprt0 gprt0 wcygprt0
 units=$(SYSTEMUNIT) ctypes objpas macpas strings \
       lineinfo heaptrc matrix \
-      windows winsock initc cmem dynlibs signals \
+      windows winsock winsock2 initc cmem dynlibs signals \
       dos crt objects messages \
       rtlconsts sysconst sysutils math types \
       strutils convutils dateutils varutils variants typinfo classes \
@@ -128,7 +128,9 @@ opengl32$(PPUEXT) : opengl32.pp windows$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
 
 winsock$(PPUEXT) : winsock.pp windows$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
 
-sockets$(PPUEXT) : sockets.pp windows$(PPUEXT) winsock$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT) \
+winsock2$(PPUEXT) : winsock2.pp windows$(PPUEXT) system$(PPUEXT)
+
+sockets$(PPUEXT) : sockets.pp windows$(PPUEXT) winsock$(PPUEXT) winsock2$(PPUEXT) system$(PPUEXT) \
                    $(INC)/sockets.inc $(INC)/socketsh.inc
 
 initc$(PPUEXT) : initc.pp $(SYSTEMUNIT)$(PPUEXT)

+ 22 - 22
rtl/win32/sockets.pp

@@ -19,7 +19,7 @@ Interface
 {$define maybelibc:=}
 
   Uses
-     windows,winsock,ctypes;
+     winsock2,ctypes;
 
 Type
   size_t  = cuint32;
@@ -29,7 +29,7 @@ Type
 
 
   Const
-     AF_MAX          = WinSock.AF_MAX;
+     AF_MAX          = WinSock2.AF_MAX;
      PF_MAX          = AF_MAX;
 
 {$i socketsh.inc}
@@ -52,7 +52,7 @@ Implementation
 
 function fpsocket       (domain:cint; xtype:cint; protocol: cint):cint;
 begin
-  fpSocket:=WinSock.Socket(Domain,xtype,ProtoCol);
+  fpSocket:=WinSock2.Socket(Domain,xtype,ProtoCol);
   if fpSocket<0 then
     SocketError:=WSAGetLastError
   else
@@ -61,7 +61,7 @@ end;
 
 function fpsend (s:cint; msg:pointer; len:size_t; flags:cint):ssize_t;
 begin
-  fpSend:=WinSock.Send(S,msg,len,flags);
+  fpSend:=WinSock2.Send(S,msg,len,flags);
   if fpSend<0 then
     SocketError:=WSAGetLastError
   else
@@ -71,7 +71,7 @@ end;
 function fpsendto (s:cint; msg:pointer; len:size_t; flags:cint; tox :psockaddr; tolen: tsocklen):ssize_t;
 begin
   // Dubious construct, this should be checked. (IPV6 fails ?)
-  fpSendTo:=WinSock.SendTo(S,msg,Len,Flags,Winsock.TSockAddr(tox^),toLen);
+  fpSendTo:=WinSock2.SendTo(S,msg,Len,Flags,Winsock2.TSockAddr(tox^),toLen);
   if fpSendTo<0 then
     SocketError:=WSAGetLastError
   else
@@ -80,7 +80,7 @@ end;
 
 function fprecv         (s:cint; buf: pointer; len: size_t; flags: cint):ssize_t;
 begin
-  fpRecv:=WinSock.Recv(S,Buf,Len,Flags);
+  fpRecv:=WinSock2.Recv(S,Buf,Len,Flags);
   if fpRecv<0 then
     SocketError:=WSAGetLastError
   else
@@ -90,7 +90,7 @@ end;
 function fprecvfrom    (s:cint; buf: pointer; len: size_t; flags: cint; from : psockaddr; fromlen : psocklen):ssize_t;
 
 begin
-  fpRecvFrom:=WinSock.RecvFrom(S,Buf,Len,Flags,Winsock.TSockAddr(from^),FromLen^);
+  fpRecvFrom:=WinSock2.RecvFrom(S,Buf,Len,Flags,Winsock2.TSockAddr(from^),FromLen^);
   if fpRecvFrom<0 then
     SocketError:=WSAGetLastError
   else
@@ -100,7 +100,7 @@ end;
 function fpconnect     (s:cint; name  : psockaddr; namelen : tsocklen):cint;
 
 begin
-  fpConnect:=WinSock.Connect(S,WinSock.TSockAddr(name^),nameLen);
+  fpConnect:=Winsock2.Connect(S,Winsock2.TSockAddr(name^),nameLen);
   if fpConnect<0 then
     SocketError:=WSAGetLastError
   else
@@ -109,7 +109,7 @@ end;
 
 function fpshutdown     (s:cint; how:cint):cint;
 begin
-  fpShutDown:=WinSock.ShutDown(S,How);
+  fpShutDown:=Winsock2.ShutDown(S,How);
   if fpShutDown<0 then
     SocketError:=WSAGetLastError
   else
@@ -146,7 +146,7 @@ end;
 function fpbind (s:cint; addrx : psockaddr; addrlen : tsocklen):cint;
 
 begin
-  fpbind:=WinSock.Bind(S,WinSock.PSockAddr(Addrx),AddrLen);
+  fpbind:=Winsock2.Bind(S,Winsock2.PSockAddr(Addrx),AddrLen);
   if fpbind<0 then
        SocketError:=WSAGetLastError
   else
@@ -156,7 +156,7 @@ end;
 function fplisten      (s:cint; backlog : cint):cint;
 
 begin
-  fplisten:=WinSock.Listen(S,backlog);
+  fplisten:=Winsock2.Listen(S,backlog);
   if fplisten<0 then
        SocketError:=WSAGetLastError
   else
@@ -165,7 +165,7 @@ end;
 
 function fpaccept      (s:cint; addrx : psockaddr; addrlen : psocklen):cint;
 begin
-  fpAccept:=WinSock.Accept(S,WinSock.PSockAddr(Addrx),plongint(@AddrLen));
+  fpAccept:=Winsock2.Accept(S,Winsock2.PSockAddr(Addrx),plongint(@AddrLen));
   if fpAccept<0 then
     SocketError:=WSAGetLastError
   else
@@ -175,7 +175,7 @@ end;
 function fpgetsockname (s:cint; name  : psockaddr; namelen : psocklen):cint;
 
 begin
-  fpGetSockName:=WinSock.GetSockName(S,WinSock.TSockAddr(name^),nameLen^);
+  fpGetSockName:=Winsock2.GetSockName(S,Winsock2.TSockAddr(name^),nameLen^);
   if fpGetSockName<0 then
     SocketError:=WSAGetLastError
   else
@@ -184,7 +184,7 @@ end;
 
 function fpgetpeername (s:cint; name  : psockaddr; namelen : psocklen):cint;
 begin
-  fpGetPeerName:=WinSock.GetPeerName(S,WinSock.TSockAddr(name^),NameLen^);
+  fpGetPeerName:=Winsock2.GetPeerName(S,Winsock2.TSockAddr(name^),NameLen^);
   if fpGetPeerName<0 then
     SocketError:=WSAGetLastError
   else
@@ -193,7 +193,7 @@ end;
 
 function fpgetsockopt  (s:cint; level:cint; optname:cint; optval:pointer; optlen : psocklen):cint;
 begin
-  fpGetSockOpt:=WinSock.GetSockOpt(S,Level,OptName,OptVal,OptLen^);
+  fpGetSockOpt:=Winsock2.GetSockOpt(S,Level,OptName,OptVal,OptLen^);
   if fpGetSockOpt<0 then
     SocketError:=WSAGetLastError
   else
@@ -203,7 +203,7 @@ end;
 function fpsetsockopt  (s:cint; level:cint; optname:cint; optval:pointer; optlen :tsocklen):cint;
 
 begin
-  fpSetSockOpt:=WinSock.SetSockOpt(S,Level,OptName,OptVal,OptLen);
+  fpSetSockOpt:=Winsock2.SetSockOpt(S,Level,OptName,OptVal,OptLen);
   if fpSetSockOpt<0 then
     SocketError:=WSAGetLastError
   else
@@ -217,7 +217,7 @@ end;
 Function CloseSocket(Sock:Longint):Longint;
 var i : longint;
 begin
-  i := Winsock.CloseSocket (Sock);
+  i := Winsock2.CloseSocket (Sock);
   if i <> 0 then
   begin
     SocketError:=WSAGetLastError;
@@ -289,7 +289,7 @@ end;
 { mimic the linux fpWrite/fpRead calls for the file/text socket wrapper }
 function fpWrite(handle : longint;Const bufptr;size : dword) : dword;
 begin
-  fpWrite := dword(WinSock.send(handle, bufptr, size, 0));
+  fpWrite := dword(Winsock2.send(handle, bufptr, size, 0));
   if fpWrite = dword(SOCKET_ERROR) then
   begin
     SocketError := WSAGetLastError;
@@ -314,7 +314,7 @@ function fpRead(handle : longint;var bufptr;size : dword) : dword;
        begin
          if size>d then
            size:=d;
-         fpRead := dword(WinSock.recv(handle, bufptr, size, 0));
+         fpRead := dword(Winsock2.recv(handle, bufptr, size, 0));
          if fpRead = dword(SOCKET_ERROR) then
          begin
            SocketError:= WSAGetLastError;
@@ -329,7 +329,7 @@ function fpRead(handle : longint;var bufptr;size : dword) : dword;
 { mimic the linux fdWrite/fdRead calls for the file/text socket wrapper }
 function fdWrite(handle : longint;Const bufptr;size : dword) : dword;
 begin
-  fdWrite := dword(WinSock.send(handle, bufptr, size, 0));
+  fdWrite := dword(Winsock2.send(handle, bufptr, size, 0));
   if fdWrite = dword(SOCKET_ERROR) then
   begin
     SocketError := WSAGetLastError;
@@ -354,7 +354,7 @@ function fdRead(handle : longint;var bufptr;size : dword) : dword;
        begin
          if size>d then
            size:=d;
-         fdRead := dword(WinSock.recv(handle, bufptr, size, 0));
+         fdRead := dword(Winsock2.recv(handle, bufptr, size, 0));
          if fdRead = dword(SOCKET_ERROR) then
          begin
            SocketError:= WSAGetLastError;
@@ -369,7 +369,7 @@ function fdRead(handle : longint;var bufptr;size : dword) : dword;
 
 {$i sockets.inc}
 
-{ winsocket stack needs an init. and cleanup code }
+{ Winsocket stack needs an init. and cleanup code }
 var
   wsadata : twsadata;
 

+ 12 - 1
rtl/win32/sysutils.pp

@@ -49,12 +49,23 @@ Var
   Win32BuildNumber   : dword;
   Win32CSDVersion    : ShortString;   // CSD record is 128 bytes only?
 
+{ Compatibility with Delphi }
+function Win32Check(res:boolean):boolean;
+
 
 implementation
 
   uses
     sysconst;
 
+function Win32Check(res:boolean):boolean;
+begin
+  if not res then
+    RaiseLastOSError;
+  result:=res;
+end;
+
+
 {$define HASCREATEGUID}
 {$define HASEXPANDUNCFILENAME}
 
@@ -357,7 +368,7 @@ begin
   if SetFileAttributes(PChar(FileName), Attr) then
     Result:=0
   else
-    Result := GetLastError;    
+    Result := GetLastError;
 end;
 
 

+ 1 - 1
rtl/win32/wininc/defines.inc

@@ -658,7 +658,7 @@
      TAPE_SETMARKS = 0;
      TAPE_SHORT_FILEMARKS = $2;
   { CreateWindow  }
-     CW_USEDEFAULT = $80000000;
+     CW_USEDEFAULT = longint($80000000);
      WS_BORDER = $800000;
      WS_CAPTION = $c00000;
      WS_CHILD = $40000000;

+ 1 - 1
rtl/win32/wininc/struct.inc

@@ -3797,7 +3797,7 @@
      TLUID = LUID;
      PLUID = ^LUID;
 
-     LUID_AND_ATTRIBUTES = record
+     LUID_AND_ATTRIBUTES = packed record
           Luid : LUID;
           Attributes : DWORD;
        end;

+ 1331 - 0
rtl/win32/winsock2.pp

@@ -0,0 +1,1331 @@
+{       Winsock2.h -- definitions to be used with the WinSock 2 DLL and WinSock 2 applications.
+        This header file corresponds to version 2.2.x of the WinSock API specification.
+        This file includes parts which are Copyright (c) 1982-1986 Regents
+        of the University of California. All rights reserved.
+        The Berkeley Software License Agreement specifies the terms and
+        conditions for redistribution. }
+
+// converted by Alex Konshin, mailto:[email protected]
+// added FreePascal stuff: [email protected]
+
+unit WinSock2;
+
+{$smartlink on}
+
+interface
+
+Uses Windows;
+
+{       Define the current Winsock version. To build an earlier Winsock version
+        application redefine this value prior to including Winsock2.h. }
+Const
+        WINSOCK_VERSION = $0202;
+        WINSOCK2_DLL = 'ws2_32.dll';
+
+Type
+  u_char = Char;
+  u_short = Word;
+  u_int = DWord;
+  u_long = DWord;
+  pu_char = ^u_char;
+  pu_short = ^u_short;
+  pu_int = ^u_int;
+  pu_long = ^u_long;
+
+  TSocket = u_int;      { The new type to be used in all instances which refer to sockets. }
+
+        WSAEVENT = THandle;
+        PWSAEVENT = ^WSAEVENT;
+        LPWSAEVENT = PWSAEVENT;
+{$IFDEF UNICODE}
+        PMBChar = PWideChar;
+{$ELSE}
+        PMBChar = PChar;
+{$ENDIF}
+
+const
+  FD_SETSIZE     =   64;
+
+type
+  PFDSet = ^TFDSet;
+  TFDSet = packed record
+    fd_count: u_int;
+    fd_array: array[0..FD_SETSIZE-1] of TSocket;
+  end;
+
+  PTimeVal = ^TTimeVal;
+  TTimeVal = packed record
+    tv_sec: Longint;
+    tv_usec: Longint;
+  end;
+
+const
+  IOCPARM_MASK = $7f;
+  IOC_VOID     = $20000000;
+  IOC_OUT      = $40000000;
+  IOC_IN       = $80000000;
+  IOC_INOUT    = (IOC_IN or IOC_OUT);
+
+  FIONREAD     = IOC_OUT or { get # bytes to read }
+    ((Longint(SizeOf(Longint)) and IOCPARM_MASK) shl 16) or
+    (Longint(Byte('f')) shl 8) or 127;
+  FIONBIO      = IOC_IN or { set/clear non-blocking i/o }
+    ((Longint(SizeOf(Longint)) and IOCPARM_MASK) shl 16) or
+    (Longint(Byte('f')) shl 8) or 126;
+  FIOASYNC     = IOC_IN or { set/clear async i/o }
+    ((Longint(SizeOf(Longint)) and IOCPARM_MASK) shl 16) or
+    (Longint(Byte('f')) shl 8) or 125;
+
+type
+  PHostEnt = ^THostEnt;
+  THostEnt = packed record
+    h_name: PChar;
+    h_aliases: ^PChar;
+    h_addrtype: Smallint;
+    h_length: Smallint;
+    case Byte of
+      0: (h_addr_list: ^PChar);
+      1: (h_addr: ^PChar)
+  end;
+
+  PNetEnt = ^TNetEnt;
+  TNetEnt = packed record
+    n_name: PChar;
+    n_aliases: ^PChar;
+    n_addrtype: Smallint;
+    n_net: u_long;
+  end;
+
+  PServEnt = ^TServEnt;
+  TServEnt = packed record
+    s_name: PChar;
+    s_aliases: ^PChar;
+    s_port: Smallint;
+    s_proto: PChar;
+  end;
+
+  PProtoEnt = ^TProtoEnt;
+  TProtoEnt = packed record
+    p_name: PChar;
+    p_aliases: ^Pchar;
+    p_proto: Smallint;
+  end;
+
+const
+
+{ Protocols }
+  IPPROTO_IP     =   0;             { dummy for IP }
+  IPPROTO_ICMP   =   1;             { control message protocol }
+  IPPROTO_IGMP   =   2;             { group management protocol }
+  IPPROTO_GGP    =   3;             { gateway^2 (deprecated) }
+  IPPROTO_TCP    =   6;             { tcp }
+  IPPROTO_PUP    =  12;             { pup }
+  IPPROTO_UDP    =  17;             { user datagram protocol }
+  IPPROTO_IDP    =  22;             { xns idp }
+  IPPROTO_ND     =  77;             { UNOFFICIAL net disk proto }
+
+  IPPROTO_RAW    =  255;            { raw IP packet }
+  IPPROTO_MAX    =  256;
+
+{ Port/socket numbers: network standard functions}
+
+  IPPORT_ECHO    =   7;
+  IPPORT_DISCARD =   9;
+  IPPORT_SYSTAT  =   11;
+  IPPORT_DAYTIME =   13;
+  IPPORT_NETSTAT =   15;
+  IPPORT_FTP     =   21;
+  IPPORT_TELNET  =   23;
+  IPPORT_SMTP    =   25;
+  IPPORT_TIMESERVER  =  37;
+  IPPORT_NAMESERVER  =  42;
+  IPPORT_WHOIS       =  43;
+  IPPORT_MTP         =  57;
+
+{ Port/socket numbers: host specific functions }
+
+  IPPORT_TFTP        =  69;
+  IPPORT_RJE         =  77;
+  IPPORT_FINGER      =  79;
+  IPPORT_TTYLINK     =  87;
+  IPPORT_SUPDUP      =  95;
+
+{ UNIX TCP sockets }
+
+  IPPORT_EXECSERVER  =  512;
+  IPPORT_LOGINSERVER =  513;
+  IPPORT_CMDSERVER   =  514;
+  IPPORT_EFSSERVER   =  520;
+
+{ UNIX UDP sockets }
+
+  IPPORT_BIFFUDP     =  512;
+  IPPORT_WHOSERVER   =  513;
+  IPPORT_ROUTESERVER =  520;
+
+{ Ports < IPPORT_RESERVED are reserved for
+  privileged processes (e.g. root). }
+
+  IPPORT_RESERVED    =  1024;
+
+{ Link numbers }
+
+  IMPLINK_IP         =  155;
+  IMPLINK_LOWEXPER   =  156;
+  IMPLINK_HIGHEXPER  =  158;
+
+  TF_DISCONNECT           = $01;
+  TF_REUSE_SOCKET         = $02;
+  TF_WRITE_BEHIND         = $04;
+
+{ Options for use with [gs]etsockopt at the IP level. }
+
+  IP_OPTIONS          = 1;
+  IP_MULTICAST_IF     = 2;           { set/get IP multicast interface   }
+  IP_MULTICAST_TTL    = 3;           { set/get IP multicast timetolive  }
+  IP_MULTICAST_LOOP   = 4;           { set/get IP multicast loopback    }
+  IP_ADD_MEMBERSHIP   = 5;           { add  an IP group membership      }
+  IP_DROP_MEMBERSHIP  = 6;           { drop an IP group membership      }
+  IP_TTL              = 7;           { set/get IP Time To Live          }
+  IP_TOS              = 8;           { set/get IP Type Of Service       }
+  IP_DONTFRAGMENT     = 9;           { set/get IP Don't Fragment flag   }
+
+
+  IP_DEFAULT_MULTICAST_TTL   = 1;    { normally limit m'casts to 1 hop  }
+  IP_DEFAULT_MULTICAST_LOOP  = 1;    { normally hear sends if a member  }
+  IP_MAX_MEMBERSHIPS         = 20;   { per socket; must fit in one mbuf }
+
+{ This is used instead of -1, since the
+  TSocket type is unsigned.}
+
+  INVALID_SOCKET                = TSocket(NOT(0));
+  SOCKET_ERROR                  = -1;
+
+{ Types }
+
+  SOCK_STREAM     = 1;               { stream socket }
+  SOCK_DGRAM      = 2;               { datagram socket }
+  SOCK_RAW        = 3;               { raw-protocol interface }
+  SOCK_RDM        = 4;               { reliably-delivered message }
+  SOCK_SEQPACKET  = 5;               { sequenced packet stream }
+
+{ Option flags per-socket. }
+
+  SO_DEBUG        = $0001;          { turn on debugging info recording }
+  SO_ACCEPTCONN   = $0002;          { socket has had listen() }
+  SO_REUSEADDR    = $0004;          { allow local address reuse }
+  SO_KEEPALIVE    = $0008;          { keep connections alive }
+  SO_DONTROUTE    = $0010;          { just use interface addresses }
+  SO_BROADCAST    = $0020;          { permit sending of broadcast msgs }
+  SO_USELOOPBACK  = $0040;          { bypass hardware when possible }
+  SO_LINGER       = $0080;          { linger on close if data present }
+  SO_OOBINLINE    = $0100;          { leave received OOB data in line }
+
+  SO_DONTLINGER  =   $ff7f;
+
+{ Additional options. }
+
+  SO_SNDBUF       = $1001;          { send buffer size }
+  SO_RCVBUF       = $1002;          { receive buffer size }
+  SO_SNDLOWAT     = $1003;          { send low-water mark }
+  SO_RCVLOWAT     = $1004;          { receive low-water mark }
+  SO_SNDTIMEO     = $1005;          { send timeout }
+  SO_RCVTIMEO     = $1006;          { receive timeout }
+  SO_ERROR        = $1007;          { get error status and clear }
+  SO_TYPE         = $1008;          { get socket type }
+
+{ Options for connect and disconnect data and options.  Used only by
+  non-TCP/IP transports such as DECNet, OSI TP4, etc. }
+
+  SO_CONNDATA     = $7000;
+  SO_CONNOPT      = $7001;
+  SO_DISCDATA     = $7002;
+  SO_DISCOPT      = $7003;
+  SO_CONNDATALEN  = $7004;
+  SO_CONNOPTLEN   = $7005;
+  SO_DISCDATALEN  = $7006;
+  SO_DISCOPTLEN   = $7007;
+
+{ Option for opening sockets for synchronous access. }
+  SO_OPENTYPE     = $7008;
+  SO_SYNCHRONOUS_ALERT    = $10;
+  SO_SYNCHRONOUS_NONALERT = $20;
+
+{ Other NT-specific options. }
+  SO_MAXDG        = $7009;
+  SO_MAXPATHDG    = $700A;
+  SO_UPDATE_ACCEPT_CONTEXT     = $700B;
+  SO_CONNECT_TIME = $700C;
+
+{ TCP options. }
+  TCP_NODELAY     = $0001;
+  TCP_BSDURGENT   = $7000;
+
+{ WinSock 2 extension -- new options }
+        SO_GROUP_ID = $2001; // ID of a socket group
+        SO_GROUP_PRIORITY = $2002; // the relative priority within a group
+        SO_MAX_MSG_SIZE = $2003; // maximum message size
+        SO_Protocol_InfoA = $2004; // WSAPROTOCOL_INFOA structure
+        SO_Protocol_InfoW = $2005; // WSAPROTOCOL_INFOW structure
+{$IFDEF UNICODE}
+        SO_Protocol_Info = SO_Protocol_InfoW;
+{$ELSE}
+        SO_Protocol_Info = SO_Protocol_InfoA;
+{$ENDIF}
+        PVD_CONFIG = $3001; // configuration info for service provider
+
+{ Address families. }
+  AF_UNSPEC       = 0;               { unspecified }
+  AF_UNIX         = 1;               { local to host (pipes, portals) }
+  AF_INET         = 2;               { internetwork: UDP, TCP, etc. }
+  AF_IMPLINK      = 3;               { arpanet imp addresses }
+  AF_PUP          = 4;               { pup protocols: e.g. BSP }
+  AF_CHAOS        = 5;               { mit CHAOS protocols }
+  AF_IPX          = 6;               { IPX and SPX }
+  AF_NS           = 6;               { XEROX NS protocols }
+  AF_ISO          = 7;               { ISO protocols }
+  AF_OSI          = AF_ISO;          { OSI is ISO }
+  AF_ECMA         = 8;               { european computer manufacturers }
+  AF_DATAKIT      = 9;               { datakit protocols }
+  AF_CCITT        = 10;              { CCITT protocols, X.25 etc }
+  AF_SNA          = 11;              { IBM SNA }
+  AF_DECnet       = 12;              { DECnet }
+  AF_DLI          = 13;              { Direct data link interface }
+  AF_LAT          = 14;              { LAT }
+  AF_HYLINK       = 15;              { NSC Hyperchannel }
+  AF_APPLETALK    = 16;              { AppleTalk }
+  AF_NETBIOS      = 17;              { NetBios-style addresses }
+  AF_VOICEVIEW    = 18;              { VoiceView }
+  AF_FIREFOX      = 19;              { FireFox }
+  AF_UNKNOWN1     = 20;              { Somebody is using this! }
+  AF_BAN          = 21;              { Banyan }
+        AF_ATM          = 22; // Native ATM Services
+        AF_INET6        = 23; // Internetwork Version 6
+
+        AF_MAX = 24;
+
+{       Socket I/O Controls }
+{Const
+        SIOCSHIWAT = _IOW('s', 0, u_long); // set high watermark
+        SIOCGHIWAT = _IOR('s', 1, u_long); // get high watermark
+        SIOCSLOWAT = _IOW('s', 2, u_long); // set low watermark
+        SIOCGLOWAT = _IOR('s', 3, u_long); // get low watermark
+        SIOCATMARK = _IOR('s', 7, u_long); // at oob mark? }
+
+{ Protocol families, same as address families for now. }
+
+  PF_UNSPEC       = AF_UNSPEC;
+  PF_UNIX         = AF_UNIX;
+  PF_INET         = AF_INET;
+  PF_IMPLINK      = AF_IMPLINK;
+  PF_PUP          = AF_PUP;
+  PF_CHAOS        = AF_CHAOS;
+  PF_NS           = AF_NS;
+  PF_IPX          = AF_IPX;
+  PF_ISO          = AF_ISO;
+  PF_OSI          = AF_OSI;
+  PF_ECMA         = AF_ECMA;
+  PF_DATAKIT      = AF_DATAKIT;
+  PF_CCITT        = AF_CCITT;
+  PF_SNA          = AF_SNA;
+  PF_DECnet       = AF_DECnet;
+  PF_DLI          = AF_DLI;
+  PF_LAT          = AF_LAT;
+  PF_HYLINK       = AF_HYLINK;
+  PF_APPLETALK    = AF_APPLETALK;
+  PF_VOICEVIEW    = AF_VOICEVIEW;
+  PF_FIREFOX      = AF_FIREFOX;
+  PF_UNKNOWN1     = AF_UNKNOWN1;
+  PF_BAN          = AF_BAN;
+        PF_ATM          = AF_ATM;
+        PF_INET6        = AF_INET6;
+
+  PF_MAX          = AF_MAX;
+
+type
+
+  SunB = packed record
+    s_b1, s_b2, s_b3, s_b4: u_char;
+  end;
+
+  SunW = packed record
+    s_w1, s_w2: u_short;
+  end;
+
+  PInAddr = ^TInAddr;
+  TInAddr = packed record
+    case integer of
+      0: (S_un_b: SunB);
+      1: (S_un_w: SunW);
+      2: (S_addr: u_long);
+  end;
+
+  PSockAddrIn = ^TSockAddrIn;
+  TSockAddrIn = packed record
+    case Integer of
+      0: (sin_family: u_short;
+          sin_port: u_short;
+          sin_addr: TInAddr;
+          sin_zero: array[0..7] of Char);
+      1: (sa_family: u_short;
+          sa_data: array[0..13] of Char)
+  end;
+
+  { Structure used by kernel to store most addresses. }
+
+  PSockAddr = ^TSockAddr;
+  TSockAddr = TSockAddrIn;
+
+  { Structure used by kernel to pass protocol information in raw sockets. }
+  PSockProto = ^TSockProto;
+  TSockProto = packed record
+    sp_family: u_short;
+    sp_protocol: u_short;
+  end;
+
+{ Structure used for manipulating linger option. }
+  PLinger = ^TLinger;
+  TLinger = packed record
+    l_onoff: u_short;
+    l_linger: u_short;
+  end;
+
+const
+  INADDR_ANY       = $00000000;
+  INADDR_LOOPBACK  = $7F000001;
+  INADDR_BROADCAST = $FFFFFFFF;
+  INADDR_NONE      = $FFFFFFFF;
+
+        MSG_OOB         = $1;             {process out-of-band data }
+  MSG_PEEK        = $2;             {peek at incoming message }
+  MSG_DONTROUTE   = $4;             {send without using routing tables }
+
+{ WinSock 2 extension -- new flags for WSASend(), WSASendTo(), WSARecv() and WSARecvFrom() }
+        MSG_INTERRUPT = $10; {/* send/recv in the interrupt context */}
+        MSG_MAXIOVLEN = 16;
+
+  MSG_PARTIAL     = $8000;          {partial send or recv for message xport }
+
+{ Define constant based on rfc883, used by gethostbyxxxx() calls. }
+
+  MAXGETHOSTSTRUCT        = 1024;
+
+{ Maximum queue length specifiable by listen. }
+        SOMAXCONN = $7fffffff;
+
+{ WinSock 2 extension -- bit values and indices for FD_XXX network events }
+        FD_READ_BIT = 0;
+        FD_READ = (1  shl  FD_READ_BIT);
+        FD_WRITE_BIT = 1;
+        FD_WRITE = (1  shl  FD_WRITE_BIT);
+        FD_OOB_BIT = 2;
+        FD_OOB = (1  shl  FD_OOB_BIT);
+        FD_ACCEPT_BIT = 3;
+        FD_ACCEPT = (1  shl  FD_ACCEPT_BIT);
+        FD_CONNECT_BIT = 4;
+        FD_CONNECT = (1  shl  FD_CONNECT_BIT);
+        FD_CLOSE_BIT = 5;
+        FD_CLOSE = (1  shl  FD_CLOSE_BIT);
+        FD_QOS_BIT = 6;
+        FD_QOS = (1  shl  FD_QOS_BIT);
+        FD_GROUP_QOS_BIT = 7;
+        FD_GROUP_QOS = (1  shl  FD_GROUP_QOS_BIT);
+        FD_MAX_EVENTS = 8;
+        FD_ALL_EVENTS = ((1  shl  FD_MAX_EVENTS) - 1);
+
+{ All Windows Sockets error constants are biased by WSABASEERR from the "normal" }
+
+  WSABASEERR              = 10000;
+
+{ Windows Sockets definitions of regular Microsoft C error constants }
+
+  WSAEINTR                = (WSABASEERR+4);
+  WSAEBADF                = (WSABASEERR+9);
+  WSAEACCES               = (WSABASEERR+13);
+  WSAEFAULT               = (WSABASEERR+14);
+  WSAEINVAL               = (WSABASEERR+22);
+  WSAEMFILE               = (WSABASEERR+24);
+
+{ Windows Sockets definitions of regular Berkeley error constants }
+
+  WSAEWOULDBLOCK          = (WSABASEERR+35);
+  WSAEINPROGRESS          = (WSABASEERR+36);
+  WSAEALREADY             = (WSABASEERR+37);
+  WSAENOTSOCK             = (WSABASEERR+38);
+  WSAEDESTADDRREQ         = (WSABASEERR+39);
+  WSAEMSGSIZE             = (WSABASEERR+40);
+  WSAEPROTOTYPE           = (WSABASEERR+41);
+  WSAENOPROTOOPT          = (WSABASEERR+42);
+  WSAEPROTONOSUPPORT      = (WSABASEERR+43);
+  WSAESOCKTNOSUPPORT      = (WSABASEERR+44);
+  WSAEOPNOTSUPP           = (WSABASEERR+45);
+  WSAEPFNOSUPPORT         = (WSABASEERR+46);
+  WSAEAFNOSUPPORT         = (WSABASEERR+47);
+  WSAEADDRINUSE           = (WSABASEERR+48);
+  WSAEADDRNOTAVAIL        = (WSABASEERR+49);
+  WSAENETDOWN             = (WSABASEERR+50);
+  WSAENETUNREACH          = (WSABASEERR+51);
+  WSAENETRESET            = (WSABASEERR+52);
+  WSAECONNABORTED         = (WSABASEERR+53);
+  WSAECONNRESET           = (WSABASEERR+54);
+  WSAENOBUFS              = (WSABASEERR+55);
+  WSAEISCONN              = (WSABASEERR+56);
+  WSAENOTCONN             = (WSABASEERR+57);
+  WSAESHUTDOWN            = (WSABASEERR+58);
+  WSAETOOMANYREFS         = (WSABASEERR+59);
+  WSAETIMEDOUT            = (WSABASEERR+60);
+  WSAECONNREFUSED         = (WSABASEERR+61);
+  WSAELOOP                = (WSABASEERR+62);
+  WSAENAMETOOLONG         = (WSABASEERR+63);
+  WSAEHOSTDOWN            = (WSABASEERR+64);
+  WSAEHOSTUNREACH         = (WSABASEERR+65);
+  WSAENOTEMPTY            = (WSABASEERR+66);
+  WSAEPROCLIM             = (WSABASEERR+67);
+  WSAEUSERS               = (WSABASEERR+68);
+  WSAEDQUOT               = (WSABASEERR+69);
+  WSAESTALE               = (WSABASEERR+70);
+  WSAEREMOTE              = (WSABASEERR+71);
+
+{ Extended Windows Sockets error constant definitions }
+
+  WSASYSNOTREADY          = (WSABASEERR+91);
+  WSAVERNOTSUPPORTED      = (WSABASEERR+92);
+  WSANOTINITIALISED       = (WSABASEERR+93);
+        WSAEDISCON = (WSABASEERR+101);
+        WSAENOMORE = (WSABASEERR+102);
+        WSAECANCELLED = (WSABASEERR+103);
+        WSAEINVALIDPROCTABLE = (WSABASEERR+104);
+        WSAEINVALIDPROVIDER = (WSABASEERR+105);
+        WSAEPROVIDERFAILEDINIT = (WSABASEERR+106);
+        WSASYSCALLFAILURE = (WSABASEERR+107);
+        WSASERVICE_NOT_FOUND = (WSABASEERR+108);
+        WSATYPE_NOT_FOUND = (WSABASEERR+109);
+        WSA_E_NO_MORE = (WSABASEERR+110);
+        WSA_E_CANCELLED = (WSABASEERR+111);
+        WSAEREFUSED = (WSABASEERR+112);
+
+
+{ Error return codes from gethostbyname() and gethostbyaddr()
+  (when using the resolver). Note that these errors are
+  retrieved via WSAGetLastError() and must therefore follow
+  the rules for avoiding clashes with error numbers from
+  specific implementations or language run-time systems.
+  For this reason the codes are based at WSABASEERR+1001.
+  Note also that [WSA]NO_ADDRESS is defined only for
+  compatibility purposes. }
+
+{ Authoritative Answer: Host not found }
+  WSAHOST_NOT_FOUND       = (WSABASEERR+1001);
+  HOST_NOT_FOUND          = WSAHOST_NOT_FOUND;
+
+{ Non-Authoritative: Host not found, or SERVERFAIL }
+  WSATRY_AGAIN            = (WSABASEERR+1002);
+  TRY_AGAIN               = WSATRY_AGAIN;
+
+{ Non recoverable errors, FORMERR, REFUSED, NOTIMP }
+  WSANO_RECOVERY          = (WSABASEERR+1003);
+  NO_RECOVERY             = WSANO_RECOVERY;
+
+{ Valid name, no data record of requested type }
+  WSANO_DATA              = (WSABASEERR+1004);
+  NO_DATA                 = WSANO_DATA;
+
+{ no address, look for MX record }
+  WSANO_ADDRESS           = WSANO_DATA;
+  NO_ADDRESS              = WSANO_ADDRESS;
+
+{ WinSock 2 extension -- new error codes and type definition }
+        WSA_IO_PENDING = ERROR_IO_PENDING;
+        WSA_IO_INCOMPLETE = ERROR_IO_INCOMPLETE;
+        WSA_INVALID_HANDLE = ERROR_INVALID_HANDLE;
+        WSA_INVALID_PARAMETER = ERROR_INVALID_PARAMETER;
+        WSA_NOT_ENOUGH_MEMORY = ERROR_NOT_ENOUGH_MEMORY;
+        WSA_OPERATION_ABORTED = ERROR_OPERATION_ABORTED;
+{$ifndef FPC}{TODO}
+        WSA_INVALID_EVENT = WSAEVENT(nil);
+{$endif}
+        WSA_MAXIMUM_WAIT_EVENTS = MAXIMUM_WAIT_OBJECTS;
+        WSA_WAIT_FAILED = $ffffffff;
+        WSA_WAIT_EVENT_0 = WAIT_OBJECT_0;
+        WSA_WAIT_IO_COMPLETION = WAIT_IO_COMPLETION;
+        WSA_WAIT_TIMEOUT = WAIT_TIMEOUT;
+        WSA_INFINITE = INFINITE;
+
+{ Windows Sockets errors redefined as regular Berkeley error constants.
+  These are commented out in Windows NT to avoid conflicts with errno.h.
+  Use the WSA constants instead. }
+
+  EWOULDBLOCK        =  WSAEWOULDBLOCK;
+  EINPROGRESS        =  WSAEINPROGRESS;
+  EALREADY           =  WSAEALREADY;
+  ENOTSOCK           =  WSAENOTSOCK;
+  EDESTADDRREQ       =  WSAEDESTADDRREQ;
+  EMSGSIZE           =  WSAEMSGSIZE;
+  EPROTOTYPE         =  WSAEPROTOTYPE;
+  ENOPROTOOPT        =  WSAENOPROTOOPT;
+  EPROTONOSUPPORT    =  WSAEPROTONOSUPPORT;
+  ESOCKTNOSUPPORT    =  WSAESOCKTNOSUPPORT;
+  EOPNOTSUPP         =  WSAEOPNOTSUPP;
+  EPFNOSUPPORT       =  WSAEPFNOSUPPORT;
+  EAFNOSUPPORT       =  WSAEAFNOSUPPORT;
+  EADDRINUSE         =  WSAEADDRINUSE;
+  EADDRNOTAVAIL      =  WSAEADDRNOTAVAIL;
+  ENETDOWN           =  WSAENETDOWN;
+  ENETUNREACH        =  WSAENETUNREACH;
+  ENETRESET          =  WSAENETRESET;
+  ECONNABORTED       =  WSAECONNABORTED;
+  ECONNRESET         =  WSAECONNRESET;
+  ENOBUFS            =  WSAENOBUFS;
+  EISCONN            =  WSAEISCONN;
+  ENOTCONN           =  WSAENOTCONN;
+  ESHUTDOWN          =  WSAESHUTDOWN;
+  ETOOMANYREFS       =  WSAETOOMANYREFS;
+  ETIMEDOUT          =  WSAETIMEDOUT;
+  ECONNREFUSED       =  WSAECONNREFUSED;
+  ELOOP              =  WSAELOOP;
+  ENAMETOOLONG       =  WSAENAMETOOLONG;
+  EHOSTDOWN          =  WSAEHOSTDOWN;
+  EHOSTUNREACH       =  WSAEHOSTUNREACH;
+  ENOTEMPTY          =  WSAENOTEMPTY;
+  EPROCLIM           =  WSAEPROCLIM;
+  EUSERS             =  WSAEUSERS;
+  EDQUOT             =  WSAEDQUOT;
+  ESTALE             =  WSAESTALE;
+  EREMOTE            =  WSAEREMOTE;
+
+
+  WSADESCRIPTION_LEN     =   256;
+  WSASYS_STATUS_LEN      =   128;
+        MAX_PROTOCOL_CHAIN = 7;
+        BASE_PROTOCOL = 1;
+        LAYERED_PROTOCOL = 0;
+        WSAPROTOCOL_LEN = 255;
+
+type
+  PWSAData = ^TWSAData;
+  TWSAData = packed record
+    wVersion: Word;
+    wHighVersion: Word;
+    szDescription: array[0..WSADESCRIPTION_LEN] of Char;
+    szSystemStatus: array[0..WSASYS_STATUS_LEN] of Char;
+    iMaxSockets: Word;
+    iMaxUdpDg: Word;
+    lpVendorInfo: PChar;
+  end;
+
+{       WSAOVERLAPPED = Record
+                Internal: LongInt;
+                InternalHigh: LongInt;
+                Offset: LongInt;
+                OffsetHigh: LongInt;
+                hEvent: WSAEVENT;
+        end;}
+        WSAOVERLAPPED = TOverlapped;
+        TWSAOverlapped = WSAOverlapped;
+        PWSAOverlapped = ^WSAOverlapped;
+        LPWSAOVERLAPPED = PWSAOverlapped;
+
+{       WinSock 2 extension -- WSABUF and QOS struct, include qos.h }
+{ to pull in FLOWSPEC and related definitions }
+
+
+        WSABUF = record
+                len: U_LONG;    { the length of the buffer }
+                buf: PChar;     { the pointer to the buffer }
+        end {WSABUF};
+        PWSABUF = ^WSABUF;
+        LPWSABUF = PWSABUF;
+
+        TServiceType = LongInt;
+
+        TFlowSpec = Record
+                TokenRate,               // In Bytes/sec
+                TokenBucketSize,         // In Bytes
+                PeakBandwidth,           // In Bytes/sec
+                Latency,                 // In microseconds
+                DelayVariation : LongInt;// In microseconds
+                ServiceType : TServiceType;
+                MaxSduSize,     MinimumPolicedSize : LongInt;// In Bytes
+        end;
+        PFlowSpec = ^TFLOWSPEC;
+
+        TQualityOfService = record
+                SendingFlowspec: TFlowSpec;     { the flow spec for data sending }
+                ReceivingFlowspec: TFlowSpec;   { the flow spec for data receiving }
+                ProviderSpecific: WSABUF; { additional provider specific stuff }
+        end {TQualityOfService};
+        PQOS = ^TQualityOfService;
+        LPQOS = PQOS;
+
+Const
+        SERVICETYPE_NOTRAFFIC             =  $00000000;  // No data in this direction
+        SERVICETYPE_BESTEFFORT            =  $00000001;  // Best Effort
+        SERVICETYPE_CONTROLLEDLOAD        =  $00000002;  // Controlled Load
+        SERVICETYPE_GUARANTEED            =  $00000003;  // Guaranteed
+        SERVICETYPE_NETWORK_UNAVAILABLE   =  $00000004;  // Used to notify change to user
+        SERVICETYPE_GENERAL_INFORMATION   =  $00000005;  // corresponds to "General Parameters" defined by IntServ
+        SERVICETYPE_NOCHANGE              =  $00000006;  // used to indicate that the flow spec contains no change from any previous one
+// to turn on immediate traffic control, OR this flag with the ServiceType field in teh FLOWSPEC
+        SERVICE_IMMEDIATE_TRAFFIC_CONTROL =  $80000000;
+
+{       WinSock 2 extension -- manifest constants for return values of the condition function }
+        CF_ACCEPT = $0000;
+        CF_REJECT = $0001;
+        CF_DEFER = $0002;
+
+{       WinSock 2 extension -- manifest constants for shutdown() }
+        SD_RECEIVE = $00;
+        SD_SEND = $01;
+        SD_BOTH = $02;
+
+{       WinSock 2 extension -- data type and manifest constants for socket groups }
+        SG_UNCONSTRAINED_GROUP = $01;
+        SG_CONSTRAINED_GROUP = $02;
+Type
+        GROUP = Word;
+
+{       WinSock 2 extension -- data type for WSAEnumNetworkEvents() }
+        TWSANetworkEvents = record
+                lNetworkEvents: LongInt;
+                iErrorCode: Array[0..FD_MAX_EVENTS-1] of Longint;
+        end {TWSANetworkEvents};
+        PWSANetworkEvents = ^TWSANetworkEvents;
+        LPWSANetworkEvents = PWSANetworkEvents;
+
+        TWSAProtocolChain = record
+                ChainLen: Longint;      // the length of the chain,
+                // length = 0 means layered protocol,
+                // length = 1 means base protocol,
+                // length > 1 means protocol chain
+                ChainEntries: Array[0..MAX_PROTOCOL_CHAIN-1] of LongInt; { a list of dwCatalogEntryIds }
+        end {TWSAPROTOCOLCHAIN};
+
+Type
+        TWSAProtocol_InfoA = record
+                dwServiceFlags1: LongInt;
+                dwServiceFlags2: LongInt;
+                dwServiceFlags3: LongInt;
+                dwServiceFlags4: LongInt;
+                dwProviderFlags: LongInt;
+                ProviderId: TGUID;
+                dwCatalogEntryId: LongInt;
+                ProtocolChain: TWSAProtocolChain;
+                iVersion: Longint;
+                iAddressFamily: Longint;
+                iMaxSockAddr: Longint;
+                iMinSockAddr: Longint;
+                iSocketType: Longint;
+                iProtocol: Longint;
+                iProtocolMaxOffset: Longint;
+                iNetworkByteOrder: Longint;
+                iSecurityScheme: Longint;
+                dwMessageSize: LongInt;
+                dwProviderReserved: LongInt;
+                szProtocol: Array[0..WSAPROTOCOL_LEN+1-1] of Char;
+        end {TWSAProtocol_InfoA};
+        PWSAProtocol_InfoA = ^TWSAProtocol_InfoA;
+        LPWSAProtocol_InfoA = PWSAProtocol_InfoA;
+
+        TWSAProtocol_InfoW = record
+                dwServiceFlags1: LongInt;
+                dwServiceFlags2: LongInt;
+                dwServiceFlags3: LongInt;
+                dwServiceFlags4: LongInt;
+                dwProviderFlags: LongInt;
+                ProviderId: TGUID;
+                dwCatalogEntryId: LongInt;
+                ProtocolChain: TWSAProtocolChain;
+                iVersion: Longint;
+                iAddressFamily: Longint;
+                iMaxSockAddr: Longint;
+                iMinSockAddr: Longint;
+                iSocketType: Longint;
+                iProtocol: Longint;
+                iProtocolMaxOffset: Longint;
+                iNetworkByteOrder: Longint;
+                iSecurityScheme: Longint;
+                dwMessageSize: LongInt;
+                dwProviderReserved: LongInt;
+                szProtocol: Array[0..(WSAPROTOCOL_LEN+1-1)] of WideChar;
+        end {TWSAProtocol_InfoW};
+        PWSAProtocol_InfoW = ^TWSAProtocol_InfoW;
+        LPWSAProtocol_InfoW = PWSAProtocol_InfoW;
+
+{$IFDEF UNICODE}
+        TWSAProtocol_Info = TWSAProtocol_InfoW;
+        LPWSAProtocol_Info = PWSAProtocol_InfoW;
+{$ELSE}
+        TWSAProtocol_Info = TWSAProtocol_InfoA;
+        LPWSAProtocol_Info = PWSAProtocol_InfoA;
+{$ENDIF}
+
+{       Flag bit definitions for dwProviderFlags */ }
+Const
+        PFL_MULTIPLE_PROTO_ENTRIES = $00000001;
+        PFL_RECOMMENDED_PROTO_ENTRY = $00000002;
+        PFL_HIDDEN = $00000004;
+        PFL_MATCHES_PROTOCOL_ZERO = $00000008;
+
+{       Flag bit definitions for dwServiceFlags1 */ }
+        XP1_CONNECTIONLESS = $00000001;
+        XP1_GUARANTEED_DELIVERY = $00000002;
+        XP1_GUARANTEED_ORDER = $00000004;
+        XP1_MESSAGE_ORIENTED = $00000008;
+        XP1_PSEUDO_STREAM = $00000010;
+        XP1_GRACEFUL_CLOSE = $00000020;
+        XP1_EXPEDITED_DATA = $00000040;
+        XP1_CONNECT_DATA = $00000080;
+        XP1_DISCONNECT_DATA = $00000100;
+        XP1_SUPPORT_BROADCAST = $00000200;
+        XP1_SUPPORT_MULTIPOINT = $00000400;
+        XP1_MULTIPOINT_CONTROL_PLANE = $00000800;
+        XP1_MULTIPOINT_DATA_PLANE = $00001000;
+        XP1_QOS_SUPPORTED = $00002000;
+        XP1_INTERRUPT = $00004000;
+        XP1_UNI_SEND = $00008000;
+        XP1_UNI_RECV = $00010000;
+        XP1_IFS_HANDLES = $00020000;
+        XP1_PARTIAL_MESSAGE = $00040000;
+
+        BIGENDIAN = $0000;
+        LITTLEENDIAN = $0001;
+
+        SECURITY_PROTOCOL_NONE = $0000;
+
+{       WinSock 2 extension -- manifest constants for WSAJoinLeaf() }
+        JL_SENDER_ONLY = $01;
+        JL_RECEIVER_ONLY = $02;
+        JL_BOTH = $04;
+
+{ WinSock 2 extension -- manifest constants for WSASocket() }
+        WSA_FLAG_OVERLAPPED = $01;
+        WSA_FLAG_MULTIPOINT_C_ROOT = $02;
+        WSA_FLAG_MULTIPOINT_C_LEAF = $04;
+        WSA_FLAG_MULTIPOINT_D_ROOT = $08;
+        WSA_FLAG_MULTIPOINT_D_LEAF = $10;
+
+{ WinSock 2 extension -- manifest constants for WSAIoctl() }
+        IOC_UNIX = $00000000;
+        IOC_WS2 = $08000000;
+        IOC_PROTOCOL = $10000000;
+        IOC_VENDOR = $18000000;
+
+        SIO_ASSOCIATE_HANDLE = IOC_IN or IOC_WS2 or 1;
+        SIO_ENABLE_CIRCULAR_QUEUEING = IOC_WS2 or 2;
+        SIO_FIND_ROUTE = IOC_OUT or IOC_WS2 or 3;
+        SIO_FLUSH = IOC_WS2 or 4;
+        SIO_GET_BROADCAST_ADDRESS = IOC_OUT or IOC_WS2 or 5;
+        SIO_GET_EXTENSION_FUNCTION_POINTER = IOC_INOUT or IOC_WS2 or 6;
+        SIO_GET_QOS = IOC_INOUT or IOC_WS2 or 7;
+        SIO_GET_GROUP_QOS = IOC_INOUT or IOC_WS2 or 8;
+        SIO_MULTIPOINT_LOOPBACK = IOC_IN or IOC_WS2 or 9;
+        SIO_MULTICAST_SCOPE = IOC_IN or IOC_WS2 or 10;
+        SIO_SET_QOS = IOC_IN or IOC_WS2 or 11;
+        SIO_SET_GROUP_QOS = IOC_IN or IOC_WS2 or 12;
+        SIO_TRANSLATE_HANDLE = IOC_INOUT or IOC_WS2 or 13;
+
+{WinSock 2 extension -- manifest constants for SIO_TRANSLATE_HANDLE ioctl }
+        TH_NETDEV = $00000001;
+        TH_TAPI = $00000002;
+
+Const
+        SERVICE_MULTIPLE = $00000001;
+
+{ & Name Spaces }
+        NS_ALL = (0);
+
+        NS_SAP = (1);
+        NS_NDS = (2);
+        NS_PEER_BROWSE = (3);
+
+        NS_TCPIP_LOCAL = (10);
+        NS_TCPIP_HOSTS = (11);
+        NS_DNS = (12);
+        NS_NETBT = (13);
+        NS_WINS = (14);
+
+        NS_NBP = (20);
+
+        NS_MS = (30);
+        NS_STDA = (31);
+        NS_NTDS = (32);
+
+        NS_X500 = (40);
+        NS_NIS = (41);
+        NS_NISPLUS = (42);
+
+        NS_WRQ = (50);
+
+{       Resolution flags for WSAGetAddressByName().
+        Note these are also used by the 1.1 API GetAddressByName, so leave them around. }
+        RES_UNUSED_1 = $00000001;
+        RES_FLUSH_CACHE = $00000002;
+        RES_SERVICE = $00000004;
+
+{       Well known value names for Service Types }
+        SERVICE_TYPE_VALUE_IPXPORTA = 'IpxSocket';
+{$ifndef FPC}{TODO}
+        SERVICE_TYPE_VALUE_IPXPORTW : PWideChar = 'IpxSocket';
+        SERVICE_TYPE_VALUE_SAPIDA = 'SapId';
+        SERVICE_TYPE_VALUE_SAPIDW : PWideChar = 'SapId';
+
+        SERVICE_TYPE_VALUE_TCPPORTA = 'TcpPort';
+        SERVICE_TYPE_VALUE_TCPPORTW : PWideChar = 'TcpPort';
+
+        SERVICE_TYPE_VALUE_UDPPORTA = 'UdpPort';
+        SERVICE_TYPE_VALUE_UDPPORTW : PWideChar = 'UdpPort';
+
+        SERVICE_TYPE_VALUE_OBJECTIDA = 'ObjectId';
+        SERVICE_TYPE_VALUE_OBJECTIDW : PWideChar = 'ObjectId';
+
+{$IFDEF UNICODE}
+        SERVICE_TYPE_VALUE_SAPID = SERVICE_TYPE_VALUE_SAPIDW;
+        SERVICE_TYPE_VALUE_TCPPORT = SERVICE_TYPE_VALUE_TCPPORTW;
+        SERVICE_TYPE_VALUE_UDPPORT = SERVICE_TYPE_VALUE_UDPPORTW;
+        SERVICE_TYPE_VALUE_OBJECTID = SERVICE_TYPE_VALUE_OBJECTIDW;
+{$ELSE}
+        SERVICE_TYPE_VALUE_SAPID = SERVICE_TYPE_VALUE_SAPIDA;
+        SERVICE_TYPE_VALUE_TCPPORT = SERVICE_TYPE_VALUE_TCPPORTA;
+        SERVICE_TYPE_VALUE_UDPPORT = SERVICE_TYPE_VALUE_UDPPORTA;
+        SERVICE_TYPE_VALUE_OBJECTID = SERVICE_TYPE_VALUE_OBJECTIDA;
+{$ENDIF}
+
+{$endif}{FPC}
+
+{ SockAddr Information }
+
+
+Type
+        SOCKET_ADDRESS = record
+                lpSockaddr : PSockAddr;
+                iSockaddrLength : Longint;
+        end {SOCKET_ADDRESS};
+        PSOCKET_ADDRESS = ^SOCKET_ADDRESS;
+
+{ CSAddr Information }
+        CSADDR_INFO = record
+                LocalAddr, RemoteAddr: SOCKET_ADDRESS;
+                iSocketType, iProtocol : LongInt;
+        end {CSADDR_INFO};
+        PCSADDR_INFO = ^CSADDR_INFO;
+
+{       Address Family/Protocol Tuples }
+        TAFProtocols = record
+                iAddressFamily: Longint;
+                iProtocol: Longint;
+        end {AFPROTOCOLS};
+        PAFProtocols = TAFProtocols;
+
+{       Client Query API Typedefs }
+
+{ The comparators }
+        TWSAEComparator = (COMP_EQUAL {= 0}, COMP_NOTLESS );
+
+        TWSAVersion = record
+                dwVersion: LongInt;
+                ecHow: TWSAEComparator;
+        end {TWSAVersion};
+        PWSAVersion = ^TWSAVersion;
+
+        TWSAQuerySetA = record
+                dwSize: LongInt;
+                lpszServiceInstanceName: PChar;
+                lpServiceClassId: PGUID;
+                lpVersion: PWSAVERSION;
+                lpszComment: PChar;
+                dwNameSpace: LongInt;
+                lpNSProviderId: PGUID;
+                lpszContext: PChar;
+                dwNumberOfProtocols: LongInt;
+                lpafpProtocols: PAFProtocols;
+                lpszQueryString: PChar;
+                dwNumberOfCsAddrs: LongInt;
+                lpcsaBuffer: PCSADDR_INFO;
+                dwOutputFlags: LongInt;
+                lpBlob: PBLOB;
+        end {TWSAQuerySetA};
+        PWSAQuerySetA = ^TWSAQuerySetA;
+        LPWSAQuerySetA = PWSAQuerySetA;
+        TWSAQuerySetW = record
+                dwSize: LongInt;
+                lpszServiceInstanceName: PWideChar;
+                lpServiceClassId: PGUID;
+                lpVersion: PWSAVERSION;
+                lpszComment: PWideChar;
+                dwNameSpace: LongInt;
+                lpNSProviderId: PGUID;
+                lpszContext: PWideChar;
+                dwNumberOfProtocols: LongInt;
+                lpafpProtocols: PAFProtocols;
+                lpszQueryString: PWideChar;
+                dwNumberOfCsAddrs: LongInt;
+                lpcsaBuffer: PCSADDR_INFO;
+                dwOutputFlags: LongInt;
+                lpBlob: PBLOB;
+        end {TWSAQuerySetW};
+        PWSAQuerySetW = ^TWSAQuerySetW;
+        LPWSAQuerySetW = PWSAQuerySetW;
+{$IFDEF UNICODE}
+        PWSAQuerySet = PWSAQuerySetW;
+        LPWSAQuerySet = PWSAQuerySetW;
+{$ELSE}
+        PWSAQuerySet = PWSAQuerySetA;
+        LPWSAQuerySet = PWSAQuerySetA;
+{$ENDIF}
+
+Const
+        LUP_DEEP = $0001;
+        LUP_CONTAINERS = $0002;
+        LUP_NOCONTAINERS = $0004;
+        LUP_NEAREST = $0008;
+        LUP_RETURN_NAME = $0010;
+        LUP_RETURN_TYPE = $0020;
+        LUP_RETURN_VERSION = $0040;
+        LUP_RETURN_COMMENT = $0080;
+        LUP_RETURN_ADDR = $0100;
+        LUP_RETURN_BLOB = $0200;
+        LUP_RETURN_ALIASES = $0400;
+        LUP_RETURN_QUERY_STRING = $0800;
+        LUP_RETURN_ALL = $0FF0;
+        LUP_RES_SERVICE = $8000;
+
+        LUP_FLUSHCACHE = $1000;
+        LUP_FLUSHPREVIOUS = $2000;
+
+
+{       Return flags }
+        RESULT_IS_ALIAS = $0001;
+
+Type
+{ Service Address Registration and Deregistration Data Types. }
+        TWSAeSetServiceOp = (RNRSERVICE_REGISTER{=0},RNRSERVICE_DEREGISTER,RNRSERVICE_DELETE);
+
+{       Service Installation/Removal Data Types. }
+        TWSANSClassInfoA = record
+                lpszName: PChar;
+                dwNameSpace: LongInt;
+                dwValueType: LongInt;
+                dwValueSize: LongInt;
+                lpValue: Pointer;
+        end {_WSANSClassInfoA};
+        PWSANSClassInfoA = ^TWSANSClassInfoA;
+        TWSANSClassInfoW = record
+                lpszName: PWideChar;
+                dwNameSpace: LongInt;
+                dwValueType: LongInt;
+                dwValueSize: LongInt;
+                lpValue: Pointer;
+        end {TWSANSClassInfoW};
+        PWSANSClassInfoW = ^TWSANSClassInfoW;
+{$IFDEF UNICODE}
+        TWSANSClassInfo = TWSANSClassInfoW;
+        PWSANSClassInfo = PWSANSClassInfoW;
+        LPWSANSClassInfo = PWSANSClassInfoW;
+{$ELSE}
+        TWSANSClassInfo = TWSANSClassInfoA;
+        PWSANSClassInfo = PWSANSClassInfoA;
+        LPWSANSClassInfo = PWSANSClassInfoA;
+{$ENDIF // UNICODE}
+
+        TWSAServiceClassInfoA = record
+                lpServiceClassId: PGUID;
+                lpszServiceClassName: PChar;
+                dwCount: LongInt;
+                lpClassInfos: PWSANSClassInfoA;
+        end {TWSAServiceClassInfoA};
+        PWSAServiceClassInfoA = ^TWSAServiceClassInfoA;
+        LPWSAServiceClassInfoA = PWSAServiceClassInfoA;
+        TWSAServiceClassInfoW = record
+                lpServiceClassId: PGUID;
+                lpszServiceClassName: PWideChar;
+                dwCount: LongInt;
+                lpClassInfos: PWSANSClassInfoW;
+        end {TWSAServiceClassInfoW};
+        PWSAServiceClassInfoW = ^TWSAServiceClassInfoW;
+        LPWSAServiceClassInfoW = PWSAServiceClassInfoW;
+{$IFDEF UNICODE}
+        TWSAServiceClassInfo = TWSAServiceClassInfoW;
+        PWSAServiceClassInfo = PWSAServiceClassInfoW;
+        LPWSAServiceClassInfo = PWSAServiceClassInfoW;
+{$ELSE}
+        TWSAServiceClassInfo = TWSAServiceClassInfoA;
+        PWSAServiceClassInfo = PWSAServiceClassInfoA;
+        LPWSAServiceClassInfo = PWSAServiceClassInfoA;
+{$ENDIF}
+
+        TWSANameSpace_InfoA = record
+                NSProviderId: TGUID;
+                dwNameSpace: LongInt;
+                fActive: LongInt{Bool};
+                dwVersion: LongInt;
+                lpszIdentifier: PChar;
+        end {TWSANameSpace_InfoA};
+        PWSANameSpace_InfoA = ^TWSANameSpace_InfoA;
+        LPWSANameSpace_InfoA = PWSANameSpace_InfoA;
+        TWSANameSpace_InfoW = record
+                NSProviderId: TGUID;
+                dwNameSpace: LongInt;
+                fActive: LongInt{Bool};
+                dwVersion: LongInt;
+                lpszIdentifier: PWideChar;
+        end {TWSANameSpace_InfoW};
+        PWSANameSpace_InfoW = ^TWSANameSpace_InfoW;
+        LPWSANameSpace_InfoW = PWSANameSpace_InfoW;
+{$IFDEF UNICODE}
+        TWSANameSpace_Info = TWSANameSpace_InfoW;
+        PWSANameSpace_Info = PWSANameSpace_InfoW;
+        LPWSANameSpace_Info = PWSANameSpace_InfoW;
+{$ELSE}
+        TWSANameSpace_Info = TWSANameSpace_InfoA;
+        PWSANameSpace_Info = PWSANameSpace_InfoA;
+        LPWSANameSpace_Info = PWSANameSpace_InfoA;
+{$ENDIF}
+
+{       WinSock 2 extensions -- data types for the condition function in }
+{ WSAAccept() and overlapped I/O completion routine. }
+Type
+        LPCONDITIONPROC = function (lpCallerId: LPWSABUF; lpCallerData : LPWSABUF; lpSQOS,lpGQOS : LPQOS; lpCalleeId,lpCalleeData : LPWSABUF;
+                g : GROUP; dwCallbackData : DWORD ) : Longint; stdcall;
+        LPWSAOVERLAPPED_COMPLETION_ROUTINE = procedure ( const dwError, cbTransferred : DWORD; const lpOverlapped : LPWSAOVERLAPPED; const dwFlags : DWORD ); stdcall;
+
+function accept( const s: TSocket; addr: PSockAddr; addrlen: PLongint ): TSocket; stdcall;external WINSOCK2_DLL name 'accept';
+function accept( const s: TSocket; addr: PSockAddr; var addrlen: Longint ): TSocket; stdcall;external WINSOCK2_DLL name 'accept';
+function bind( const s: TSocket; addr: PSockAddr; const namelen: Longint ): Longint; stdcall;external WINSOCK2_DLL name 'bind';
+function bind( const s: TSocket; const addr: TSockAddr; namelen: Longint ): Longint; stdcall;external WINSOCK2_DLL name 'bind';
+function closesocket( const s: TSocket ): Longint; stdcall;external WINSOCK2_DLL name 'closesocket';
+function connect( const s: TSocket; name: PSockAddr; namelen: Longint): Longint; stdcall;external WINSOCK2_DLL name 'connect';
+function connect( const s: TSocket; const name: TSockAddr; namelen: Longint): Longint; stdcall;external WINSOCK2_DLL name 'connect';
+function ioctlsocket( const s: TSocket; cmd: Longint; var arg: u_long ): Longint; stdcall;external WINSOCK2_DLL name 'ioctlsocket';
+function ioctlsocket( const s: TSocket; cmd: Longint; argp: pu_long ): Longint; stdcall;external WINSOCK2_DLL name 'ioctlsocket';
+function getpeername( const s: TSocket; var name: TSockAddr; var namelen: Longint ): Longint; stdcall;external WINSOCK2_DLL name 'getpeername';
+function getsockname( const s: TSocket; var name: TSockAddr; var namelen: Longint ): Longint; stdcall;external WINSOCK2_DLL name 'getsockname';
+function getsockopt( const s: TSocket; const level, optname: Longint; optval: PChar; var optlen: Longint ): Longint; stdcall;external WINSOCK2_DLL name 'getsockopt';
+function getsockopt( const s: TSocket; const level, optname: Longint; optval: Pointer; var optlen: Longint ): Longint; stdcall;external WINSOCK2_DLL name 'getsockopt';
+function getsockopt( const s: TSocket; const level, optname: Longint; var optval; var optlen: Longint ): Longint; stdcall;external WINSOCK2_DLL name 'getsockopt';
+function htonl(hostlong: u_long): u_long; stdcall;external WINSOCK2_DLL name 'htonl';
+function htons(hostshort: u_short): u_short; stdcall;external WINSOCK2_DLL name 'htons';
+function inet_addr(cp: PChar): u_long; stdcall;external WINSOCK2_DLL name 'inet_addr';
+function inet_ntoa(inaddr: TInAddr): PChar; stdcall;external WINSOCK2_DLL name 'inet_ntoa';
+function listen(s: TSocket; backlog: Longint): Longint; stdcall;external WINSOCK2_DLL name 'listen';
+function ntohl(netlong: u_long): u_long; stdcall;external WINSOCK2_DLL name 'ntohl';
+function ntohs(netshort: u_short): u_short; stdcall;external WINSOCK2_DLL name 'ntohs';
+function recv(s: TSocket; var Buf; len, flags: Longint): Longint; stdcall;external WINSOCK2_DLL name 'recv';
+function recv(s: TSocket; Buf: PChar; len, flags: Longint): Longint; stdcall;external WINSOCK2_DLL name 'recv';
+function recv(s: TSocket; Buf: Pointer; len, flags: Longint): Longint; stdcall;external WINSOCK2_DLL name 'recv';
+function recvfrom(s: TSocket; Buf: PChar; len, flags: Longint; from: PSockAddr; fromlen: PLongint): Longint; stdcall;external WINSOCK2_DLL name 'recvfrom';
+function recvfrom(s: TSocket; Buf: Pointer; len, flags: Longint; from: PSockAddr; fromlen: PLongint): Longint; stdcall;external WINSOCK2_DLL name 'recvfrom';
+function recvfrom(s: TSocket; var Buf; len, flags: Longint; const from: TSockAddr; var fromlen: Longint): Longint; stdcall;external WINSOCK2_DLL name 'recvfrom';
+function select(nfds: Longint; readfds, writefds, exceptfds: PFDSet; timeout: PTimeVal): Longint; stdcall;external WINSOCK2_DLL name 'select';
+function send(s: TSocket; const Buf; len, flags: Longint): Longint; stdcall;external WINSOCK2_DLL name 'send';
+function send(s: TSocket; Buf: PChar; len, flags: Longint): Longint; stdcall;external WINSOCK2_DLL name 'send';
+function send(s: TSocket; Buf: Pointer; len, flags: Longint): Longint; stdcall;external WINSOCK2_DLL name 'send';
+function sendto(s: TSocket; const Buf; len, flags: Longint; const addrto: TSockAddr; tolen: Longint): Longint; stdcall;external WINSOCK2_DLL name 'sendto';
+function sendto(s: TSocket; Buf: PChar; len, flags: Longint; addrto: PSockAddr; tolen: Longint): Longint; stdcall;external WINSOCK2_DLL name 'sendto';
+function sendto(s: TSocket; Buf: Pointer; len, flags: Longint; addrto: PSockAddr; tolen: Longint): Longint; stdcall;external WINSOCK2_DLL name 'sendto';
+function setsockopt(s: TSocket; level, optname: Longint; const optval; optlen: Longint): Longint; stdcall;external WINSOCK2_DLL name 'setsockopt';
+function setsockopt(s: TSocket; level, optname: Longint; optval: PChar; optlen: Longint): Longint; stdcall;external WINSOCK2_DLL name 'setsockopt';
+function setsockopt(s: TSocket; level, optname: Longint; optval: Pointer; optlen: Longint): Longint; stdcall;external WINSOCK2_DLL name 'setsockopt';
+function shutdown(s: TSocket; how: Longint): Longint; stdcall;external WINSOCK2_DLL name 'shutdown';
+function socket(af, struct, protocol: Longint): TSocket; stdcall;external WINSOCK2_DLL name 'socket';
+
+function gethostbyaddr(addr: Pointer; len, struct: Longint): PHostEnt; stdcall;external WINSOCK2_DLL name 'gethostbyaddr';
+function gethostbyname(name: PChar): PHostEnt; stdcall;external WINSOCK2_DLL name 'gethostbyname';
+function gethostname(name: PChar; len: Longint): Longint; stdcall;external WINSOCK2_DLL name 'gethostname';
+function getservbyport(port: Longint; proto: PChar): PServEnt; stdcall;external WINSOCK2_DLL name 'getservbyport';
+function getservbyname(name, proto: PChar): PServEnt; stdcall;external WINSOCK2_DLL name 'getservbyname';
+function getprotobynumber(proto: Longint): PProtoEnt; stdcall;external WINSOCK2_DLL name 'getprotobynumber';
+function getprotobyname(name: PChar): PProtoEnt; stdcall;external WINSOCK2_DLL name 'getprotobyname';
+
+function WSAStartup(wVersionRequired: word; var WSData: TWSAData): Longint; stdcall; external WINSOCK2_DLL name 'WSAStartup';
+function WSACleanup: Longint; stdcall; external WINSOCK2_DLL name 'WSACleanup';
+procedure WSASetLastError(iError: Longint); stdcall; external WINSOCK2_DLL name 'WSASetLastError';
+function WSAGetLastError: Longint; stdcall; external WINSOCK2_DLL name 'WSAGetLastError';
+function WSAIsBlocking: BOOL; stdcall; external WINSOCK2_DLL name 'WSAIsBlocking';
+function WSAUnhookBlockingHook: Longint; stdcall; external WINSOCK2_DLL name 'WSAUnhookBlockingHook';
+function WSASetBlockingHook(lpBlockFunc: TFarProc): TFarProc; stdcall; external WINSOCK2_DLL name 'WSASetBlockingHook';
+function WSACancelBlockingCall: Longint; stdcall; external WINSOCK2_DLL name 'WSACancelBlockingCall';
+function WSAAsyncGetServByName(HWindow: HWND; wMsg: u_int; name, proto, buf: PChar; buflen: Longint): THandle; stdcall; external WINSOCK2_DLL name 'WSAAsyncGetServByName';
+function WSAAsyncGetServByPort( HWindow: HWND; wMsg, port: u_int; proto, buf: PChar; buflen: Longint): THandle; stdcall; external WINSOCK2_DLL name 'WSAAsyncGetServByPort';
+function WSAAsyncGetProtoByName(HWindow: HWND; wMsg: u_int; name, buf: PChar; buflen: Longint): THandle; stdcall; external WINSOCK2_DLL name 'WSAAsyncGetProtoByName';
+function WSAAsyncGetProtoByNumber(HWindow: HWND; wMsg: u_int; number: Longint; buf: PChar; buflen: Longint): THandle; stdcall; external WINSOCK2_DLL name 'WSAAsyncGetProtoByNumber';
+function WSAAsyncGetHostByName(HWindow: HWND; wMsg: u_int; name, buf: PChar; buflen: Longint): THandle; stdcall; external WINSOCK2_DLL name 'WSAAsyncGetHostByName';
+function WSAAsyncGetHostByAddr(HWindow: HWND; wMsg: u_int; addr: PChar; len, struct: Longint; buf: PChar; buflen: Longint): THandle; stdcall; external WINSOCK2_DLL name 'WSAAsyncGetHostByAddr';
+function WSACancelAsyncRequest(hAsyncTaskHandle: THandle): Longint; stdcall; external WINSOCK2_DLL name 'WSACancelAsyncRequest';
+function WSAAsyncSelect(s: TSocket; HWindow: HWND; wMsg: u_int; lEvent: Longint): Longint; stdcall; external WINSOCK2_DLL name 'WSAAsyncSelect';
+function __WSAFDIsSet(s: TSOcket; var FDSet: TFDSet): Bool; stdcall; external WINSOCK2_DLL name '__WSAFDIsSet';
+
+{       WinSock 2 API new function prototypes }
+function WSAAccept( s : TSocket; addr : TSockAddr; addrlen : PLongint; lpfnCondition : LPCONDITIONPROC; dwCallbackData : DWORD ): TSocket; stdcall; external WINSOCK2_DLL name 'WSAAccept';
+function WSACloseEvent( hEvent : WSAEVENT) : WordBool; stdcall; external WINSOCK2_DLL name 'WSACloseEvent';
+function WSAConnect( s : TSocket; const name : PSockAddr; namelen : Longint; lpCallerData,lpCalleeData : LPWSABUF; lpSQOS,lpGQOS : LPQOS ) : Longint; stdcall; external WINSOCK2_DLL name 'WSAConnect';
+function WSACreateEvent : WSAEVENT; stdcall; external WINSOCK2_DLL name 'WSACreateEvent';
+function WSADuplicateSocketA( s : TSocket; dwProcessId : DWORD; lpProtocolInfo : LPWSAProtocol_InfoA ) : Longint; stdcall; external WINSOCK2_DLL name 'WSADuplicateSocketA';
+function WSADuplicateSocketW( s : TSocket; dwProcessId : DWORD; lpProtocolInfo : LPWSAProtocol_InfoW ) : Longint; stdcall; external WINSOCK2_DLL name 'WSADuplicateSocketW';
+function WSADuplicateSocket( s : TSocket; dwProcessId : DWORD; lpProtocolInfo : LPWSAProtocol_Info ) : Longint; stdcall; external WINSOCK2_DLL name 'WSADuplicateSocket';
+function WSAEnumNetworkEvents( const s : TSocket; const hEventObject : WSAEVENT; lpNetworkEvents : LPWSANETWORKEVENTS ) :Longint; stdcall; external WINSOCK2_DLL name 'WSAEnumNetworkEvents';
+function WSAEnumProtocolsA( lpiProtocols : PLongint; lpProtocolBuffer : LPWSAProtocol_InfoA; var lpdwBufferLength : DWORD ) : Longint; stdcall; external WINSOCK2_DLL name 'WSAEnumProtocolsA';
+function WSAEnumProtocolsW( lpiProtocols : PLongint; lpProtocolBuffer : LPWSAProtocol_InfoW; var lpdwBufferLength : DWORD ) : Longint; stdcall; external WINSOCK2_DLL name 'WSAEnumProtocolsW';
+function WSAEnumProtocols( lpiProtocols : PLongint; lpProtocolBuffer : LPWSAProtocol_Info; var lpdwBufferLength : DWORD ) : Longint; stdcall; external WINSOCK2_DLL name 'WSAEnumProtocols';
+function WSAEventSelect( s : TSocket; hEventObject : WSAEVENT; lNetworkEvents : LongInt ): Longint; stdcall; external WINSOCK2_DLL name 'WSAEventSelect';
+function WSAGetOverlappedResult( s : TSocket; lpOverlapped : LPWSAOVERLAPPED; lpcbTransfer : LPDWORD; fWait : BOOL; var lpdwFlags : DWORD ) : WordBool; stdcall; external WINSOCK2_DLL name 'WSAGetOverlappedResult';
+function WSAGetQosByName( s : TSocket; lpQOSName : LPWSABUF; lpQOS : LPQOS ): WordBool; stdcall; external WINSOCK2_DLL name 'WSAGetQosByName';
+function WSAhtonl( s : TSocket; hostlong : u_long; var lpnetlong : DWORD ): Longint; stdcall; external WINSOCK2_DLL name 'WSAhtonl';
+function WSAhtons( s : TSocket; hostshort : u_short; var lpnetshort : WORD ): Longint; stdcall; external WINSOCK2_DLL name 'WSAhtons';
+function WSAIoctl( s : TSocket; dwIoControlCode : DWORD; lpvInBuffer : Pointer; cbInBuffer : DWORD; lpvOutBuffer : Pointer; cbOutBuffer : DWORD;
+        lpcbBytesReturned : LPDWORD; lpOverlapped : LPWSAOVERLAPPED; lpCompletionRoutine : LPWSAOVERLAPPED_COMPLETION_ROUTINE ) : Longint; stdcall; external WINSOCK2_DLL name 'WSAIoctl';
+function WSAJoinLeaf( s : TSocket; name : PSockAddr; namelen : Longint; lpCallerData,lpCalleeData : LPWSABUF;
+        lpSQOS,lpGQOS : LPQOS; dwFlags : DWORD ) : TSocket; stdcall; external WINSOCK2_DLL name 'WSAJoinLeaf';
+function WSANtohl( s : TSocket; netlong : u_long; var lphostlong : DWORD ): Longint; stdcall; external WINSOCK2_DLL name 'WSANtohl';
+function WSANtohs( s : TSocket; netshort : u_short; var lphostshort : WORD ): Longint; stdcall; external WINSOCK2_DLL name 'WSANtohs';
+function WSARecv( s : TSocket; lpBuffers : LPWSABUF; dwBufferCount : DWORD; var lpNumberOfBytesRecvd : DWORD; var lpFlags : DWORD;
+        lpOverlapped : LPWSAOVERLAPPED; lpCompletionRoutine : LPWSAOVERLAPPED_COMPLETION_ROUTINE ): Longint; stdcall; external WINSOCK2_DLL name 'WSARecv';
+function WSARecvDisconnect( s : TSocket; lpInboundDisconnectData : LPWSABUF ): Longint; stdcall; external WINSOCK2_DLL name 'WSARecvDisconnect';
+function WSARecvFrom( s : TSocket; lpBuffers : LPWSABUF; dwBufferCount : DWORD; var lpNumberOfBytesRecvd : DWORD; var lpFlags : DWORD;
+        lpFrom : PSockAddr; lpFromlen : PLongint; lpOverlapped : LPWSAOVERLAPPED; lpCompletionRoutine : LPWSAOVERLAPPED_COMPLETION_ROUTINE ): Longint; stdcall; external WINSOCK2_DLL name 'WSARecvFrom';
+function WSAResetEvent( hEvent : WSAEVENT ): WordBool; stdcall; external WINSOCK2_DLL name 'WSAResetEvent';
+function WSASend( s : TSocket; lpBuffers : LPWSABUF; dwBufferCount : DWORD; var lpNumberOfBytesSent : DWORD; dwFlags : DWORD;
+        lpOverlapped : LPWSAOVERLAPPED; lpCompletionRoutine : LPWSAOVERLAPPED_COMPLETION_ROUTINE ): Longint; stdcall; external WINSOCK2_DLL name 'WSASend';
+function WSASendDisconnect( s : TSocket; lpOutboundDisconnectData : LPWSABUF ): Longint; stdcall; external WINSOCK2_DLL name 'WSASendDisconnect';
+function WSASendTo( s : TSocket; lpBuffers : LPWSABUF; dwBufferCount : DWORD; var lpNumberOfBytesSent : DWORD; dwFlags : DWORD;
+        lpTo : PSockAddr; iTolen : Longint; lpOverlapped : LPWSAOVERLAPPED; lpCompletionRoutine : LPWSAOVERLAPPED_COMPLETION_ROUTINE ): Longint; stdcall; external WINSOCK2_DLL name 'WSASendTo';
+function WSASetEvent( hEvent : WSAEVENT ): WordBool; stdcall; external WINSOCK2_DLL name 'WSASetEvent';
+function WSASocketA( af, iType, protocol : Longint; lpProtocolInfo : LPWSAProtocol_InfoA; g : GROUP; dwFlags : DWORD ): TSocket; stdcall; external WINSOCK2_DLL name 'WSASocketA';
+function WSASocketW( af, iType, protocol : Longint; lpProtocolInfo : LPWSAProtocol_InfoW; g : GROUP; dwFlags : DWORD ): TSocket; stdcall; external WINSOCK2_DLL name 'WSASocketW';
+function WSASocket( af, iType, protocol : Longint; lpProtocolInfo : LPWSAProtocol_Info; g : GROUP; dwFlags : DWORD ): TSocket; stdcall; external WINSOCK2_DLL name 'WSASocket';
+function WSAWaitForMultipleEvents( cEvents : DWORD; lphEvents : PWSAEVENT; fWaitAll : LongBool;
+        dwTimeout : DWORD; fAlertable : LongBool ): DWORD; stdcall; external WINSOCK2_DLL name 'WSAWaitForMultipleEvents';
+function WSAAddressToStringA( var lpsaAddress : TSockAddr; const dwAddressLength : DWORD; const lpProtocolInfo : LPWSAProtocol_InfoA;
+        const lpszAddressString : PChar; var lpdwAddressStringLength : DWORD ): Longint; stdcall; external WINSOCK2_DLL name 'WSAAddressToStringA';
+function WSAAddressToStringW( var lpsaAddress : TSockAddr; const dwAddressLength : DWORD; const lpProtocolInfo : LPWSAProtocol_InfoW;
+        const lpszAddressString : PWideChar; var lpdwAddressStringLength : DWORD ): Longint; stdcall; external WINSOCK2_DLL name 'WSAAddressToStringW';
+function WSAAddressToString( var lpsaAddress : TSockAddr; const dwAddressLength : DWORD; const lpProtocolInfo : LPWSAProtocol_Info;
+        const lpszAddressString : PMBChar; var lpdwAddressStringLength : DWORD ): Longint; stdcall; external WINSOCK2_DLL name 'WSAAddressToString';
+function WSAStringToAddressA( const AddressString : PChar; const AddressFamily: Longint; const lpProtocolInfo : LPWSAProtocol_InfoA;
+        var lpAddress : TSockAddr; var lpAddressLength : Longint ): Longint; stdcall; external WINSOCK2_DLL name 'WSAStringToAddressA';
+function WSAStringToAddressW( const AddressString : PWideChar; const AddressFamily: Longint; const lpProtocolInfo : LPWSAProtocol_InfoA;
+        var lpAddress : TSockAddr; var lpAddressLength : Longint ): Longint; stdcall; external WINSOCK2_DLL name 'WSAStringToAddressW';
+function WSAStringToAddress( const AddressString : PMBChar; const AddressFamily: Longint; const lpProtocolInfo : LPWSAProtocol_Info;
+        var lpAddress : TSockAddr; var lpAddressLength : Longint ): Longint; stdcall; external WINSOCK2_DLL name 'WSAStringToAddress';
+
+{       Registration and Name Resolution API functions }
+function WSALookupServiceBeginA( const lpqsRestrictions : LPWSAQuerySetA; const dwControlFlags : DWORD; lphLookup : PHANDLE ): Longint; stdcall; external WINSOCK2_DLL name 'WSALookupServiceBeginA';
+function WSALookupServiceBeginW( const lpqsRestrictions : LPWSAQuerySetW; const dwControlFlags : DWORD; lphLookup : PHANDLE ): Longint; stdcall; external WINSOCK2_DLL name 'WSALookupServiceBeginW';
+function WSALookupServiceBegin( const lpqsRestrictions : LPWSAQuerySet; const dwControlFlags : DWORD; lphLookup : PHANDLE ): Longint; stdcall; external WINSOCK2_DLL name 'WSALookupServiceBegin';
+function WSALookupServiceNextA( const hLookup : THandle; const dwControlFlags : DWORD; var lpdwBufferLength : DWORD; lpqsResults : LPWSAQuerySetA ): Longint; stdcall; external WINSOCK2_DLL name 'WSALookupServiceNextA';
+function WSALookupServiceNextW( const hLookup : THandle; const dwControlFlags : DWORD; var lpdwBufferLength : DWORD; lpqsResults : LPWSAQuerySetW ): Longint; stdcall; external WINSOCK2_DLL name 'WSALookupServiceNextW';
+function WSALookupServiceNext( const hLookup : THandle; const dwControlFlags : DWORD; var lpdwBufferLength : DWORD; lpqsResults : LPWSAQuerySet ): Longint; stdcall; external WINSOCK2_DLL name 'WSALookupServiceNext';
+function WSALookupServiceEnd( const hLookup : THandle ): Longint; stdcall; external WINSOCK2_DLL name 'WSALookupServiceEnd';
+function WSAInstallServiceClassA( const lpServiceClassInfo : LPWSAServiceClassInfoA ) : Longint; stdcall; external WINSOCK2_DLL name 'WSAInstallServiceClassA';
+function WSAInstallServiceClassW( const lpServiceClassInfo : LPWSAServiceClassInfoW ) : Longint; stdcall; external WINSOCK2_DLL name 'WSAInstallServiceClassW';
+function WSAInstallServiceClass( const lpServiceClassInfo : LPWSAServiceClassInfo ) : Longint; stdcall; external WINSOCK2_DLL name 'WSAInstallServiceClass';
+function WSARemoveServiceClass( const lpServiceClassId : PGUID ) : Longint; stdcall; external WINSOCK2_DLL name 'WSARemoveServiceClass';
+function WSAGetServiceClassInfoA( const lpProviderId : PGUID; const lpServiceClassId : PGUID; var lpdwBufSize : DWORD;
+        lpServiceClassInfo : LPWSAServiceClassInfoA ): Longint; stdcall; external WINSOCK2_DLL name 'WSAGetServiceClassInfoA';
+function WSAGetServiceClassInfoW( const lpProviderId : PGUID; const lpServiceClassId : PGUID; var lpdwBufSize : DWORD;
+        lpServiceClassInfo : LPWSAServiceClassInfoW ): Longint; stdcall; external WINSOCK2_DLL name 'WSAGetServiceClassInfoW';
+function WSAGetServiceClassInfo( const lpProviderId : PGUID; const lpServiceClassId : PGUID; var lpdwBufSize : DWORD;
+        lpServiceClassInfo : LPWSAServiceClassInfo ): Longint; stdcall; external WINSOCK2_DLL name 'WSAGetServiceClassInfo';
+function WSAEnumNameSpaceProvidersA( var lpdwBufferLength: DWORD; const lpnspBuffer: LPWSANameSpace_InfoA ): Longint; stdcall; external WINSOCK2_DLL name 'WSAEnumNameSpaceProvidersA';
+function WSAEnumNameSpaceProvidersW( var lpdwBufferLength: DWORD; const lpnspBuffer: LPWSANameSpace_InfoW ): Longint; stdcall; external WINSOCK2_DLL name 'WSAEnumNameSpaceProvidersW';
+function WSAEnumNameSpaceProviders( var lpdwBufferLength: DWORD; const lpnspBuffer: LPWSANameSpace_Info ): Longint; stdcall; external WINSOCK2_DLL name 'WSAEnumNameSpaceProviders';
+function WSAGetServiceClassNameByClassIdA( const lpServiceClassId: PGUID; lpszServiceClassName: PChar;
+        var lpdwBufferLength: DWORD ): Longint; stdcall; external WINSOCK2_DLL name 'WSAGetServiceClassNameByClassIdA';
+function WSAGetServiceClassNameByClassIdW( const lpServiceClassId: PGUID; lpszServiceClassName: PWideChar;
+        var lpdwBufferLength: DWORD ): Longint; stdcall; external WINSOCK2_DLL name 'WSAGetServiceClassNameByClassIdW';
+function WSAGetServiceClassNameByClassId( const lpServiceClassId: PGUID; lpszServiceClassName: PMBChar;
+        var lpdwBufferLength: DWORD ): Longint; stdcall; external WINSOCK2_DLL name 'WSAGetServiceClassNameByClassId';
+function WSASetServiceA( const lpqsRegInfo: LPWSAQuerySetA; const essoperation: TWSAeSetServiceOp;
+        const dwControlFlags: DWORD ): Longint; stdcall; external WINSOCK2_DLL name 'WSASetServiceA';
+function WSASetServiceW( const lpqsRegInfo: LPWSAQuerySetW; const essoperation: TWSAeSetServiceOp;
+        const dwControlFlags: DWORD ): Longint; stdcall; external WINSOCK2_DLL name 'WSASetServiceW';
+function WSASetService( const lpqsRegInfo: LPWSAQuerySet; const essoperation: TWSAeSetServiceOp;
+        const dwControlFlags: DWORD ): Longint; stdcall; external WINSOCK2_DLL name 'WSASetService';
+
+{ Macros }
+function WSAMakeSyncReply(Buflen, Error: Word): Longint;
+function WSAMakeSelectReply(Event, Error: Word): Longint;
+function WSAGetAsyncBuflen(Param: Longint): Word;
+function WSAGetAsyncError(Param: Longint): Word;
+function WSAGetSelectEvent(Param: Longint): Word;
+function WSAGetSelectError(Param: Longint): Word;
+
+procedure FD_CLR(Socket: TSocket; var FDSet: TFDSet);
+function FD_ISSET(Socket: TSocket; var FDSet: TFDSet): Boolean;
+procedure FD_SET(Socket: TSocket; var FDSet: TFDSet);
+procedure FD_ZERO(var FDSet: TFDSet);
+
+//=============================================================
+implementation
+//=============================================================
+
+function WSAMakeSyncReply(Buflen, Error: Word): Longint;
+begin
+  WSAMakeSyncReply:= MakeLong(Buflen, Error);
+end;
+
+function WSAMakeSelectReply(Event, Error: Word): Longint;
+begin
+  WSAMakeSelectReply:= MakeLong(Event, Error);
+end;
+
+function WSAGetAsyncBuflen(Param: Longint): Word;
+begin
+  WSAGetAsyncBuflen:= LOWORD(Param);
+end;
+
+function WSAGetAsyncError(Param: Longint): Word;
+begin
+  WSAGetAsyncError:= HIWORD(Param);
+end;
+
+function WSAGetSelectEvent(Param: Longint): Word;
+begin
+  WSAGetSelectEvent:= LOWORD(Param);
+end;
+
+function WSAGetSelectError(Param: Longint): Word;
+begin
+  WSAGetSelectError:= HIWORD(Param);
+end;
+
+procedure FD_CLR(Socket: TSocket; var FDSet: TFDSet);
+var
+  I: Longint;
+begin
+  I := 0;
+  while I < FDSet.fd_count do
+  begin
+    if FDSet.fd_array[I] = Socket then
+    begin
+      while I < FDSet.fd_count - 1 do
+      begin
+        FDSet.fd_array[I] := FDSet.fd_array[I + 1];
+        Inc(I);
+      end;
+      Dec(FDSet.fd_count);
+      Break;
+    end;
+    Inc(I);
+  end;
+end;
+
+function FD_ISSET(Socket: TSocket; var FDSet: TFDSet): Boolean;
+begin
+  FD_ISSET := __WSAFDIsSet(Socket, FDSet);
+end;
+
+procedure FD_SET(Socket: TSocket; var FDSet: TFDSet);
+begin
+  if FDSet.fd_count < FD_SETSIZE then
+  begin
+    FDSet.fd_array[FDSet.fd_count] := Socket;
+    Inc(FDSet.fd_count);
+  end;
+end;
+
+procedure FD_ZERO(var FDSet: TFDSet);
+begin
+  FDSet.fd_count := 0;
+end;
+
+end.

+ 43 - 0
tests/webtbs/tw4707.pp

@@ -0,0 +1,43 @@
+{ %OPT=-S2 }
+{ Source provided for Free Pascal Bug Report 4704 }
+{ Submitted by "Phil H." on  2006-01-17 }
+{ e-mail: [email protected] }
+program TestExcep;
+
+uses
+  SysUtils,
+  Variants;
+
+var
+  AnInt : Integer;
+  AVar  : Variant;
+  
+begin
+  AVar := Null;
+  try
+    AnInt := AVar;
+    halt(1);
+    case AnInt of
+      1 : ;
+      end;
+    
+  except 
+    on E: EVariantError do
+      begin
+      WriteLn('Handled EVariantError');
+      WriteLn(E.ClassName);
+      WriteLn(E.Message);
+      if (E.Message = '') then
+        halt(3);
+      end;
+    on E: Exception do
+      begin
+      WriteLn('Handled Exception');
+      WriteLn(E.ClassName);
+      WriteLn(E.Message);
+      halt(2);
+      end;
+    end;
+  
+end.
+