Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

unixstuff.inc 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. {$ifdef UNIX}
  2. {$macro on}
  3. {$ifdef VER1_0}
  4. {$define tv_sec := sec}
  5. {$define tv_usec := usec}
  6. function dup(const original:integer):integer;inline;
  7. begin
  8. linux.dup(original,result);
  9. end;
  10. {$define gettimeofdaysec := gettimeofday}
  11. const
  12. IPPROTO_UDP=17;
  13. IPPROTO_ICMP=1;
  14. function ntohs(invalue:word):word;inline;
  15. var
  16. invaluebytes : array[0..1] of byte absolute invalue;
  17. resultbytes : array[0..1] of byte absolute result;
  18. begin
  19. {$ifdef endian_little}
  20. resultbytes[0] := invaluebytes[1];
  21. resultbytes[1] := invaluebytes[0];
  22. {$else}
  23. result := invalue;
  24. {$endif}
  25. end;
  26. {$else}
  27. {$define sigprocmask := fpsigprocmask}
  28. {$define sigaction := fpsigaction}
  29. {$define fdclose := fpclose}
  30. {$define fcntl := fpfcntl}
  31. {$define fdwrite := fpwrite}
  32. {$define fdread := fpread}
  33. {$define fdopen := fpopen}
  34. {$define select := fpselect}
  35. {$define linuxerror := fpgeterrno}
  36. {$define fork := fpfork}
  37. {$define getpid := fpgetpid}
  38. {$define getenv := fpgetenv}
  39. {$define chmod := fpchmod}
  40. {$define dup2 := fpdup2}
  41. {$ifndef ver1_9_2}
  42. {$define flock := fpflock}
  43. {$ifndef ver1_9_4}
  44. procedure Execl(Todo:string);inline;
  45. var
  46. p : ppchar;
  47. begin
  48. p := unixutil.StringToPPChar(Todo,1);
  49. if (p=nil) or (p^=nil) then exit;
  50. fpexecv(p^,p);
  51. end;
  52. {$endif}
  53. {$endif}
  54. {$ifdef ver2_0}
  55. const
  56. IPPROTO_UDP=17;
  57. IPPROTO_ICMP=1;
  58. {$endif}
  59. {$ifdef ver1_9}
  60. const
  61. IPPROTO_UDP=17;
  62. IPPROTO_ICMP=1;
  63. function ntohs(invalue:word):word;inline;
  64. var
  65. invaluebytes : array[0..1] of byte absolute invalue;
  66. resultbytes : array[0..1] of byte absolute result;
  67. begin
  68. {$ifdef endian_little}
  69. resultbytes[0] := invaluebytes[1];
  70. resultbytes[1] := invaluebytes[0];
  71. {$else}
  72. result := invalue;
  73. {$endif}
  74. end;
  75. {$endif}
  76. procedure gettimeofday(var tv:ttimeval);inline;
  77. begin
  78. fpgettimeofday(@tv,nil);
  79. end;
  80. function gettimeofdaysec : longint;
  81. var
  82. tv:ttimeval;
  83. begin
  84. gettimeofday(tv);
  85. result := tv.tv_sec;
  86. end;
  87. //a function is used here rather than a define to prevent issues with tlasio.dup
  88. function dup(const original:integer):integer;inline;
  89. begin
  90. result := fpdup(original);
  91. end;
  92. function octal(invalue:longint):longint;
  93. var
  94. a : integer;
  95. i : integer;
  96. begin
  97. i := 0;
  98. result := 0;
  99. while invalue <> 0 do begin
  100. a := invalue mod 10;
  101. result := result + (a shl (i*3));
  102. invalue := invalue div 10;
  103. inc(i);
  104. end;
  105. end;
  106. const
  107. sys_eintr=esyseintr;
  108. {$endif}
  109. {$endif}