/[lcore]/trunk/fd_utils.pas
ViewVC logotype

Contents of /trunk/fd_utils.pas

Parent Directory Parent Directory | Revision Log Revision Log


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

Properties

Name Value
svn:eol-style CRLF

No admin address has been configured">No admin address has been configured
ViewVC Help
Powered by ViewVC 1.1.5