Add compat bits for libtls on Windows
This commit is contained in:
parent
47781e69e2
commit
3681d02253
@ -21,6 +21,7 @@
|
||||
#ifdef __MINGW32__
|
||||
#include <_bsd_types.h>
|
||||
typedef uint32_t in_addr_t;
|
||||
typedef uint32_t uid_t;
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
@ -29,6 +30,7 @@ typedef unsigned short u_short;
|
||||
typedef unsigned int u_int;
|
||||
typedef uint32_t in_addr_t;
|
||||
typedef uint32_t mode_t;
|
||||
typedef uint32_t uid_t;
|
||||
|
||||
#include <basetsd.h>
|
||||
typedef SSIZE_T ssize_t;
|
||||
|
@ -7,7 +7,16 @@
|
||||
#define LIBCRYPTOCOMPAT_UNISTD_H
|
||||
|
||||
#ifndef _MSC_VER
|
||||
|
||||
#include_next <unistd.h>
|
||||
|
||||
#ifdef __MINGW32__
|
||||
int ftruncate(int fd, off_t length);
|
||||
uid_t getuid(void);
|
||||
ssize_t pread(int d, void *buf, size_t nbytes, off_t offset);
|
||||
ssize_t pwrite(int d, const void *buf, size_t nbytes, off_t offset);
|
||||
#endif
|
||||
|
||||
#else
|
||||
|
||||
#include <stdlib.h>
|
||||
@ -22,10 +31,19 @@
|
||||
#define X_OK 0
|
||||
#define F_OK 0
|
||||
|
||||
#define SEEK_SET 0
|
||||
#define SEEK_CUR 1
|
||||
#define SEEK_END 2
|
||||
|
||||
#define access _access
|
||||
|
||||
unsigned int sleep(unsigned int seconds);
|
||||
|
||||
int ftruncate(int fd, off_t length);
|
||||
uid_t getuid(void);
|
||||
ssize_t pread(int d, void *buf, size_t nbytes, off_t offset);
|
||||
ssize_t pwrite(int d, const void *buf, size_t nbytes, off_t offset);
|
||||
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_GETENTROPY
|
||||
|
@ -19,6 +19,16 @@ set(
|
||||
tls_verify.c
|
||||
)
|
||||
|
||||
if(CMAKE_HOST_WIN32)
|
||||
set(
|
||||
TLS_SRC
|
||||
${TLS_SRC}
|
||||
compat/ftruncate.c
|
||||
compat/getuid.c
|
||||
compat/pread.c
|
||||
compat/pwrite.c
|
||||
)
|
||||
endif()
|
||||
|
||||
if(NOT "${OPENSSLDIR}" STREQUAL "")
|
||||
add_definitions(-D_PATH_SSL_CA_FILE=\"${OPENSSLDIR}/cert.pem\")
|
||||
|
@ -30,3 +30,10 @@ libtls_la_SOURCES += tls_peer.c
|
||||
libtls_la_SOURCES += tls_util.c
|
||||
libtls_la_SOURCES += tls_verify.c
|
||||
noinst_HEADERS = tls_internal.h
|
||||
|
||||
if HOST_WIN
|
||||
libtls_la_SOURCES += compat/ftruncate.c
|
||||
libtls_la_SOURCES += compat/getuid.c
|
||||
libtls_la_SOURCES += compat/pread.c
|
||||
libtls_la_SOURCES += compat/pwrite.c
|
||||
endif
|
||||
|
13
tls/compat/ftruncate.c
Normal file
13
tls/compat/ftruncate.c
Normal file
@ -0,0 +1,13 @@
|
||||
/*
|
||||
* Public domain
|
||||
*
|
||||
* Kinichiro Inoguchi <inoguchi@openbsd.org>
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
int
|
||||
ftruncate(int fd, off_t length)
|
||||
{
|
||||
return _chsize(fd, length);
|
||||
}
|
14
tls/compat/getuid.c
Normal file
14
tls/compat/getuid.c
Normal file
@ -0,0 +1,14 @@
|
||||
/*
|
||||
* Public domain
|
||||
*
|
||||
* Kinichiro Inoguchi <inoguchi@openbsd.org>
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
uid_t
|
||||
getuid(void)
|
||||
{
|
||||
/* Windows fstat sets 0 as st_uid */
|
||||
return 0;
|
||||
}
|
23
tls/compat/pread.c
Normal file
23
tls/compat/pread.c
Normal file
@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Public domain
|
||||
*
|
||||
* Kinichiro Inoguchi <inoguchi@openbsd.org>
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
ssize_t
|
||||
pread(int d, void *buf, size_t nbytes, off_t offset)
|
||||
{
|
||||
off_t cpos, opos, rpos;
|
||||
ssize_t bytes;
|
||||
if((cpos = lseek(d, 0, SEEK_CUR)) == -1)
|
||||
return -1;
|
||||
if((opos = lseek(d, offset, SEEK_SET)) == -1)
|
||||
return -1;
|
||||
if((bytes = read(d, buf, nbytes)) == -1)
|
||||
return -1;
|
||||
if((rpos = lseek(d, cpos, SEEK_SET)) == -1)
|
||||
return -1;
|
||||
return bytes;
|
||||
}
|
23
tls/compat/pwrite.c
Normal file
23
tls/compat/pwrite.c
Normal file
@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Public domain
|
||||
*
|
||||
* Kinichiro Inoguchi <inoguchi@openbsd.org>
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
ssize_t
|
||||
pwrite(int d, const void *buf, size_t nbytes, off_t offset)
|
||||
{
|
||||
off_t cpos, opos, rpos;
|
||||
ssize_t bytes;
|
||||
if((cpos = lseek(d, 0, SEEK_CUR)) == -1)
|
||||
return -1;
|
||||
if((opos = lseek(d, offset, SEEK_SET)) == -1)
|
||||
return -1;
|
||||
if((bytes = write(d, buf, nbytes)) == -1)
|
||||
return -1;
|
||||
if((rpos = lseek(d, cpos, SEEK_SET)) == -1)
|
||||
return -1;
|
||||
return bytes;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user