simulate gettimeofday on windows
[lcore.git] / fd_utils.pas
1 // this file contains code copied from linux.pp in the free pascal rtl\r
2 // i had to copy them because i use a different definition of fdset to them\r
3 // the copyright block from the file in question is shown below\r
4 {\r
5    $Id: fd_utils.pas,v 1.2 2004/08/19 23:12:09 plugwash Exp $\r
6    This file is part of the Free Pascal run time library.\r
7    Copyright (c) 1999-2000 by Michael Van Canneyt,\r
8    BSD parts (c) 2000 by Marco van de Voort\r
9    members of the Free Pascal development team.\r
10 \r
11    See the file COPYING.FPC, included in this distribution,\r
12    for details about the copyright.\r
13 \r
14    This program is distributed in the hope that it will be useful,\r
15    but WITHOUT ANY WARRANTY;without even the implied warranty of\r
16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\r
17 \r
18 **********************************************************************}\r
19 {$ifdef fpc}\r
20   {$mode delphi}\r
21   {$inlining on}\r
22 {$endif}\r
23 unit fd_utils;\r
24 interface\r
25 \r
26 const\r
27     FDwordshift=5;\r
28     FDwordmaxbit=(1 shl FDwordshift)-1;\r
29 \r
30 type\r
31     FDword=longint;\r
32     FDSet= Array [0..255] of fdword; {31}\r
33     PFDSet= ^FDSet;\r
34 \r
35 Procedure FD_Clr(fd:longint;var fds:fdSet);\r
36 Procedure FD_Zero(var fds:fdSet);\r
37 Procedure FD_Set(fd:longint;var fds:fdSet);\r
38 Function FD_IsSet(fd:longint;var fds:fdSet):boolean;\r
39 \r
40 {$ifdef fpc}\r
41   {$ifndef ver1_0}\r
42     {$define useinline}\r
43   {$endif}\r
44 {$endif}\r
45 \r
46 implementation  \r
47 uses sysutils;\r
48 Procedure FD_Clr(fd:longint;var fds:fdSet);{$ifdef useinline}inline;{$endif}\r
49 { Remove fd from the set of filedescriptors}\r
50 begin\r
51   if (fd < 0) then raise exception.create('FD_Clr fd out of range: '+inttostr(fd));\r
52   fds[fd shr fdwordshift]:=fds[fd shr fdwordshift] and (not (1 shl (fd and fdwordmaxbit)));\r
53 end;\r
54 \r
55 Procedure FD_Zero(var fds:fdSet);\r
56 { Clear the set of filedescriptors }\r
57 begin\r
58   FillChar(fds,sizeof(fdSet),0);\r
59 end;\r
60 \r
61 Procedure FD_Set(fd:longint;var fds:fdSet);{$ifdef useinline}inline;{$endif}\r
62 { Add fd to the set of filedescriptors }\r
63 begin\r
64   if (fd < 0) then raise exception.create('FD_set fd out of range: '+inttostr(fd));\r
65   fds[fd shr fdwordshift]:=fds[fd shr fdwordshift] or (1 shl (fd and fdwordmaxbit));\r
66 end;\r
67 \r
68 Function FD_IsSet(fd:longint;var fds:fdSet):boolean;{$ifdef useinline}inline;{$endif}\r
69 { Test if fd is part of the set of filedescriptors }\r
70 begin\r
71   if (fd < 0) then begin\r
72     result := false;\r
73     exit;\r
74   end;\r
75   FD_IsSet:=((fds[fd shr fdwordshift] and (1 shl (fd and fdwordmaxbit)))<>0);\r
76 end;\r
77 end.\r