235 |
|
} |
236 |
|
} |
237 |
|
*/ |
238 |
+ |
|
239 |
+ |
#ifndef HAVE_ATOLL |
240 |
+ |
long long int atoll (const char *nptr){ |
241 |
+ |
return strtoll (nptr, (char **) NULL, 10); |
242 |
+ |
} |
243 |
+ |
#endif |
244 |
+ |
|
245 |
+ |
#ifndef HAVE_STRLCPY |
246 |
+ |
/* |
247 |
+ |
* Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com> |
248 |
+ |
* All rights reserved. |
249 |
+ |
* |
250 |
+ |
* Redistribution and use in source and binary forms, with or without |
251 |
+ |
* modification, are permitted provided that the following conditions |
252 |
+ |
* are met: |
253 |
+ |
* 1. Redistributions of source code must retain the above copyright |
254 |
+ |
* notice, this list of conditions and the following disclaimer. |
255 |
+ |
* 2. Redistributions in binary form must reproduce the above copyright |
256 |
+ |
* notice, this list of conditions and the following disclaimer in the |
257 |
+ |
* documentation and/or other materials provided with the distribution. |
258 |
+ |
* 3. The name of the author may not be used to endorse or promote products |
259 |
+ |
* derived from this software without specific prior written permission. |
260 |
+ |
* |
261 |
+ |
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, |
262 |
+ |
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY |
263 |
+ |
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL |
264 |
+ |
* THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
265 |
+ |
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
266 |
+ |
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
267 |
+ |
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
268 |
+ |
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
269 |
+ |
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
270 |
+ |
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
271 |
+ |
*/ |
272 |
+ |
|
273 |
+ |
/* |
274 |
+ |
* Copy src to string dst of size siz. At most siz-1 characters |
275 |
+ |
* will be copied. Always NUL terminates (unless siz == 0). |
276 |
+ |
* Returns strlen(src); if retval >= siz, truncation occurred. |
277 |
+ |
*/ |
278 |
+ |
size_t |
279 |
+ |
strlcpy(dst, src, siz) |
280 |
+ |
char *dst; |
281 |
+ |
const char *src; |
282 |
+ |
size_t siz; |
283 |
+ |
{ |
284 |
+ |
register char *d = dst; |
285 |
+ |
register const char *s = src; |
286 |
+ |
register size_t n = siz; |
287 |
+ |
|
288 |
+ |
/* Copy as many bytes as will fit */ |
289 |
+ |
if (n != 0 && --n != 0) { |
290 |
+ |
do { |
291 |
+ |
if ((*d++ = *s++) == 0) |
292 |
+ |
break; |
293 |
+ |
} while (--n != 0); |
294 |
+ |
} |
295 |
+ |
|
296 |
+ |
/* Not enough room in dst, add NUL and traverse rest of src */ |
297 |
+ |
if (n == 0) { |
298 |
+ |
if (siz != 0) |
299 |
+ |
*d = '\0'; /* NUL-terminate dst */ |
300 |
+ |
while (*s++) |
301 |
+ |
; |
302 |
+ |
} |
303 |
+ |
|
304 |
+ |
return(s - src - 1); /* count does not include NUL */ |
305 |
+ |
} |
306 |
+ |
|
307 |
+ |
#endif |
308 |
+ |
|
309 |
|
|
310 |
|
FILE *create_tcp_connection(char *hostname, int port){ |
311 |
|
int sock; |