freebsd.pas 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. Unit FreeBSD;
  2. {
  3. This file is part of the Free Pascal run time library.
  4. (c) 2005 by Marco van de Voort
  5. member of the Free Pascal development team.
  6. based on the sendfile conversion of Ales Katona 30.01.2006
  7. See the file COPYING.FPC, included in this distribution,
  8. for details about the copyright.
  9. Unit for FreeBSD specific calls. Calls may move to "BSD" unit in time,
  10. if turns out that more BSDs include them.
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY;without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14. }
  15. {$IFDEF FPC}
  16. {$PACKRECORDS C}
  17. {$inline on}
  18. {$Macro On}
  19. {$ifdef FPC_USE_LIBC}
  20. {$define directives:=cdecl; external 'c';}
  21. {$else}
  22. {$define directives:=inline;}
  23. {$endif}
  24. {$ENDIF}
  25. interface
  26. uses
  27. BaseUnix,Unix;
  28. const
  29. SF_NODISKIO = $00000001; // don't wait for disk IO, similar to non-blocking socket setting
  30. Type
  31. SF_HDTR = record
  32. headers: PIOVec; //* pointer to an array of header struct iovec's */
  33. hdr_cnt: cint; //* number of header iovec's */
  34. trailers: PIOVec; //* pointer to an array of trailer struct iovec's */
  35. trl_cnt: cint; //* number of trailer iovec's */
  36. end;
  37. TSF_HDTR = SF_HDTR;
  38. PSF_HDTR = ^TSF_HDTR;
  39. function sendfile(fd: cint; s: cint; Offset: TOff; nBytes: TSize;
  40. HDTR: PSF_HDTR; sBytes: POff; Flags: cint): cint; directives
  41. implementation
  42. Uses
  43. {$ifndef FPC_USE_LIBC} SysCall; {$else} InitC; {$endif}
  44. {$IFNDEF FPC_USE_LIBC}
  45. function SendFile(fd: cint; s: cint; Offset: TOff; nBytes: TSize;
  46. HDTR: PSF_HDTR; sBytes: POff; Flags: cint): cint;
  47. begin
  48. SendFile:=Do_Syscall(syscall_nr_sendfile, fd, s,
  49. {$IFNDEF CPU64}
  50. {$IFDEF LITTLE_ENDIAN} // little endian is lo - hi
  51. Lo(Offset), Hi(Offset),
  52. {$ELSE} // big endian is hi - lo
  53. Hi(Offset), Lo(Offset),
  54. {$ENDIF}
  55. {$ELSE} // 64-bit doesn't care.
  56. TSysParam(Offset),
  57. {$ENDIF}
  58. nBytes, TSysParam(HDTR), TSysParam(sBytes), Flags);
  59. end;
  60. {$ENDIF}
  61. end.