Skip to content

Commit b50ab10

Browse files
authored
Merge pull request #193 from google/mingw64
mingw64
2 parents 7a49227 + 8d7f920 commit b50ab10

23 files changed

+552
-31
lines changed

configure.ac

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,32 @@ AC_TYPE_UINT8_T
5151
# Checks for library functions.
5252
AC_FUNC_MALLOC
5353
AC_FUNC_REALLOC
54-
AC_CHECK_FUNCS([memmove memset regcomp select socket stpcpy strcasecmp strncasecmp strchr strdup strndup strrchr strstr strtol])
54+
55+
# Check for operating system
56+
AC_MSG_CHECKING([whether to enable WIN32 build settings])
57+
case ${host_os} in
58+
*mingw*|*msys*|*cygwin*)
59+
win32=true
60+
AC_MSG_RESULT([yes])
61+
AC_DEFINE(WIN32_LEAN_AND_MEAN, 1, [Define to limit the scope of windows.h])
62+
AC_DEFINE(__USE_MINGW_ANSI_STDIO, 1, [Define to use C99 printf/snprintf in MinGW])
63+
;;
64+
*)
65+
win32=false
66+
AC_MSG_RESULT([no])
67+
;;
68+
esac
69+
AM_CONDITIONAL(WIN32, test "x$win32" = "xtrue")
70+
71+
# Check for pcre presence if regex.h is absent
72+
AC_CHECK_HEADER(regex.h, [ac_have_regex_h="yes"], [ac_have_regex_h="no"])
73+
if test "x$ac_have_regex_h" = "xno"; then
74+
PKG_CHECK_MODULES(libpcreposix, libpcreposix, [], [AC_MSG_ERROR([Neither regex.h nor pcre headers were found])])
75+
else
76+
AC_DEFINE(HAVE_REGEX_H, 1, [regex.h is present])
77+
fi
78+
79+
AC_CHECK_FUNCS([memmove memset regcomp select socket strcasecmp strncasecmp strchr strdup strndup strrchr strstr strtol strcasestr getline])
5580

5681
SAVE_CFLAGS=$CFLAGS
5782
CFLAGS="$CFLAGS $libimobiledevice_CFLAGS"

examples/dl_client.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
// An example device_listener client
66
//
77

8+
#ifdef HAVE_CONFIG_H
9+
#include <config.h>
10+
#endif
11+
812
#include <errno.h>
913
#include <stdio.h>
1014
#include <stdlib.h>

examples/wi_client.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
// A minimal webinspector client
66
//
77

8+
#ifdef HAVE_CONFIG_H
9+
#include <config.h>
10+
#endif
11+
812
#include <errno.h>
913
#include <signal.h>
1014
#include <stdbool.h>

examples/ws_echo1.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
// A minimal websocket "echo" server
66
//
77

8+
#ifdef HAVE_CONFIG_H
9+
#include <config.h>
10+
#endif
11+
812
#include <stdio.h>
913
#include <stdlib.h>
1014
#include <string.h>

examples/ws_echo2.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
// A select-based websocket "echo" server
66
//
77

8+
#ifdef HAVE_CONFIG_H
9+
#include <config.h>
10+
#endif
11+
812
#include <signal.h>
913
#include <stdbool.h>
1014
#include <stdio.h>

examples/ws_echo_common.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
// A minimal websocket "echo" server
66
//
77

8+
#ifdef HAVE_CONFIG_H
9+
#include <config.h>
10+
#endif
11+
812
#define _GNU_SOURCE
913
#include <stdbool.h>
1014
#include <stdio.h>

include/getline.h

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
/* getline.c -- Replacement for GNU C library function getline
2+
3+
Copyright (C) 1993 Free Software Foundation, Inc.
4+
5+
This program is free software; you can redistribute it and/or
6+
modify it under the terms of the GNU General Public License as
7+
published by the Free Software Foundation; either version 2 of the
8+
License, or (at your option) any later version.
9+
10+
This program is distributed in the hope that it will be useful, but
11+
WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
General Public License for more details. */
14+
15+
/* Written by Jan Brittenson, [email protected]. */
16+
17+
#ifndef __GETLINE_H
18+
#define __GETLINE_H
19+
20+
#ifdef HAVE_CONFIG_H
21+
#include <config.h>
22+
#endif
23+
24+
#include <sys/types.h>
25+
#include <stdio.h>
26+
#include <assert.h>
27+
#include <errno.h>
28+
29+
#ifndef HAVE_GETLINE
30+
/* Always add at least this many bytes when extending the buffer. */
31+
#define GETLINE_MIN_CHUNK 256
32+
33+
static inline int getstr(char **lineptr, size_t *n, FILE *stream,
34+
char terminator, int offset) {
35+
int nchars_avail; /* Allocated but unused chars in *LINEPTR. */
36+
char *read_pos; /* Where we're reading into *LINEPTR. */
37+
int ret;
38+
39+
if (!lineptr || !n || !stream)
40+
{
41+
errno = EINVAL;
42+
return -1;
43+
}
44+
45+
if (!*lineptr)
46+
{
47+
*n = GETLINE_MIN_CHUNK;
48+
*lineptr = malloc (*n);
49+
if (!*lineptr)
50+
{
51+
errno = ENOMEM;
52+
return -1;
53+
}
54+
}
55+
56+
nchars_avail = *n - offset;
57+
read_pos = *lineptr + offset;
58+
59+
for (;;)
60+
{
61+
int save_errno;
62+
register int c = getc (stream);
63+
64+
save_errno = errno;
65+
66+
/* We always want at least one char left in the buffer, since we
67+
always (unless we get an error while reading the first char)
68+
NUL-terminate the line buffer. */
69+
70+
assert((*lineptr + *n) == (read_pos + nchars_avail));
71+
if (nchars_avail < 2)
72+
{
73+
if (*n > GETLINE_MIN_CHUNK)
74+
*n *= 2;
75+
else
76+
*n += GETLINE_MIN_CHUNK;
77+
78+
nchars_avail = *n + *lineptr - read_pos;
79+
*lineptr = realloc (*lineptr, *n);
80+
if (!*lineptr)
81+
{
82+
errno = ENOMEM;
83+
return -1;
84+
}
85+
read_pos = *n - nchars_avail + *lineptr;
86+
assert((*lineptr + *n) == (read_pos + nchars_avail));
87+
}
88+
89+
if (ferror (stream))
90+
{
91+
/* Might like to return partial line, but there is no
92+
place for us to store errno. And we don't want to just
93+
lose errno. */
94+
errno = save_errno;
95+
return -1;
96+
}
97+
98+
if (c == EOF)
99+
{
100+
/* Return partial line, if any. */
101+
if (read_pos == *lineptr)
102+
return -1;
103+
else
104+
break;
105+
}
106+
107+
*read_pos++ = c;
108+
nchars_avail--;
109+
110+
if (c == terminator)
111+
/* Return the line. */
112+
break;
113+
}
114+
115+
/* Done - NUL terminate and return the number of chars read. */
116+
*read_pos = '\0';
117+
118+
ret = read_pos - (*lineptr + offset);
119+
return ret;
120+
}
121+
122+
static inline int getline(char **lineptr, size_t *n, FILE *stream)
123+
{
124+
return getstr(lineptr, n, stream, '\n', 0);
125+
}
126+
#endif
127+
128+
#endif

include/strcasestr.h

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*-
2+
* Copyright (c) 1990, 1993
3+
* The Regents of the University of California. All rights reserved.
4+
*
5+
* This code is derived from software contributed to Berkeley by
6+
* Chris Torek.
7+
*
8+
* Redistribution and use in source and binary forms, with or without
9+
* modification, are permitted provided that the following conditions
10+
* are met:
11+
* 1. Redistributions of source code must retain the above copyright
12+
* notice, this list of conditions and the following disclaimer.
13+
* 2. Redistributions in binary form must reproduce the above copyright
14+
* notice, this list of conditions and the following disclaimer in the
15+
* documentation and/or other materials provided with the distribution.
16+
* 3. All advertising materials mentioning features or use of this software
17+
* must display the following acknowledgement:
18+
* This product includes software developed by the University of
19+
* California, Berkeley and its contributors.
20+
* 4. Neither the name of the University nor the names of its contributors
21+
* may be used to endorse or promote products derived from this software
22+
* without specific prior written permission.
23+
*
24+
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27+
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30+
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32+
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33+
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34+
* SUCH DAMAGE.
35+
*/
36+
37+
#ifndef __STRCASESTR_H
38+
#define __STRCASESTR_H
39+
40+
#ifdef HAVE_CONFIG_H
41+
#include <config.h>
42+
#endif
43+
44+
#include <ctype.h>
45+
#include <string.h>
46+
47+
#ifndef HAVE_STRCASESTR
48+
static inline char* strcasestr(const char *s, const char *find)
49+
{
50+
char c, sc;
51+
size_t len;
52+
53+
if ((c = *find++) != 0) {
54+
c = tolower((unsigned char)c);
55+
len = strlen(find);
56+
do {
57+
do {
58+
if ((sc = *s++) == 0)
59+
return (NULL);
60+
} while ((char)tolower((unsigned char)sc) != c);
61+
} while (strncasecmp(s, find, len) != 0);
62+
s--;
63+
}
64+
return ((char *)s);
65+
}
66+
#endif
67+
68+
#endif

include/strndup.h

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/* Implement the strndup function.
2+
Copyright (C) 2005 Free Software Foundation, Inc.
3+
Written by Kaveh R. Ghazi <[email protected]>.
4+
5+
This file is part of the libiberty library.
6+
Libiberty is free software; you can redistribute it and/or
7+
modify it under the terms of the GNU Library General Public
8+
License as published by the Free Software Foundation; either
9+
version 2 of the License, or (at your option) any later version.
10+
11+
Libiberty is distributed in the hope that it will be useful,
12+
but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+
Library General Public License for more details.
15+
16+
You should have received a copy of the GNU Library General Public
17+
License along with libiberty; see the file COPYING.LIB. If
18+
not, write to the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
19+
Boston, MA 02110-1301, USA. */
20+
21+
#ifndef __STRNDUP_H
22+
#define __STRNDUP_H
23+
24+
#ifdef HAVE_CONFIG_H
25+
#include <config.h>
26+
#endif
27+
28+
#include <string.h>
29+
30+
#ifndef HAVE_STRNDUP
31+
static inline char* strndup(const char *s, size_t n)
32+
{
33+
char *result;
34+
size_t len = strlen (s);
35+
36+
if (n < len)
37+
len = n;
38+
39+
result = (char *) malloc (len + 1);
40+
if (!result)
41+
return 0;
42+
43+
result[len] = '\0';
44+
return (char *) memcpy (result, s, len);
45+
}
46+
#endif
47+
48+
#endif
File renamed without changes.

src/Makefile.am

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/include/ios-webkit-debug-proxy
55

6-
AM_CFLAGS = $(GLOBAL_CFLAGS) $(libimobiledevice_CFLAGS) $(libplist_CFLAGS)
7-
AM_LDFLAGS = $(libimobiledevice_LIBS) $(libplist_LIBS)
6+
AM_CFLAGS = $(GLOBAL_CFLAGS) $(libimobiledevice_CFLAGS) $(libplist_CFLAGS) $(libpcreposix_CFLAGS)
7+
AM_LDFLAGS = $(libimobiledevice_LIBS) $(libplist_LIBS) $(libpcreposix_LIBS)
88

99
lib_LTLIBRARIES = libios_webkit_debug_proxy.la
1010
libios_webkit_debug_proxy_la_LIBADD =

src/base64.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@
2929

3030
#if defined(POLARSSL_BASE64_C)
3131

32+
#ifdef HAVE_CONFIG_H
33+
#include <config.h>
34+
#endif
35+
3236
//#include "polarssl/base64.h"
3337
#include "base64.h"
3438
#include "stdio.h"

src/char_buffer.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
// Google BSD license https://developers.google.com/google-bsd-license
22
// Copyright 2012 Google Inc. [email protected]
33

4+
#ifdef HAVE_CONFIG_H
5+
#include <config.h>
6+
#endif
7+
48
#include <math.h>
59
#include <stdio.h>
610
#include <stdlib.h>

0 commit comments

Comments
 (0)