Skip to content

Commit 41bbb89

Browse files
committed
mingw32
1 parent fec01df commit 41bbb89

24 files changed

+656
-34
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*.la
55
.deps
66
.libs
7+
*.exe
78
src/ios_webkit_debug_proxy
89
examples/dl_client
910
examples/wi_client

configure.ac

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,34 @@ AC_TYPE_UINT64_T
4141
AC_TYPE_UINT8_T
4242

4343
# Checks for library functions.
44-
AC_FUNC_MALLOC
45-
AC_FUNC_REALLOC
46-
AC_CHECK_FUNCS([memmove memset regcomp select socket stpcpy strcasecmp strncasecmp strchr strdup strndup strrchr strstr strtol])
44+
AC_CHECK_FUNCS([malloc realloc memmove memset regcomp select socket stpcpy strcasecmp strncasecmp strchr strdup strndup strrchr strstr strtol strcasestr va_copy vasprintf asprintf stpncpy stpcpy strndup getline htobe64])
45+
46+
# Check for pcre presence if regex.h is absent
47+
AC_CHECK_HEADER(regex.h, [ac_have_regex_h="yes"], [ac_have_regex_h="no"])
48+
if test "x$ac_have_regex_h" = "xno"; then
49+
PKG_CHECK_MODULES(libpcreposix, libpcreposix, [], [AC_MSG_ERROR([Neither regex.h nor pcre headers were found])])
50+
else
51+
AC_DEFINE(HAVE_REGEX_H, 1, [regex.h is present])
52+
fi
53+
54+
# Check for operating system
55+
AC_MSG_CHECKING([whether to enable WIN32 build settings])
56+
case ${host_os} in
57+
*mingw32*|*cygwin*)
58+
win32=true
59+
AC_MSG_RESULT([yes])
60+
AC_DEFINE(WIN32_LEAN_AND_MEAN, 1, [Define to limit the scope of windows.h])
61+
AC_DEFINE(__USE_MINGW_ANSI_STDIO, 1, [Define to use C99 printf/snprintf in MinGW])
62+
;;
63+
*)
64+
win32=false
65+
AC_MSG_RESULT([no])
66+
;;
67+
esac
68+
AM_CONDITIONAL(WIN32, test x$win32 = xtrue)
69+
70+
# Check endianess
71+
AC_C_BIGENDIAN
4772

4873
AC_CONFIG_FILES([Makefile src/Makefile include/Makefile examples/Makefile])
4974

examples/dl_client.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,13 @@
99
#include <stdio.h>
1010
#include <stdlib.h>
1111
#include <string.h>
12+
#ifdef WIN32
13+
#define WIN32_LEAN_AND_MEAN 1
14+
#include <windows.h>
15+
#include <winsock2.h>
16+
#else
1217
#include <sys/socket.h>
18+
#endif
1319
#include <unistd.h>
1420

1521
#include "device_listener.h"

examples/wi_client.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,13 @@
1111
#include <stdio.h>
1212
#include <stdlib.h>
1313
#include <string.h>
14+
#ifdef WIN32
15+
#define WIN32_LEAN_AND_MEAN 1
16+
#include <windows.h>
17+
#include <winsock2.h>
18+
#else
1419
#include <sys/socket.h>
20+
#endif
1521
#include <unistd.h>
1622

1723
#include "webinspector.h"
@@ -121,7 +127,11 @@ int main(int argc, char **argv) {
121127
size_t buf_length = 1024;
122128
while (!quit_flag) {
123129
ssize_t read_bytes = recv(fd, buf, buf_length, 0);
130+
#ifndef WIN32
124131
if (read_bytes < 0 && errno == EWOULDBLOCK) {
132+
#else
133+
if (read_bytes && WSAGetLastError() != WSAEWOULDBLOCK) {
134+
#endif
125135
continue;
126136
}
127137
if (wi->on_recv(wi, buf, read_bytes)) {

examples/ws_echo1.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,29 @@
1212
#include "ws_echo_common.h"
1313
#include "websocket.h"
1414

15+
#ifdef WIN32
16+
#define WIN32_LEAN_AND_MEAN 1
17+
#include <windows.h>
18+
#include <winsock2.h>
19+
#else
1520
#include <sys/ioctl.h>
1621
#include <sys/socket.h>
1722
#include <arpa/inet.h>
23+
#endif
1824
#include <errno.h>
1925
#include <unistd.h>
2026

2127
#define BUF_LEN 1024
2228
#define PORT 8080
2329

2430
int main(int argc, char** argv) {
31+
#ifdef WIN32
32+
WSADATA wsa_data;
33+
if (WSAStartup(MAKEWORD(2,2), &wsa_data) != ERROR_SUCCESS) {
34+
fprintf(stderr, "WSAStartup failed!\n");
35+
ExitProcess(-1);
36+
}
37+
#endif
2538
int port = PORT;
2639

2740
int sfd = socket(AF_INET, SOCK_STREAM, 0);
@@ -38,7 +51,11 @@ int main(int argc, char** argv) {
3851
bind(sfd, (struct sockaddr*)&local, sizeof(local)) < 0 ||
3952
listen(sfd, 1)) {
4053
perror("Unable to bind");
54+
#ifndef WIN32
4155
close(sfd);
56+
#else
57+
closesocket(sfd);
58+
#endif
4259
return -1;
4360
}
4461

examples/ws_echo2.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,14 @@
1212
#include <string.h>
1313
#include <assert.h>
1414

15+
#ifdef WIN32
16+
#define WIN32_LEAN_AND_MEAN 1
17+
#include <windows.h>
18+
#include <winsock2.h>
19+
#else
1520
#include <sys/socket.h>
1621
#include <arpa/inet.h>
22+
#endif
1723
#include <errno.h>
1824

1925
#include "socket_manager.h"

examples/ws_echo_common.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,17 @@
1010
#include <stdio.h>
1111
#include <stdlib.h>
1212
#include <string.h>
13+
#ifdef WIN32
14+
#define WIN32_LEAN_AND_MEAN 1
15+
#include <windows.h>
16+
#include <winsock2.h>
17+
#else
1318
#include <sys/socket.h>
19+
#endif
1420

1521
#include "ws_echo_common.h"
1622
#include "websocket.h"
17-
23+
#include "asprintf.h"
1824

1925
// websocket callbacks:
2026

include/asprintf.h

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/*
2+
* Copyright (c) 2004 Darren Tucker.
3+
*
4+
* Based originally on asprintf.c from OpenBSD:
5+
* Copyright (c) 1997 Todd C. Miller <[email protected]>
6+
*
7+
* Permission to use, copy, modify, and distribute this software for any
8+
* purpose with or without fee is hereby granted, provided that the above
9+
* copyright notice and this permission notice appear in all copies.
10+
*
11+
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12+
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13+
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14+
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15+
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16+
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17+
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18+
*/
19+
20+
#ifndef __ASPRINTF_H
21+
#define __ASPRINTF_H
22+
23+
#ifdef HAVE_CONFIG_H
24+
#include <config.h>
25+
#endif
26+
27+
#include <stdarg.h>
28+
#include <limits.h>
29+
30+
#ifndef HAVE_VASPRINTF
31+
32+
#ifndef VA_COPY
33+
# ifdef HAVE_VA_COPY
34+
# define VA_COPY(dest, src) va_copy(dest, src)
35+
# else
36+
# ifdef HAVE___VA_COPY
37+
# define VA_COPY(dest, src) __va_copy(dest, src)
38+
# else
39+
# define VA_COPY(dest, src) (dest) = (src)
40+
# endif
41+
# endif
42+
#endif
43+
44+
#define INIT_SZ 128
45+
46+
static inline int vasprintf(char **str, const char *fmt, va_list ap)
47+
{
48+
int ret = -1;
49+
va_list ap2;
50+
char *string, *newstr;
51+
size_t len;
52+
53+
VA_COPY(ap2, ap);
54+
if ((string = malloc(INIT_SZ)) == NULL)
55+
goto fail;
56+
57+
ret = vsnprintf(string, INIT_SZ, fmt, ap2);
58+
if (ret >= 0 && ret < INIT_SZ) { /* succeeded with initial alloc */
59+
*str = string;
60+
} else if (ret == INT_MAX || ret < 0) { /* Bad length */
61+
free(string);
62+
goto fail;
63+
} else { /* bigger than initial, realloc allowing for nul */
64+
len = (size_t)ret + 1;
65+
if ((newstr = realloc(string, len)) == NULL) {
66+
free(string);
67+
goto fail;
68+
} else {
69+
va_end(ap2);
70+
VA_COPY(ap2, ap);
71+
ret = vsnprintf(newstr, len, fmt, ap2);
72+
if (ret >= 0 && (size_t)ret < len) {
73+
*str = newstr;
74+
} else { /* failed with realloc'ed string, give up */
75+
free(newstr);
76+
goto fail;
77+
}
78+
}
79+
}
80+
va_end(ap2);
81+
return (ret);
82+
83+
fail:
84+
*str = NULL;
85+
va_end(ap2);
86+
return (-1);
87+
}
88+
#endif
89+
90+
#ifndef HAVE_ASPRINTF
91+
static inline int asprintf(char **str, const char *fmt, ...)
92+
{
93+
va_list ap;
94+
int ret;
95+
96+
*str = NULL;
97+
va_start(ap, fmt);
98+
ret = vasprintf(str, fmt, ap);
99+
va_end(ap);
100+
101+
return ret;
102+
}
103+
#endif
104+
105+
#endif

include/getline.h

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/* Copyright (C) 1991, 1992, 1995, 1996, 1997 Free Software Foundation, Inc.
2+
This file is part of the GNU C Library.
3+
4+
The GNU C Library is free software; you can redistribute it and/or
5+
modify it under the terms of the GNU Lesser General Public
6+
License as published by the Free Software Foundation; either
7+
version 2.1 of the License, or (at your option) any later version.
8+
9+
The GNU C Library is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+
Lesser General Public License for more details.
13+
14+
You should have received a copy of the GNU Lesser General Public
15+
License along with the GNU C Library; if not, write to the Free
16+
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
17+
02111-1307 USA. */
18+
19+
#ifndef __GETLINE_H
20+
#define __GETLINE_H
21+
22+
#ifdef HAVE_CONFIG_H
23+
#include <config.h>
24+
#endif
25+
26+
#include <stdio.h>
27+
#include <stdlib.h>
28+
#include <string.h>
29+
30+
#ifndef HAVE_GETLINE
31+
static inline int getline(char **lineptr, size_t *n, FILE *stream)
32+
{
33+
if (lineptr == NULL || n == NULL)
34+
{
35+
return -1;
36+
}
37+
if (*lineptr == NULL || *n == 0)
38+
{
39+
*n = 120;
40+
*lineptr = (char *) malloc (*n);
41+
if (*lineptr == NULL)
42+
{
43+
return -1;
44+
}
45+
}
46+
if (fgets (*lineptr, *n, stream))
47+
return *n;
48+
else
49+
return -1;
50+
}
51+
#endif
52+
53+
#endif

include/rpc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ extern "C" {
1313
#endif
1414

1515
#include <plist/plist.h>
16+
#include <stdbool.h>
1617
#include <stdint.h>
1718
#include <stdlib.h>
1819

0 commit comments

Comments
 (0)