Mirror of :pserver:cvs@cvs.fefe.de:/cvs libowfat https://www.fefe.de/libowfat/
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.
 
 
 
 

91 lines
1.9 KiB

  1. #ifdef __hpux__
  2. #include <sys/types.h>
  3. #include <sys/uio.h>
  4. #include <sys/socket.h>
  5. #include <stdio.h>
  6. int main() {
  7. /*
  8. sbsize_t sendfile(int s, int fd, off_t offset, bsize_t nbytes,
  9. const struct iovec *hdtrl, int flags);
  10. */
  11. struct iovec x[2];
  12. int fd=open("havesendfile.c",0);
  13. x[0].iov_base="header";
  14. x[0].iov_len=6;
  15. x[1].iov_base="footer";
  16. x[1].iov_len=6;
  17. sendfile(1 /* dest socket */,fd /* src file */,
  18. 0 /* offset */, 23 /* nbytes */,
  19. x, 0);
  20. perror("sendfile");
  21. return 0;
  22. }
  23. #elif defined (__sun__) && defined(__svr4__)
  24. #include <sys/types.h>
  25. #include <sys/socket.h>
  26. #include <sys/sendfile.h>
  27. #include <stdio.h>
  28. int main() {
  29. off_t o;
  30. o=0;
  31. sendfile(1 /* dest */, 0 /* src */,&o,23 /* nbytes */);
  32. perror("sendfile");
  33. return 0;
  34. }
  35. #elif defined (_AIX)
  36. #define _FILE_OFFSET_BITS 64
  37. #include <sys/types.h>
  38. #include <sys/socket.h>
  39. #include <unistd.h>
  40. #include <stdio.h>
  41. int main() {
  42. int fd=open("havesendfile.c",0);
  43. struct sf_parms p;
  44. int destfd=1;
  45. p.header_data="header";
  46. p.header_length=6;
  47. p.file_descriptor=fd;
  48. p.file_offset=0;
  49. p.file_bytes=23;
  50. p.trailer_data="footer";
  51. p.trailer_length=6;
  52. if (send_file(&destfd,&p,0)>=0)
  53. printf("sent %lu bytes.\n",p.bytes_sent);
  54. return 0;
  55. }
  56. #elif defined(__linux__)
  57. #define _FILE_OFFSET_BITS 64
  58. #include <sys/types.h>
  59. #include <unistd.h>
  60. #if defined(__GLIBC__)
  61. #include <sys/sendfile.h>
  62. #elif defined(__dietlibc__)
  63. #include <sys/sendfile.h>
  64. #else
  65. #include <linux/unistd.h>
  66. _syscall4(int,sendfile,int,out,int,in,long *,offset,unsigned long,count)
  67. #endif
  68. #include <stdio.h>
  69. int main() {
  70. int fd=open("havesendfile.c",0);
  71. off_t o=0;
  72. off_t r=sendfile(1,fd,&o,23);
  73. if (r!=-1)
  74. printf("sent %llu bytes.\n",r);
  75. return 0;
  76. }
  77. #else
  78. #error unsupported architecture
  79. /* stupid fucking IRIX c99 does not signal #error via a non-zero exit
  80. * code! ARGH! So insert a parse error */
  81. #include rumpelstilzchen
  82. )
  83. #endif