Skip to content

Commit 45afde6

Browse files
committed
all: Build fixes for MSVC.
This is a very old set of changes, implementing better MSVC support. At this point I don't know if it's enough; probably there are still more changes needed to get things to work on MSVC, but it's a big step in the right direction, and it's better to commit this rather than keep it lying around forever in my working copy.
1 parent 9733f59 commit 45afde6

File tree

13 files changed

+80
-18
lines changed

13 files changed

+80
-18
lines changed

src/csnip/CMakeLists.txt

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ set(CSNIP_CONF__SUPPORT_THREADING ${SUPPORT_THREADING})
99
# Check for various types & APIs in libc and provided
1010
# libraries.
1111

12+
include(CheckIncludeFiles)
1213
include(CheckSymbolExists)
1314
include(CheckStructHasMember)
1415
include(CheckTypeSize)
@@ -34,6 +35,8 @@ endif ()
3435

3536
check_include_file("io.h" CSNIP_CONF__HAVE_IO_H)
3637
check_include_file("unistd.h" CSNIP_CONF__HAVE_UNISTD_H)
38+
check_include_file("sys/select.h" CSNIP_CONF__HAVE_SYS_SELECT_H)
39+
check_include_file("WinSock2.h" CSNIP_CONF__HAVE_WINSOCK2_H)
3740

3841
# Check for symbols
3942

@@ -82,7 +85,7 @@ set(CMAKE_REQUIRED_DEFINITIONS
8285
check_symbol_exists(strerror_r "string.h"
8386
CSNIP_CONF__HAVE_STRERROR_R)
8487
unset(CMAKE_REQUIRED_DEFINITIONS)
85-
check_symbol_exists(strerror_s "sec_api/string_s.h"
88+
check_symbol_exists(strerror_s "string.h"
8689
CSNIP_CONF__HAVE_STRERROR_S)
8790
check_symbol_exists(strtok_r "string.h"
8891
CSNIP_CONF__HAVE_STRTOK_R)
@@ -91,14 +94,21 @@ check_struct_has_member("struct timespec" tv_sec "time.h"
9194
check_symbol_exists(timespec_get "time.h"
9295
CSNIP_CONF__HAVE_TIMESPEC_GET)
9396
check_struct_has_member("struct timeval" tv_sec "sys/time.h"
94-
CSNIP_CONF__HAVE_TIMEVAL)
97+
timeval_in_sys_time)
98+
check_struct_has_member("struct timeval" tv_sec
99+
"WinSock2.h" timeval_in_winsock2)
100+
if (timeval_in_sys_time OR timeval_in_winsock2)
101+
set(CSNIP_CONF__HAVE_TIMEVAL 1)
102+
endif ()
95103
check_symbol_exists(writev "sys/uio.h"
96104
CSNIP_CONF__HAVE_WRITEV)
97105
set(CMAKE_REQUIRED_DEFINITIONS "-D_GNU_SOURCE")
98106
check_symbol_exists(vasprintf "stdio.h"
99107
CSNIP_CONF__HAVE_VASPRINTF)
100108
unset(CMAKE_REQUIRED_DEFINITIONS)
101-
109+
check_symbol_exists(Sleep "windows.h"
110+
CSNIP_CONF__HAVE_WIN32_SLEEP)
111+
102112
set(CSNIP_CONF__HAVE_UNLOCKED_STDIO 0)
103113
if (${CSNIP_CONF__HAVE_FLOCKFILE}
104114
AND ${CSNIP_CONF__HAVE_FUNLOCKFILE}

src/csnip/csnip_conf.h.in

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,11 @@
4343

4444
#cmakedefine CSNIP_CONF__HAVE_SSIZE_T
4545
#cmakedefine CSNIP_CONF__HAVE_STDINT_H
46+
#cmakedefine CSNIP_CONF__HAVE_SYS_SELECT_H
4647
#cmakedefine CSNIP_CONF__HAVE_SYS_TYPES_H
48+
#cmakedefine CSNIP_CONF__HAVE_SYS_TIME_H
4749
#cmakedefine CSNIP_CONF__HAVE_UNISTD_H
50+
#cmakedefine CSNIP_CONF__HAVE_WINSOCK2_H
4851
#cmakedefine CSNIP_CONF__HAVE_IO_H
4952

5053
/** Macros for individual libc functions */
@@ -62,6 +65,7 @@
6265
#cmakedefine CSNIP_CONF__HAVE_GETLINE
6366
#cmakedefine CSNIP_CONF__HAVE_GETOPT
6467
#cmakedefine CSNIP_CONF__HAVE_MEMALIGN
68+
#cmakedefine CSNIP_CONF__HAVE_NANOSLEEP
6569
#cmakedefine CSNIP_CONF__HAVE_POSIX_MEMALIGN
6670
#cmakedefine CSNIP_CONF__HAVE_PUTC_UNLOCKED
6771
#cmakedefine CSNIP_CONF__HAVE_READV
@@ -74,6 +78,7 @@
7478
#cmakedefine CSNIP_CONF__HAVE_TIMESPEC_GET
7579
#cmakedefine CSNIP_CONF__HAVE_TIMEVAL
7680
#cmakedefine CSNIP_CONF__HAVE_VASPRINTF
81+
#cmakedefine CSNIP_CONF__HAVE_WIN32_SLEEP
7782
#cmakedefine CSNIP_CONF__HAVE_WRITEV
7883

7984
/** Macros for groups */

src/csnip/log.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
#include <csnip/csnip_conf.h>
2-
31
#include <errno.h>
42
#include <stdarg.h>
53
#include <stdio.h>
64
#include <string.h>
75
#include <stdlib.h>
86
#include <stdbool.h>
97

8+
#include <csnip/csnip_conf.h>
9+
#ifdef CSNIP_CONF__HAVE_SYS_TYPES_H
1010
#include <sys/types.h>
11+
#endif
1112
#ifdef CSNIP_CONF__HAVE_REGCOMP
1213
#include <regex.h>
1314
#endif

src/csnip/time.c

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,21 @@
1-
#include <sys/time.h>
1+
#include <time.h>
2+
3+
#include <csnip/csnip_conf.h>
4+
#ifndef CSNIP_CONF__HAVE_NANOSLEEP
5+
/* Access Win32's Sleep() */
6+
# ifdef CSNIP_CONF__HAVE_WIN32_SLEEP
7+
# define WIN32_LEAN_AND_MEAN
8+
# include <windows.h>
9+
# endif
10+
11+
/* Get select() for UNIX platforms that don't have nanosleep.
12+
* Note that we can't use WinSock's select() since that requires
13+
* library initialization, which the app may not have performed.
14+
*/
15+
# ifdef CSNIP_CONF__HAVE_SYS_SELECT_H
16+
# include <sys/select.h>
17+
# endif
18+
#endif
219

320
#include "time.h"
421

@@ -53,7 +70,17 @@ struct timeval csnip_time_timespec_as_timeval(struct timespec ts)
5370

5471
int csnip_time_sleep(struct timespec ts)
5572
{
56-
int err = nanosleep(&ts, NULL);
73+
int err = 0;
74+
#if defined(CSNIP_CONF__HAVE_NANOSLEEP)
75+
err = nanosleep(&ts, NULL);
76+
#elif defined(CSNIP_CONF__HAVE_WIN32_SLEEP)
77+
DWORD msec = ts.tv_nsec / 1000000;
78+
msec += (DWORD)(ts.tv_sec * 1000);
79+
Sleep(msec);
80+
#else
81+
struct timeval tv = csnip_time_timespec_as_timeval(ts);
82+
err = select(0, NULL, NULL, NULL, &tv);
83+
#endif
5784
if (err != 0) {
5885
return csnip_err_ERRNO;
5986
}

src/csnip/time.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,13 @@
5151
#include <csnip/csnip_conf.h>
5252

5353
#include <time.h>
54-
#ifdef CSNIP_CONF__HAVE_TIMEVAL
54+
55+
#ifdef CSNIP_CONF__HAVE_SYS_TIME_H
5556
#include <sys/time.h>
5657
#endif
58+
#if defined(CSNIP_CONF__HAVE_WINSOCK2_H)
59+
#include <WinSock2.h>
60+
#endif
5761

5862
#include <csnip/err.h>
5963

src/csnip/x.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* csnip's wrapper.
1414
*/
1515

16+
#include <limits.h>
1617
#include <stdio.h>
1718
#include <stddef.h>
1819
#include <stdarg.h>

src/csnip/x/getdelim.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@
1010
#include <csnip/csnip_conf.h>
1111

1212
/* Check if we can use unlocked stdio, and define macros accordingly. */
13-
#if defined(CSNIP_CONF__HAVE_FLOCKFILE) \
14-
&& defined(CSNIP_CONF__HAVE_FUNLOCKFILE) \
15-
&& defined(CSNIP_CONF__HAVE_UNLOCKED_STDIO)
13+
#if defined(CSNIP_CONF__HAVE_UNLOCKED_STDIO)
1614
#define my_flockfile(fp) flockfile(fp)
1715
#define my_getc(fp) getc_unlocked(fp)
1816
#define my_funlockfile(fp) funlockfile(fp)

src/csnip/x/readv.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
#include <errno.h>
33

44
#include <csnip/csnip_conf.h>
5+
#ifdef CSNIP_CONF__HAVE_IO_H
6+
#include <io.h>
7+
#endif
58

69
#include <csnip/util.h>
710
#include <csnip/x.h>

src/csnip/x/strerror_r.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1+
/* Linux: Make sure we get XSI version of strerror_r() */
2+
#define _POSIX_C_SOURCE 200809L
3+
#undef _GNU_SOURCE
4+
#include <string.h>
5+
16
#include <csnip/csnip_conf.h>
27

38
#include <csnip/x.h>
49

510
#if defined(CSNIP_CONF__HAVE_STRERROR_R)
6-
/* Linux: Make sure we get XSI version of strerror_r() */
7-
#define _POSIX_C_SOURCE 200809L
8-
#undef _GNU_SOURCE
9-
#include <string.h>
1011

1112
int csnip_x_strerror_r(int errnum, char* buf, size_t buflen)
1213
{
1314
return strerror_r(errnum, buf, buflen);
1415
}
1516
#elif defined(CSNIP_CONF__HAVE_STRERROR_S)
16-
#include <sec_api/string_s.h>
1717

1818
int csnip_x_strerror_r(int errnum, char* buf, size_t buflen)
1919
{

test/err_test1.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
int main(void)
1010
{
1111
char* a = "XXX";
12-
mem_Alloc(128ull * 1024 * 1024 * 1024, a, error_ignore);
12+
// XXX: This is a very broken test. Always has been. Remove
13+
// it or something.
14+
mem_Alloc(1024, a, error_ignore);
1315
printf("Pointer: %p\n", (void*)a);
1416

1517
return 0;

0 commit comments

Comments
 (0)