Commit d4d7d6d6 authored by Ghislain MARY's avatar Ghislain MARY

Fix build for Windows 10.

parent 381df010
......@@ -362,6 +362,15 @@ BCTBX_PUBLIC int bctbx_timespec_compare(const bctoolboxTimeSpec *s1, const bctoo
BCTBX_PUBLIC unsigned int bctbx_random(void);
BCTBX_PUBLIC int bctbx_bind(bctbx_socket_t socket, const struct sockaddr *address, socklen_t address_len);
BCTBX_PUBLIC int bctbx_connect(bctbx_socket_t socket, const struct sockaddr *address, socklen_t address_len);
BCTBX_PUBLIC ssize_t bctbx_send(bctbx_socket_t socket, const void *buffer, size_t length, int flags);
BCTBX_PUBLIC ssize_t bctbx_sendto(bctbx_socket_t socket, const void *message, size_t length, int flags, const struct sockaddr *dest_addr, socklen_t dest_len);
BCTBX_PUBLIC ssize_t bctbx_recv(bctbx_socket_t socket, void *buffer, size_t length, int flags);
BCTBX_PUBLIC ssize_t bctbx_recvfrom(bctbx_socket_t socket, void *buffer, size_t length, int flags, struct sockaddr *address, socklen_t *address_len);
BCTBX_PUBLIC ssize_t bctbx_read(int fd, void *buf, size_t nbytes);
BCTBX_PUBLIC ssize_t bctbx_write(int fd, const void *buf, size_t nbytes);
/* Portable and bug-less getaddrinfo */
BCTBX_PUBLIC int bctbx_getaddrinfo(const char *node, const char *service, const struct addrinfo *hints, struct addrinfo **res);
BCTBX_PUBLIC void bctbx_freeaddrinfo(struct addrinfo *res);
......
......@@ -99,7 +99,7 @@ static ssize_t bcRead(bctbx_vfs_file_t *pFile, void *buf, size_t count, off_t of
ssize_t nRead; /* Return value from read() */
if (pFile) {
if (bctbx_file_seek(pFile, offset, SEEK_SET) == BCTBX_VFS_OK) {
nRead = read(pFile->fd, buf, count);
nRead = bctbx_read(pFile->fd, buf, count);
/* Error while reading */
if (nRead < 0) {
if (errno) return -errno;
......@@ -121,11 +121,11 @@ static ssize_t bcRead(bctbx_vfs_file_t *pFile, void *buf, size_t count, off_t of
* @return number of bytes written (can be 0), negative value errno if an error occurred.
*/
static ssize_t bcWrite(bctbx_vfs_file_t *p, const void *buf, size_t count, off_t offset) {
size_t nWrite = 0; /* Return value from write() */
ssize_t nWrite = 0; /* Return value from write() */
if (p) {
if ((bctbx_file_seek(p, offset, SEEK_SET)) == BCTBX_VFS_OK) {
nWrite = write(p->fd, buf, count);
nWrite = bctbx_write(p->fd, buf, count);
if (nWrite > 0) return nWrite;
else if (nWrite <= 0) {
if (errno) return -errno;
......@@ -192,7 +192,7 @@ static int bcGetLine(bctbx_vfs_file_t *pFile, char *s, int max_len) {
if (pNextLine) {
/* Got a line! */
*pNextLine = '\0';
sizeofline = pNextLine - s + 1;
sizeofline = (int)(pNextLine - s + 1);
if (pNextLine[1] == '\n') sizeofline += 1; /*take into account the \r\n" case*/
/* offset to next beginning of line*/
......@@ -401,4 +401,4 @@ bctbx_vfs_t* bctbx_vfs_get_default(void) {
bctbx_vfs_t* bctbx_vfs_get_standard(void) {
return &bcVfs;
}
\ No newline at end of file
}
......@@ -214,7 +214,7 @@ int32_t bctbx_x509_certificate_parse(bctbx_x509_certificate_t *cert, const char
int32_t bctbx_x509_certificate_get_der_length(bctbx_x509_certificate_t *cert) {
if (cert!=NULL) {
return ((mbedtls_x509_crt *)cert)->raw.len;
return (int32_t)((mbedtls_x509_crt *)cert)->raw.len;
}
return 0;
}
......@@ -454,7 +454,7 @@ int32_t bctbx_x509_certificate_get_fingerprint(const bctbx_x509_certificate_t *c
if (hash_length>0) {
size_t i;
int fingerprint_index = strlen(hash_alg_string);
size_t fingerprint_index = strlen(hash_alg_string);
char prefix=' ';
fingerprint_size=fingerprint_index+3*hash_length+1;
......@@ -1419,7 +1419,7 @@ int32_t bctbx_aes_gcm_encrypt_and_tag(const uint8_t *key, size_t keyLength,
int ret;
mbedtls_gcm_init(&gcmContext);
ret = mbedtls_gcm_setkey(&gcmContext, MBEDTLS_CIPHER_ID_AES, key, keyLength*8);
ret = mbedtls_gcm_setkey(&gcmContext, MBEDTLS_CIPHER_ID_AES, key, (unsigned int)keyLength*8);
if (ret != 0) return ret;
ret = mbedtls_gcm_crypt_and_tag(&gcmContext, MBEDTLS_GCM_ENCRYPT, plainTextLength, initializationVector, initializationVectorLength, authenticatedData, authenticatedDataLength, plainText, output, tagLength, tag);
......@@ -1455,7 +1455,7 @@ int32_t bctbx_aes_gcm_decrypt_and_auth(const uint8_t *key, size_t keyLength,
int ret;
mbedtls_gcm_init(&gcmContext);
ret = mbedtls_gcm_setkey(&gcmContext, MBEDTLS_CIPHER_ID_AES, key, keyLength*8);
ret = mbedtls_gcm_setkey(&gcmContext, MBEDTLS_CIPHER_ID_AES, key, (unsigned int)keyLength*8);
if (ret != 0) return ret;
ret = mbedtls_gcm_auth_decrypt(&gcmContext, cipherTextLength, initializationVector, initializationVectorLength, authenticatedData, authenticatedDataLength, tag, tagLength, cipherText, output);
......@@ -1501,7 +1501,7 @@ bctbx_aes_gcm_context_t *bctbx_aes_gcm_context_new(const uint8_t *key, size_t ke
ctx = bctbx_malloc0(sizeof(mbedtls_gcm_context));
mbedtls_gcm_init(ctx);
ret = mbedtls_gcm_setkey(ctx, MBEDTLS_CIPHER_ID_AES, key, keyLength*8);
ret = mbedtls_gcm_setkey(ctx, MBEDTLS_CIPHER_ID_AES, key, (unsigned int)keyLength*8);
if (ret != 0) {
bctbx_free(ctx);
return NULL;
......
......@@ -904,6 +904,76 @@ bool_t bctbx_is_multicast_addr(const struct sockaddr *addr) {
}
#ifdef _WIN32
int bctbx_bind(bctbx_socket_t socket, const struct sockaddr *address, socklen_t address_len) {
return bind(socket, address, (int)address_len);
}
int bctbx_connect(bctbx_socket_t socket, const struct sockaddr *address, socklen_t address_len) {
return connect(socket, address, (int)address_len);
}
ssize_t bctbx_send(bctbx_socket_t socket, const void *buffer, size_t length, int flags) {
return send(socket, (const char *)buffer, (int)length, flags);
}
ssize_t bctbx_sendto(bctbx_socket_t socket, const void *message, size_t length, int flags, const struct sockaddr *dest_addr, socklen_t dest_len) {
return sendto(socket, (const char *)message, (int)length, flags, dest_addr, (int)dest_len);
}
ssize_t bctbx_recv(bctbx_socket_t socket, void *buffer, size_t length, int flags) {
return recv(socket, (char *)buffer, (int)length, flags);
}
ssize_t bctbx_recvfrom(bctbx_socket_t socket, void *buffer, size_t length, int flags, struct sockaddr *address, socklen_t *address_len) {
return recvfrom(socket, (char *)buffer, (int)length, flags, address, (int *)address_len);
}
ssize_t bctbx_read(int fd, void *buf, size_t nbytes) {
return (ssize_t)_read(fd, buf, (unsigned int)nbytes);
}
ssize_t bctbx_write(int fd, const void *buf, size_t nbytes) {
return (ssize_t)_write(fd, buf, (unsigned int)nbytes);
}
#else
int bctbx_bind(bctbx_socket_t socket, const struct sockaddr *address, socklen_t address_len) {
return bind(socket, address, address_len);
}
int bctbx_connect(bctbx_socket_t socket, const struct sockaddr *address, socklen_t address_len) {
return connect(socket, address, address_len);
}
ssize_t bctbx_send(bctbx_socket_t socket, const void *buffer, size_t length, int flags) {
return send(socket, buffer, length, flags);
}
ssize_t bctbx_sendto(bctbx_socket_t socket, const void *message, size_t length, int flags, const struct sockaddr *dest_addr, socklen_t dest_len) {
return sendto(socket, message, length, flags, dest_addr, dest_len);
}
ssize_t bctbx_recv(bctbx_socket_t socket, void *buffer, size_t length, int flags) {
return recv(socket, buffer, length, flags);
}
ssize_t bctbx_recvfrom(bctbx_socket_t socket, void *buffer, size_t length, int flags, struct sockaddr *address, socklen_t *address_len) {
return recvfrom(socket, buffer, length, flags, address, address_len);
}
ssize_t bctbx_read(int fd, void *buf, size_t nbytes) {
return read(fd, buf, nbytes);
}
ssize_t bctbx_write(int fd, const void *buf, size_t nbytes) {
return write(fd, buf, nbytes);
}
#endif
#if defined(ANDROID) || defined(_WIN32)
......@@ -1056,7 +1126,7 @@ static void _bctbx_addrinfo_to_ip_address_error(int err, char *ip, size_t ip_siz
int bctbx_addrinfo_to_ip_address(const struct addrinfo *ai, char *ip, size_t ip_size, int *port){
char serv[16];
int err=getnameinfo(ai->ai_addr,ai->ai_addrlen,ip,ip_size,serv,sizeof(serv),NI_NUMERICHOST|NI_NUMERICSERV);
int err=getnameinfo(ai->ai_addr,(socklen_t)ai->ai_addrlen,ip,(socklen_t)ip_size,serv,(socklen_t)sizeof(serv),NI_NUMERICHOST|NI_NUMERICSERV);
if (err!=0) _bctbx_addrinfo_to_ip_address_error(err, ip, ip_size);
if (port) *port=atoi(serv);
return 0;
......@@ -1065,7 +1135,7 @@ int bctbx_addrinfo_to_ip_address(const struct addrinfo *ai, char *ip, size_t ip_
int bctbx_addrinfo_to_printable_ip_address(const struct addrinfo *ai, char *printable_ip, size_t printable_ip_size) {
char ip[64];
char serv[16];
int err = getnameinfo(ai->ai_addr, ai->ai_addrlen, ip, sizeof(ip), serv, sizeof(serv), NI_NUMERICHOST | NI_NUMERICSERV);
int err = getnameinfo(ai->ai_addr, (socklen_t)ai->ai_addrlen, ip, sizeof(ip), serv, sizeof(serv), NI_NUMERICHOST | NI_NUMERICSERV);
if (err != 0) _bctbx_addrinfo_to_ip_address_error(err, ip, sizeof(ip));
if (ai->ai_family == AF_INET)
snprintf(printable_ip, printable_ip_size, "%s:%s", ip, serv);
......
......@@ -26,7 +26,7 @@ else()
set(PROJECT_LIBS bctoolbox bctoolbox-tester)
endif()
if(BCUNIT_FOUND)
if(BCUNIT_FOUND AND NOT CMAKE_SYSTEM_NAME STREQUAL "WindowsStore")
set(TESTER_SOURCES
bctoolbox_tester.c
bctoolbox_tester.h
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment