You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

fd_utils.pas 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. See the file COPYING.FPC, included in this distribution,
  11. for details about the copyright.
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY;without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. **********************************************************************}
  16. {$ifdef fpc}
  17. {$mode delphi}
  18. {$inlining on}
  19. {$endif}
  20. unit fd_utils;
  21. interface
  22. type
  23. FDSet= Array [0..255] of longint; {31}
  24. PFDSet= ^FDSet;
  25. Procedure FD_Clr(fd:longint;var fds:fdSet);
  26. Procedure FD_Zero(var fds:fdSet);
  27. Procedure FD_Set(fd:longint;var fds:fdSet);
  28. Function FD_IsSet(fd:longint;var fds:fdSet):boolean;
  29. {$ifdef fpc}
  30. {$ifndef ver1_0}
  31. {$define useinline}
  32. {$endif}
  33. {$endif}
  34. implementation
  35. uses sysutils;
  36. Procedure FD_Clr(fd:longint;var fds:fdSet);{$ifdef useinline}inline;{$endif}
  37. { Remove fd from the set of filedescriptors}
  38. begin
  39. if (fd < 0) then raise exception.create('FD_Clr fd out of range: '+inttostr(fd));
  40. fds[fd shr 5]:=fds[fd shr 5] and (not (1 shl (fd and 31)));
  41. end;
  42. Procedure FD_Zero(var fds:fdSet);
  43. { Clear the set of filedescriptors }
  44. begin
  45. FillChar(fds,sizeof(fdSet),0);
  46. end;
  47. Procedure FD_Set(fd:longint;var fds:fdSet);{$ifdef useinline}inline;{$endif}
  48. { Add fd to the set of filedescriptors }
  49. begin
  50. if (fd < 0) then raise exception.create('FD_set fd out of range: '+inttostr(fd));
  51. fds[fd shr 5]:=fds[fd shr 5] or (1 shl (fd and 31));
  52. end;
  53. Function FD_IsSet(fd:longint;var fds:fdSet):boolean;{$ifdef useinline}inline;{$endif}
  54. { Test if fd is part of the set of filedescriptors }
  55. begin
  56. if (fd < 0) then begin
  57. result := false;
  58. exit;
  59. end;
  60. FD_IsSet:=((fds[fd shr 5] and (1 shl (fd and 31)))<>0);
  61. end;
  62. end.