/[lcore]/trunk/unixstuff.inc
ViewVC logotype

Contents of /trunk/unixstuff.inc

Parent Directory Parent Directory | Revision Log Revision Log


Revision 160 - (show annotations)
Sat Sep 25 16:58:24 2021 UTC (2 months ago) by beware
File size: 5559 byte(s)
FPC_FULLVERSION >= 30200 breaks delphi 6 even inside an ifdef it shouldnt process
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 {$define need_v6constants}
27 {$else}
28
29 {$define sigprocmask := fpsigprocmask}
30 {$define sigaction := fpsigaction}
31 {$define fdclose := fpclose}
32 {$define fcntl := fpfcntl}
33 {$define fdwrite := fpwrite}
34 {$define fdread := fpread}
35 {$define fdopen := fpopen}
36 {$define select := fpselect}
37 {$define linuxerror := fpgeterrno}
38 {$define fork := fpfork}
39 {$define getpid := fpgetpid}
40 {$define getenv := fpgetenv}
41 {$define chmod := fpchmod}
42 {$define dup2 := fpdup2}
43 {$ifndef ver1_9_2}
44 {$define flock := fpflock}
45 {$ifndef ver1_9_4}
46 //beware: this is needed because FPC_FULLVERSION >= 30200 breaks delphi 6 even inside an ifdef it shouldn't process
47 {$ifdef fpc}
48 {$ifdef ver3}
49 {$ifndef ver3_0}{$ifndef ver3_1}{$define fpc_3_2_or_later}{$endif}{$endif}
50 {$endif}
51 {$ifdef ver4}{$define fpc_3_2_or_later}{$endif}
52 {$endif}
53 {$ifdef fpc_3_2_or_later}
54 procedure Execl(Todo:rawbytestring);inline;
55 {$else}
56 procedure Execl(Todo:string);inline;
57 {$endif}
58 var
59 p : ppchar;
60 begin
61 p := unixutil.StringToPPChar(Todo,0);
62 if (p=nil) or (p^=nil) then exit;
63 fpexecv(p^,p);
64 end;
65 function SendTo(Sock: LongInt; const Buf;BufLen: LongInt;Flags: LongInt;var Addr;AddrLen: LongInt):LongInt;
66 begin
67 result := fpsendto(sock,@buf,buflen,flags,@addr,addrlen);
68 end;
69 function RecvFrom(Sock: LongInt;var Buf;Buflen: LongInt;Flags: LongInt;var Addr;var addrlen: Longint):LongInt;
70 begin
71 result := fprecvfrom(sock,@buf,buflen,flags,@addr,@addrlen);
72 end;
73 {$define socket := fpsocket}
74 function Bind(Sock: LongInt;const Addr;AddrLen: LongInt):Boolean;
75 begin
76 result := fpbind(sock,@addr,addrlen) = 0;
77 end;
78 function SetSocketOptions(Sock: LongInt;Level: LongInt;OptName: LongInt;const OptVal;optlen: LongInt):LongInt;
79 begin
80 result := fpsetsockopt(sock,level,optname,@optval,optlen);
81 end;
82 function Connect(Sock: LongInt;const Addr;Addrlen: LongInt):Boolean;
83 begin
84 result := fpconnect(sock,@addr,addrlen) >= 0;
85 end;
86 function listen(Sock: LongInt;MaxConnect: LongInt):Boolean;
87 begin
88 result := fplisten(sock,maxconnect) = 0;
89 end;
90 function GetPeerName(Sock: LongInt; var Addr;var Addrlen: LongInt):LongInt;
91 begin
92 result := fpgetpeername(sock,@addr,@addrlen);
93 end;
94 function GetSocketName(Sock: LongInt; var Addr;var Addrlen: LongInt):LongInt;
95 begin
96 result := fpgetsockname(sock,@addr,@addrlen);
97 end;
98 function Accept(Sock: LongInt; var Addr; var Addrlen: LongInt):LongInt;
99 begin
100 result := fpaccept(sock,@addr,@addrlen);
101 end;
102 {$endif}
103 {$endif}
104 {$ifdef ver2_0}
105 const
106 IPPROTO_UDP=17;
107 IPPROTO_ICMP=1;
108 {$define need_v6constants}
109 {$endif}
110 {$ifdef ver1_9}
111 const
112 IPPROTO_UDP=17;
113 IPPROTO_ICMP=1;
114 function ntohs(invalue:word):word;inline;
115 var
116 invaluebytes : array[0..1] of byte absolute invalue;
117 resultbytes : array[0..1] of byte absolute result;
118 begin
119 {$ifdef endian_little}
120 resultbytes[0] := invaluebytes[1];
121 resultbytes[1] := invaluebytes[0];
122 {$else}
123 result := invalue;
124 {$endif}
125 end;
126 {$define need_v6constants}
127 {$endif}
128 procedure gettimeofday(var tv:ttimeval);inline;
129 begin
130 fpgettimeofday(@tv,nil);
131 end;
132 function gettimeofdaysec : longint;
133 var
134 tv:ttimeval;
135 begin
136 gettimeofday(tv);
137 result := tv.tv_sec;
138 end;
139
140 //a function is used here rather than a define to prevent issues with tlasio.dup
141 function dup(const original:integer):integer;inline;
142 begin
143 result := fpdup(original);
144 end;
145 function octal(invalue:longint):longint;
146 var
147 a : integer;
148 i : integer;
149 begin
150 i := 0;
151 result := 0;
152 while invalue <> 0 do begin
153 a := invalue mod 10;
154 result := result + (a shl (i*3));
155
156 invalue := invalue div 10;
157 inc(i);
158 end;
159 end;
160 const
161 sys_eintr=esyseintr;
162
163 {$endif}
164 {$ifdef need_v6constants}
165 {$ifdef linux}
166 //the below values are only known correct on linux, I don't support
167 //1.0.x on any other unix platform atm anyway --plugwash
168 const
169 IPPROTO_IPV6 = 41;
170 IPV6_V6ONLY = 26;
171 {$endif}
172 {$endif}
173 {$ifdef freebsd}
174 //freepascal doesn't seem to define IPV6_V6ONLY on freebsd, the definition
175 //here is taken from the include files of a freebsd 8 system
176 const
177 IPV6_V6ONLY = 27;
178 {$endif}
179
180 {$endif}
181
182

Properties

Name Value
svn:eol-style CRLF

No admin address has been configured">No admin address has been configured
ViewVC Help
Powered by ViewVC 1.1.26