Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix several issues when building DDS on Windows with MinGW #6

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
a80846f
Merge pull request #1 from qeo/master
ivan-galvez Jul 8, 2016
94ee04b
Do not include Posix sys/socket.h.
ivan-galvez May 24, 2016
9600d27
Fix nonmatching types on Windows implementation of socket related fun…
ivan-galvez May 24, 2016
86fe7ad
Do not include arpa/inet.h on non-posix systems.
ivan-galvez May 24, 2016
29f71b0
Use C-style comments.
ivan-galvez May 24, 2016
07d26a6
Added BSD implementation of fnmatch for Windows systems.
ivan-galvez Jul 8, 2016
38a5b2d
Fix Mingw32 specific errors compiling on Windows.
ivan-galvez May 27, 2016
c4a4424
Initialize static mutex at acquisition.
ivan-galvez May 27, 2016
14371b3
Do not include poll.h on WIN32.
ivan-galvez May 31, 2016
fcec408
Do not redifine vsnprintf for MinGW compiler.
ivan-galvez May 31, 2016
c273ba3
Move MSG_NO_SIGNAL definition to header.
ivan-galvez May 31, 2016
c1bbc4f
Fixed several errors in Windows Dyn IP implementation.
ivan-galvez May 31, 2016
1a62c3c
Move implementation of static mutex creation to .c.
ivan-galvez Jun 1, 2016
b8689a0
Export 'fatal' simbol used on several tests.
ivan-galvez Jun 1, 2016
1c700d3
Only build gettimeofday on Visual Studio.
ivan-galvez Jun 1, 2016
2f1f159
Patch for usleep in Windows
santiagomayoral Jun 2, 2016
c60a3e3
Add missing header to build certain tests on Windows.
ivan-galvez Jun 2, 2016
a8fc64f
Additional guards to build api test on Windows.
ivan-galvez Jun 2, 2016
2e23f76
Export additional symbols required to build test partitions.
ivan-galvez Jun 3, 2016
7e95d86
Fixed compilation of test chat on Windows.
ivan-galvez Jun 3, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions dds/api/headers/dds/dds_debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#define __dds_debug_h_

#include "dds/dds_error.h"
#include "dds/dds_aux.h"
#ifdef XTYPES_USED
#include "dds/dds_xtypes.h"
#endif
Expand Down
2 changes: 2 additions & 0 deletions dds/apps/chat/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
#include <string.h>
#include <ctype.h>
#include <unistd.h>
#ifndef _WIN32
#include <poll.h>
#endif
#include "thread.h"
#include "libx.h"
#include "tty.h"
Expand Down
4 changes: 3 additions & 1 deletion dds/src/bgns/bgns.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
/* bgns.c -- Implements the Background Notification Server functionality. */

#include <stdint.h>
#include <arpa/inet.h>
#ifndef _WIN32
# include <arpa/inet.h>
#endif /* _WIN32 */
#include "log.h"
#include "list.h"
#include "error.h"
Expand Down
199 changes: 199 additions & 0 deletions dds/src/co/fnmatch.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
/*
* Copyright (c) 1989, 1993, 1994
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Guido van Rossum.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* From FreeBSD fnmatch.c 1.11
* $Id: fnmatch.c,v 1.3 1997/08/19 02:34:30 jdp Exp $
*/

#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "@(#)fnmatch.c 8.2 (Berkeley) 4/16/94";
#endif /* LIBC_SCCS and not lint */

/*
* Function fnmatch() as specified in POSIX 1003.2-1992, section B.6.
* Compares a filename or pathname to a pattern.
*/

#include <ctype.h>
#include <string.h>
#include <stdio.h>

#include "fnmatch.h"

#define EOS '\0'

static const char *rangematch(const char *, char, int);

int
fnmatch(const char *pattern, const char *string, int flags)
{
const char *stringstart;
char c, test;

for (stringstart = string;;)
switch (c = *pattern++) {
case EOS:
if ((flags & FNM_LEADING_DIR) && *string == '/')
return (0);
return (*string == EOS ? 0 : FNM_NOMATCH);
case '?':
if (*string == EOS)
return (FNM_NOMATCH);
if (*string == '/' && (flags & FNM_PATHNAME))
return (FNM_NOMATCH);
if (*string == '.' && (flags & FNM_PERIOD) &&
(string == stringstart ||
((flags & FNM_PATHNAME) && *(string - 1) == '/')))
return (FNM_NOMATCH);
++string;
break;
case '*':
c = *pattern;
/* Collapse multiple stars. */
while (c == '*')
c = *++pattern;

if (*string == '.' && (flags & FNM_PERIOD) &&
(string == stringstart ||
((flags & FNM_PATHNAME) && *(string - 1) == '/')))
return (FNM_NOMATCH);

/* Optimize for pattern with * at end or before /. */
if (c == EOS)
if (flags & FNM_PATHNAME)
return ((flags & FNM_LEADING_DIR) ||
strchr(string, '/') == NULL ?
0 : FNM_NOMATCH);
else
return (0);
else if (c == '/' && flags & FNM_PATHNAME) {
if ((string = strchr(string, '/')) == NULL)
return (FNM_NOMATCH);
break;
}

/* General case, use recursion. */
while ((test = *string) != EOS) {
if (!fnmatch(pattern, string, flags & ~FNM_PERIOD))
return (0);
if (test == '/' && flags & FNM_PATHNAME)
break;
++string;
}
return (FNM_NOMATCH);
case '[':
if (*string == EOS)
return (FNM_NOMATCH);
if (*string == '/' && flags & FNM_PATHNAME)
return (FNM_NOMATCH);
if ((pattern =
rangematch(pattern, *string, flags)) == NULL)
return (FNM_NOMATCH);
++string;
break;
case '\\':
if (!(flags & FNM_NOESCAPE)) {
if ((c = *pattern++) == EOS) {
c = '\\';
--pattern;
}
}
/* FALLTHROUGH */
default:
if (c == *string)
;
else if ((flags & FNM_CASEFOLD) &&
(tolower((unsigned char)c) ==
tolower((unsigned char)*string)))
;
else if ((flags & FNM_PREFIX_DIRS) && *string == EOS &&
((c == '/' && string != stringstart) ||
(string == stringstart+1 && *stringstart == '/')))
return (0);
else
return (FNM_NOMATCH);
string++;
break;
}
/* NOTREACHED */
}

static const char *
rangematch(const char *pattern, char test, int flags)
{
int negate, ok;
char c, c2;

/*
* A bracket expression starting with an unquoted circumflex
* character produces unspecified results (IEEE 1003.2-1992,
* 3.13.2). This implementation treats it like '!', for
* consistency with the regular expression syntax.
* J.T. Conklin ([email protected])
*/
if ( (negate = (*pattern == '!' || *pattern == '^')) )
++pattern;

if (flags & FNM_CASEFOLD)
test = tolower((unsigned char)test);

for (ok = 0; (c = *pattern++) != ']';) {
if (c == '\\' && !(flags & FNM_NOESCAPE))
c = *pattern++;
if (c == EOS)
return (NULL);

if (flags & FNM_CASEFOLD)
c = tolower((unsigned char)c);

if (*pattern == '-'
&& (c2 = *(pattern+1)) != EOS && c2 != ']') {
pattern += 2;
if (c2 == '\\' && !(flags & FNM_NOESCAPE))
c2 = *pattern++;
if (c2 == EOS)
return (NULL);

if (flags & FNM_CASEFOLD)
c2 = tolower((unsigned char)c2);

if ((unsigned char)c <= (unsigned char)test &&
(unsigned char)test <= (unsigned char)c2)
ok = 1;
} else if (c == test)
ok = 1;
}
return (ok == negate ? NULL : pattern);
}
3 changes: 2 additions & 1 deletion dds/src/co/libx.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <stdarg.h>
#include <string.h>
#include "libx.h"
#include "dds/dds_error.h"

/* astrcmp -- Compare two strings for equality but do it case independent. */

Expand Down Expand Up @@ -62,7 +63,7 @@ int astrncmp (const char *s1, const char *s2, size_t n)
}


void fatal (const char *fmt, ...)
DDS_EXPORT void fatal (const char *fmt, ...)
{
va_list arg;

Expand Down
5 changes: 2 additions & 3 deletions dds/src/co/sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <unistd.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <sys/socket.h>
#ifdef __linux__
#include <sys/epoll.h>
#define EPOLL_USED
Expand All @@ -45,7 +46,6 @@
#include "debug.h"
#include "sock.h"
#include <sys/types.h>
#include <sys/socket.h>

static int n_ready;
static lock_t sock_lock;
Expand Down Expand Up @@ -352,7 +352,7 @@ int sock_fd_event_socket (SOCKET s, short events, int set)

/* sock_fd_udata_socket -- Update the notified user data on a socket. */

int sock_fd_udata_socket (SOCKET s, void *udata)
void sock_fd_udata_socket (SOCKET s, void *udata)
{
unsigned i;
SockSocket_t *sp;
Expand All @@ -364,7 +364,6 @@ int sock_fd_udata_socket (SOCKET s, void *udata)
break;
}
lock_release (sock_lock);
return (0);
}

/* sock_fd_schedule -- Schedule all pending event handlers. */
Expand Down
17 changes: 15 additions & 2 deletions dds/src/co/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -451,10 +451,10 @@ void rcl_done (void *p)
}

#else

#ifndef _WIN32
void rcl_access (void *p) {}
void rcl_done (void *p) {}

#endif /* _WIN32 */
#endif /* PTHREADS_USED */

#ifdef _WIN32
Expand All @@ -469,6 +469,19 @@ void rcl_done (void *p) {}
#define ev_signal(ev) SetEvent (ev)
#define ev_destroy(ev) CloseHandle (ev)

int emulate_pthread_mutex_lock(volatile lock_t *mx)
{
if (*mx == NULL) /* Static Initializer */
{
lock_t p = CreateMutex (NULL, 0, /*s*/NULL);
if ( InterlockedCompareExchangePointer( (PVOID *)mx, (PVOID)p, NULL) != NULL )
{
CloseHandle(p);
}
}
return WaitForSingleObject (*mx, INFINITE) == WAIT_FAILED;
}

static lock_t rclock;

int dds_cond_broadcast (cond_t *cv)
Expand Down
2 changes: 1 addition & 1 deletion dds/src/co/tty.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
#ifndef _WIN32
#include <unistd.h>
#include <termios.h>
#include <poll.h>
#endif
#include <stdarg.h>
#include <stdint.h>
#include <poll.h>
#include "libx.h"
#include "dds/dds_aux.h"
#include "tty.h"
Expand Down
47 changes: 25 additions & 22 deletions dds/src/co/win.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,6 @@

#ifdef _WIN32

void usleep (long usec)
{
LARGE_INTEGER lFrequency;
LARGE_INTEGER lEndTime;
LARGE_INTEGER lCurTime;

if (usec >= 1000) {
Sleep (usec / 1000); /* Don't bother with us accuracy. */
return;
}
QueryPerformanceFrequency (&lFrequency);
if (lFrequency.QuadPart) {
QueryPerformanceCounter (&lEndTime);
lEndTime.QuadPart += (LONGLONG) usec * lFrequency.QuadPart / 1000000;
do {
QueryPerformanceCounter (&lCurTime);
Sleep(0);
}
while (lCurTime.QuadPart < lEndTime.QuadPart);
}
}

static LARGE_INTEGER get_filetime_offset (void)
{
SYSTEMTIME s;
Expand Down Expand Up @@ -106,6 +84,30 @@ int clock_gettime (int X, struct timespec *tv)
return (0);
}

#if _MSC_VER /* Only available on MS Visual Studio */

void usleep (long usec)
{
LARGE_INTEGER lFrequency;
LARGE_INTEGER lEndTime;
LARGE_INTEGER lCurTime;

if (usec >= 1000) {
Sleep (usec / 1000); /* Don't bother with us accuracy. */
return;
}
QueryPerformanceFrequency (&lFrequency);
if (lFrequency.QuadPart) {
QueryPerformanceCounter (&lEndTime);
lEndTime.QuadPart += (LONGLONG) usec * lFrequency.QuadPart / 1000000;
do {
QueryPerformanceCounter (&lCurTime);
Sleep(0);
}
while (lCurTime.QuadPart < lEndTime.QuadPart);
}
}

int gettimeofday (struct timeval *tv, struct timezone *tz)
{
struct timespec ts;
Expand All @@ -127,5 +129,6 @@ int gettimeofday (struct timeval *tv, struct timezone *tz)
}
return (0);
}
#endif /* _MSC_VER */

#endif /* _WIN32 */
Loading