X-Git-Url: http://www.lcore.org/git/lcore.git/blobdiff_plain/4782a5c5afee47721cc617daa40dd29828342c2b..9951872c6c46881c8b414bcd04a18320c457b811:/fd_utils.pas?ds=sidebyside diff --git a/fd_utils.pas b/fd_utils.pas old mode 100755 new mode 100644 index ea6e833..86b6d3a --- a/fd_utils.pas +++ b/fd_utils.pas @@ -23,21 +23,24 @@ unit fd_utils; interface +const + FDwordshift=5; + FDwordmaxbit=(1 shl FDwordshift)-1; + type - FDSet= Array [0..255] of longint; {31} + FDword=longint; + FDSet= Array [0..255] of fdword; {31} PFDSet= ^FDSet; -const - absoloutemaxs=(sizeof(fdset)*8)-1; Procedure FD_Clr(fd:longint;var fds:fdSet); Procedure FD_Zero(var fds:fdSet); Procedure FD_Set(fd:longint;var fds:fdSet); Function FD_IsSet(fd:longint;var fds:fdSet):boolean; - -{$ifdef fpc} - {$ifndef ver1_0} - {$define useinline} - {$endif} + +{$ifdef fpc} + {$ifndef ver1_0} + {$define useinline} + {$endif} {$endif} implementation @@ -45,8 +48,8 @@ uses sysutils; Procedure FD_Clr(fd:longint;var fds:fdSet);{$ifdef useinline}inline;{$endif} { Remove fd from the set of filedescriptors} begin - if (fd < 0) then raise exception.create('FD_Clr fd out of range: '+inttostr(fd)); - fds[fd shr 5]:=fds[fd shr 5] and (not (1 shl (fd and 31))); + if (fd < 0) or ((fd shr fdwordshift) > high(fdset)) then raise exception.create('FD_Clr fd out of range: '+inttostr(fd)); + fds[fd shr fdwordshift]:=fds[fd shr fdwordshift] and (not (1 shl (fd and fdwordmaxbit))); end; Procedure FD_Zero(var fds:fdSet); @@ -58,17 +61,17 @@ end; Procedure FD_Set(fd:longint;var fds:fdSet);{$ifdef useinline}inline;{$endif} { Add fd to the set of filedescriptors } begin - if (fd < 0) then raise exception.create('FD_set fd out of range: '+inttostr(fd)); - fds[fd shr 5]:=fds[fd shr 5] or (1 shl (fd and 31)); + if (fd < 0) or ((fd shr fdwordshift) > high(fdset)) then raise exception.create('FD_set fd out of range: '+inttostr(fd)); + fds[fd shr fdwordshift]:=fds[fd shr fdwordshift] or (1 shl (fd and fdwordmaxbit)); end; Function FD_IsSet(fd:longint;var fds:fdSet):boolean;{$ifdef useinline}inline;{$endif} { Test if fd is part of the set of filedescriptors } begin - if (fd < 0) then begin + if (fd < 0) or ((fd shr fdwordshift) > high(fdset)) then begin result := false; exit; end; - FD_IsSet:=((fds[fd shr 5] and (1 shl (fd and 31)))<>0); + FD_IsSet:=((fds[fd shr fdwordshift] and (1 shl (fd and fdwordmaxbit)))<>0); end; end.