Use monotonic time source if available.
[platform/upstream/c-ares.git] / windows_port.c
1 #include "setup.h"
2
3 /* $Id$ */
4
5 /* only do the following on windows
6  */
7 #if (defined(WIN32) || defined(WATT32)) && !defined(MSDOS)
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <ctype.h>
11 #include <string.h>
12 #include <errno.h>
13 #include <malloc.h>
14
15 #ifdef WATT32
16 #include <sys/socket.h>
17 #else
18 #include "nameser.h"
19 #endif
20 #include "ares.h"
21 #include "ares_private.h"
22
23 #ifdef __WATCOMC__
24 /*
25  * Watcom needs a DllMain() in order to initialise the clib startup code.
26  */
27 BOOL
28 WINAPI DllMain (HINSTANCE hnd, DWORD reason, LPVOID reserved)
29 {
30   (void) hnd;
31   (void) reason;
32   (void) reserved;
33   return (TRUE);
34 }
35 #endif
36
37 #ifndef __MINGW32__
38 int
39 ares_strncasecmp(const char *a, const char *b, int n)
40 {
41     int i;
42
43     for (i = 0; i < n; i++) {
44         int c1 = ISUPPER(a[i]) ? tolower(a[i]) : a[i];
45         int c2 = ISUPPER(b[i]) ? tolower(b[i]) : b[i];
46         if (c1 != c2) return c1-c2;
47     }
48     return 0;
49 }
50
51 int
52 ares_strcasecmp(const char *a, const char *b)
53 {
54     return strncasecmp(a, b, strlen(a)+1);
55 }
56 #endif
57
58 int
59 ares_writev (ares_socket_t s, const struct iovec *vector, size_t count)
60 {
61   char *buffer, *bp;
62   size_t i, bytes = 0;
63
64   /* Find the total number of bytes to write
65    */
66   for (i = 0; i < count; i++)
67       bytes += vector[i].iov_len;
68
69   if (bytes == 0)   /* not an error */
70      return (0);
71
72   /* Allocate a temporary buffer to hold the data
73    */
74   buffer = bp = (char*) alloca (bytes);
75   if (!buffer)
76   {
77     SET_ERRNO(ENOMEM);
78     return (-1);
79   }
80
81   /* Copy the data into buffer.
82    */
83   for (i = 0; i < count; ++i)
84   {
85     memcpy (bp, vector[i].iov_base, vector[i].iov_len);
86     bp += vector[i].iov_len;
87   }
88   return (int)swrite(s, buffer, bytes);
89 }
90 #endif /* WIN32 builds only */