unit fd_utils;\r
interface\r
\r
+const\r
+ FDwordshift=5;\r
+ FDwordmaxbit=(1 shl FDwordshift)-1;\r
+\r
type\r
- FDSet= Array [0..255] of longint; {31}\r
+ FDword=longint;\r
+ FDSet= Array [0..255] of fdword; {31}\r
PFDSet= ^FDSet;\r
-const\r
- absoloutemaxs=(sizeof(fdset)*8)-1;\r
\r
Procedure FD_Clr(fd:longint;var fds:fdSet);\r
Procedure FD_Zero(var fds:fdSet);\r
Procedure FD_Set(fd:longint;var fds:fdSet);\r
Function FD_IsSet(fd:longint;var fds:fdSet):boolean;\r
-
-{$ifdef fpc}
- {$ifndef ver1_0}
- {$define useinline}
- {$endif}
+\r
+{$ifdef fpc}\r
+ {$ifndef ver1_0}\r
+ {$define useinline}\r
+ {$endif}\r
{$endif}\r
\r
implementation \r
Procedure FD_Clr(fd:longint;var fds:fdSet);{$ifdef useinline}inline;{$endif}\r
{ Remove fd from the set of filedescriptors}\r
begin\r
- if (fd < 0) then raise exception.create('FD_Clr fd out of range: '+inttostr(fd));\r
- fds[fd shr 5]:=fds[fd shr 5] and (not (1 shl (fd and 31)));\r
+ if (fd < 0) or ((fd shr fdwordshift) > high(fdset)) then raise exception.create('FD_Clr fd out of range: '+inttostr(fd));\r
+ fds[fd shr fdwordshift]:=fds[fd shr fdwordshift] and (not (1 shl (fd and fdwordmaxbit)));\r
end;\r
\r
Procedure FD_Zero(var fds:fdSet);\r
Procedure FD_Set(fd:longint;var fds:fdSet);{$ifdef useinline}inline;{$endif}\r
{ Add fd to the set of filedescriptors }\r
begin\r
- if (fd < 0) then raise exception.create('FD_set fd out of range: '+inttostr(fd));\r
- fds[fd shr 5]:=fds[fd shr 5] or (1 shl (fd and 31));\r
+ if (fd < 0) or ((fd shr fdwordshift) > high(fdset)) then raise exception.create('FD_set fd out of range: '+inttostr(fd));\r
+ fds[fd shr fdwordshift]:=fds[fd shr fdwordshift] or (1 shl (fd and fdwordmaxbit));\r
end;\r
\r
Function FD_IsSet(fd:longint;var fds:fdSet):boolean;{$ifdef useinline}inline;{$endif}\r
{ Test if fd is part of the set of filedescriptors }\r
begin\r
- if (fd < 0) then begin\r
+ if (fd < 0) or ((fd shr fdwordshift) > high(fdset)) then begin\r
result := false;\r
exit;\r
end;\r
- FD_IsSet:=((fds[fd shr 5] and (1 shl (fd and 31)))<>0);\r
+ FD_IsSet:=((fds[fd shr fdwordshift] and (1 shl (fd and fdwordmaxbit)))<>0);\r
end;\r
end.\r