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

Contents of /trunk/unixstuff.inc

Parent Directory Parent Directory | Revision Log Revision Log


Revision 135 - (show annotations)
Thu Mar 13 21:27:50 2014 UTC (3 years, 9 months ago) by beware
File size: 5075 byte(s)
removed incorrect executable status from files
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 procedure Execl(Todo:string);inline;
47 var
48 p : ppchar;
49 begin
50 p := unixutil.StringToPPChar(Todo,0);
51 if (p=nil) or (p^=nil) then exit;
52 fpexecv(p^,p);
53 end;
54 function SendTo(Sock: LongInt; const Buf;BufLen: LongInt;Flags: LongInt;var Addr;AddrLen: LongInt):LongInt;
55 begin
56 result := fpsendto(sock,@buf,buflen,flags,@addr,addrlen);
57 end;
58 function RecvFrom(Sock: LongInt;var Buf;Buflen: LongInt;Flags: LongInt;var Addr;var addrlen: Longint):LongInt;
59 begin
60 result := fprecvfrom(sock,@buf,buflen,flags,@addr,@addrlen);
61 end;
62 {$define socket := fpsocket}
63 function Bind(Sock: LongInt;const Addr;AddrLen: LongInt):Boolean;
64 begin
65 result := fpbind(sock,@addr,addrlen) = 0;
66 end;
67 function SetSocketOptions(Sock: LongInt;Level: LongInt;OptName: LongInt;const OptVal;optlen: LongInt):LongInt;
68 begin
69 result := fpsetsockopt(sock,level,optname,@optval,optlen);
70 end;
71 function Connect(Sock: LongInt;const Addr;Addrlen: LongInt):Boolean;
72 begin
73 result := fpconnect(sock,@addr,addrlen) >= 0;
74 end;
75 function listen(Sock: LongInt;MaxConnect: LongInt):Boolean;
76 begin
77 result := fplisten(sock,maxconnect) = 0;
78 end;
79 function GetPeerName(Sock: LongInt; var Addr;var Addrlen: LongInt):LongInt;
80 begin
81 result := fpgetpeername(sock,@addr,@addrlen);
82 end;
83 function GetSocketName(Sock: LongInt; var Addr;var Addrlen: LongInt):LongInt;
84 begin
85 result := fpgetsockname(sock,@addr,@addrlen);
86 end;
87 function Accept(Sock: LongInt; var Addr; var Addrlen: LongInt):LongInt;
88 begin
89 result := fpaccept(sock,@addr,@addrlen);
90 end;
91 {$endif}
92 {$endif}
93 {$ifdef ver2_0}
94 const
95 IPPROTO_UDP=17;
96 IPPROTO_ICMP=1;
97 {$define need_v6constants}
98 {$endif}
99 {$ifdef ver1_9}
100 const
101 IPPROTO_UDP=17;
102 IPPROTO_ICMP=1;
103 function ntohs(invalue:word):word;inline;
104 var
105 invaluebytes : array[0..1] of byte absolute invalue;
106 resultbytes : array[0..1] of byte absolute result;
107 begin
108 {$ifdef endian_little}
109 resultbytes[0] := invaluebytes[1];
110 resultbytes[1] := invaluebytes[0];
111 {$else}
112 result := invalue;
113 {$endif}
114 end;
115 {$define need_v6constants}
116 {$endif}
117 procedure gettimeofday(var tv:ttimeval);inline;
118 begin
119 fpgettimeofday(@tv,nil);
120 end;
121 function gettimeofdaysec : longint;
122 var
123 tv:ttimeval;
124 begin
125 gettimeofday(tv);
126 result := tv.tv_sec;
127 end;
128
129 //a function is used here rather than a define to prevent issues with tlasio.dup
130 function dup(const original:integer):integer;inline;
131 begin
132 result := fpdup(original);
133 end;
134 function octal(invalue:longint):longint;
135 var
136 a : integer;
137 i : integer;
138 begin
139 i := 0;
140 result := 0;
141 while invalue <> 0 do begin
142 a := invalue mod 10;
143 result := result + (a shl (i*3));
144
145 invalue := invalue div 10;
146 inc(i);
147 end;
148 end;
149 const
150 sys_eintr=esyseintr;
151
152 {$endif}
153 {$ifdef need_v6constants}
154 {$ifdef linux}
155 //the below values are only known correct on linux, I don't support
156 //1.0.x on any other unix platform atm anyway --plugwash
157 const
158 IPPROTO_IPV6 = 41;
159 IPV6_V6ONLY = 26;
160 {$endif}
161 {$endif}
162 {$ifdef freebsd}
163 //freepascal doesn't seem to define IPV6_V6ONLY on freebsd, the definition
164 //here is taken from the include files of a freebsd 8 system
165 const
166 IPV6_V6ONLY = 27;
167 {$endif}
168
169 {$endif}
170
171

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.5