Get rid of a lot of WIN32 ifdefs by providing a compatibility function instead
This commit is contained in:
@@ -30,6 +30,10 @@
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#if defined(WIN32)
|
||||
#include "win32/win32_compat.h"
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include "iscsi.h"
|
||||
@@ -69,11 +73,8 @@ iscsi_log_message(struct iscsi_context *iscsi, int level, const char *format, ..
|
||||
|
||||
if (iscsi->target_name[0]) {
|
||||
static char message2[1024];
|
||||
#if defined(WIN32)
|
||||
_snprintf_s(message2, 1024, 1024, "%s [%s]", message, iscsi->target_name);
|
||||
#else
|
||||
|
||||
snprintf(message2, 1024, "%s [%s]", message, iscsi->target_name);
|
||||
#endif
|
||||
iscsi->log_fn(level, message2);
|
||||
}
|
||||
else
|
||||
|
||||
33
lib/login.c
33
lib/login.c
@@ -33,6 +33,7 @@
|
||||
|
||||
#if defined(WIN32)
|
||||
#include <winsock2.h>
|
||||
#include "win32/win32_compat.h"
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
@@ -58,11 +59,7 @@ iscsi_login_add_initiatorname(struct iscsi_context *iscsi, struct iscsi_pdu *pdu
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if defined(WIN32)
|
||||
if (_snprintf_s(str, MAX_STRING_SIZE, MAX_STRING_SIZE, "InitiatorName=%s", iscsi->initiator_name) == -1) {
|
||||
#else
|
||||
if (snprintf(str, MAX_STRING_SIZE, "InitiatorName=%s", iscsi->initiator_name) == -1) {
|
||||
#endif
|
||||
iscsi_set_error(iscsi, "Out-of-memory: aprintf failed.");
|
||||
return -1;
|
||||
}
|
||||
@@ -85,11 +82,7 @@ iscsi_login_add_alias(struct iscsi_context *iscsi, struct iscsi_pdu *pdu)
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if defined(WIN32)
|
||||
if (_snprintf_s(str, MAX_STRING_SIZE, MAX_STRING_SIZE, "InitiatorAlias=%s", iscsi->alias) == -1) {
|
||||
#else
|
||||
if (snprintf(str, MAX_STRING_SIZE, "InitiatorAlias=%s", iscsi->alias) == -1) {
|
||||
#endif
|
||||
iscsi_set_error(iscsi, "Out-of-memory: aprintf failed.");
|
||||
return -1;
|
||||
}
|
||||
@@ -119,11 +112,7 @@ iscsi_login_add_targetname(struct iscsi_context *iscsi, struct iscsi_pdu *pdu)
|
||||
return -1;
|
||||
}
|
||||
|
||||
#if defined(WIN32)
|
||||
if (_snprintf_s(str, MAX_STRING_SIZE, MAX_STRING_SIZE, "TargetName=%s", iscsi->target_name) == -1) {
|
||||
#else
|
||||
if (snprintf(str, MAX_STRING_SIZE, "TargetName=%s", iscsi->target_name) == -1) {
|
||||
#endif
|
||||
iscsi_set_error(iscsi, "Out-of-memory: aprintf failed.");
|
||||
return -1;
|
||||
}
|
||||
@@ -235,11 +224,7 @@ iscsi_login_add_initialr2t(struct iscsi_context *iscsi, struct iscsi_pdu *pdu)
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if defined(WIN32)
|
||||
if (_snprintf_s(str, MAX_STRING_SIZE, MAX_STRING_SIZE, "InitialR2T=%s", iscsi->want_initial_r2t == ISCSI_INITIAL_R2T_NO ?
|
||||
#else
|
||||
if (snprintf(str, MAX_STRING_SIZE, "InitialR2T=%s", iscsi->want_initial_r2t == ISCSI_INITIAL_R2T_NO ?
|
||||
#endif
|
||||
"No" : "Yes") == -1) {
|
||||
iscsi_set_error(iscsi, "Out-of-memory: aprintf failed.");
|
||||
return -1;
|
||||
@@ -264,11 +249,7 @@ iscsi_login_add_immediatedata(struct iscsi_context *iscsi, struct iscsi_pdu *pdu
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if defined(WIN32)
|
||||
if (_snprintf_s(str, MAX_STRING_SIZE, MAX_STRING_SIZE, "ImmediateData=%s", iscsi->want_immediate_data == ISCSI_IMMEDIATE_DATA_NO ?
|
||||
#else
|
||||
if (snprintf(str, MAX_STRING_SIZE, "ImmediateData=%s", iscsi->want_immediate_data == ISCSI_IMMEDIATE_DATA_NO ?
|
||||
#endif
|
||||
"No" : "Yes") == -1) {
|
||||
iscsi_set_error(iscsi, "Out-of-memory: aprintf failed.");
|
||||
return -1;
|
||||
@@ -293,11 +274,7 @@ iscsi_login_add_maxburstlength(struct iscsi_context *iscsi, struct iscsi_pdu *pd
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if defined(WIN32)
|
||||
if (_snprintf_s(str, MAX_STRING_SIZE, MAX_STRING_SIZE, "MaxBurstLength=%d", iscsi->max_burst_length) == -1) {
|
||||
#else
|
||||
if (snprintf(str, MAX_STRING_SIZE, "MaxBurstLength=%d", iscsi->max_burst_length) == -1) {
|
||||
#endif
|
||||
iscsi_set_error(iscsi, "Out-of-memory: aprintf failed.");
|
||||
return -1;
|
||||
}
|
||||
@@ -320,11 +297,7 @@ iscsi_login_add_firstburstlength(struct iscsi_context *iscsi, struct iscsi_pdu *
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if defined(WIN32)
|
||||
if (_snprintf_s(str, MAX_STRING_SIZE, MAX_STRING_SIZE, "FirstBurstLength=%d", iscsi->first_burst_length) == -1) {
|
||||
#else
|
||||
if (snprintf(str, MAX_STRING_SIZE, "FirstBurstLength=%d", iscsi->first_burst_length) == -1) {
|
||||
#endif
|
||||
iscsi_set_error(iscsi, "Out-of-memory: aprintf failed.");
|
||||
return -1;
|
||||
}
|
||||
@@ -347,11 +320,7 @@ iscsi_login_add_maxrecvdatasegmentlength(struct iscsi_context *iscsi, struct isc
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if defined(WIN32)
|
||||
if (_snprintf_s(str, MAX_STRING_SIZE, MAX_STRING_SIZE, "MaxRecvDataSegmentLength=%d", iscsi->initiator_max_recv_data_segment_length) == -1) {
|
||||
#else
|
||||
if (snprintf(str, MAX_STRING_SIZE, "MaxRecvDataSegmentLength=%d", iscsi->initiator_max_recv_data_segment_length) == -1) {
|
||||
#endif
|
||||
iscsi_set_error(iscsi, "Out-of-memory: aprintf failed.");
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -48,6 +48,7 @@ typedef int socklen_t;
|
||||
#define poll(x, y, z) win32_poll(x, y, z)
|
||||
#define inet_pton(x,y,z) win32_inet_pton(x,y,z)
|
||||
#define sleep(x) Sleep(x * 1000)
|
||||
#define snprintf(a, b, c, ...) _snprintf_s(a, b, b, c, ## __VA_ARGS)
|
||||
int win32_inet_pton(int af, const char * src, void * dst);
|
||||
int win32_poll(struct pollfd *fds, unsigned int nfsd, int timeout);
|
||||
int win32_gettimeofday(struct timeval *tv, struct timezone *tz);
|
||||
|
||||
Reference in New Issue
Block a user