Replace all instances of ssize_t with long and rearranged unistd include, fixing compile errors on Windows VS.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282
diff --git a/src/smtp.c b/src/smtp.c
index 950b89a..b99d540 100644
--- a/src/smtp.c
+++ b/src/smtp.c
@@ -39,6 +39,7 @@
# include <sys/select.h>
# include <sys/socket.h>
# include <netdb.h>
+# include <unistd.h>
#endif /* SMTP_IS_WINDOWS */
#include <errno.h>
@@ -48,7 +49,6 @@
#include <string.h>
#include <stdlib.h>
#include <time.h>
-#include <unistd.h>
#ifdef SMTP_OPENSSL
# include <openssl/bio.h>
@@ -276,12 +276,12 @@ smtp_str_getdelimfd_read_timeout(struct smtp *const smtp){
* @retval >=0 Number of bytes read.
* @retval -1 Failed to read from the socket.
*/
-static ssize_t
+static long
smtp_str_getdelimfd_read(struct str_getdelimfd *const gdfd,
void *buf,
size_t count){
struct smtp *smtp;
- ssize_t bytes_read;
+ long bytes_read;
smtp = gdfd->user_data;
@@ -394,7 +394,7 @@ smtp_str_getdelimfd_free(struct str_getdelimfd *const gdfd){
SMTP_LINKAGE enum str_getdelim_retcode
smtp_str_getdelimfd(struct str_getdelimfd *const gdfd){
size_t delim_pos;
- ssize_t bytes_read;
+ long bytes_read;
void *read_buf_ptr;
char *buf_new;
size_t buf_sz_remaining;
@@ -629,7 +629,7 @@ smtp_base64_encode_block(const char *const buf,
*/
SMTP_LINKAGE char *
smtp_base64_encode(const char *const buf,
- ssize_t buflen){
+ long buflen){
char *b64;
size_t b64_sz;
size_t buf_i;
@@ -781,13 +781,13 @@ smtp_base64_decode_block(const unsigned char *const buf,
* @retval >=0 Length of the data stored in the decode parameter.
* @retval -1 Memory allocation failure or invalid base64 byte sequences.
*/
-SMTP_LINKAGE ssize_t
+SMTP_LINKAGE long
smtp_base64_decode(const char *const buf,
unsigned char **decode){
size_t buf_len;
size_t buf_i;
unsigned char *b64_decode;
- ssize_t decode_len;
+ long decode_len;
int decode_block_len;
*decode = NULL;
@@ -923,7 +923,7 @@ smtp_str_has_nonascii_utf8(const char *const s){
* @retval maxlen If length of s has more bytes than maxlen.
* @retval -1 If @p s contains an invalid UTF-8 byte sequence.
*/
-SMTP_LINKAGE ssize_t
+SMTP_LINKAGE long
smtp_strnlen_utf8(const char *s,
size_t maxlen){
size_t i;
@@ -967,7 +967,7 @@ smtp_chunk_split(const char *const s,
size_t chunk_i;
size_t snew_i;
size_t body_i;
- ssize_t body_copy_len;
+ long body_copy_len;
if(chunklen < 1){
errno = EINVAL;
@@ -1338,11 +1338,16 @@ smtp_connect(struct smtp *const smtp,
}
if(connect(smtp->sock, res->ai_addr, res->ai_addrlen) < 0){
+#ifdef SMTP_IS_WINDOWS
+ closesocket(smtp->sock);
+#else /* POSIX */
close(smtp->sock);
+#endif /* SMTP_IS_WINDOWS */
smtp->sock = -1;
- continue;
}
- break;
+ else{
+ break;
+ }
}
freeaddrinfo(res0);
@@ -1630,7 +1635,7 @@ smtp_auth_cram_md5(struct smtp *const smtp,
const char *const pass){
struct smtp_command cmd;
unsigned char *challenge_decoded;
- ssize_t challenge_decoded_len;
+ long challenge_decoded_len;
const char *key;
int key_len;
unsigned char hmac[EVP_MAX_MD_SIZE];
@@ -3091,7 +3096,7 @@ enum smtp_status_code
smtp_attachment_add_mem(struct smtp *const smtp,
const char *const name,
const void *const data,
- ssize_t datasz){
+ long datasz){
size_t new_size;
struct smtp_attachment *new_attachment_list;
struct smtp_attachment *new_attachment;
diff --git a/src/smtp.h b/src/smtp.h
index 9db9446..e9d3cf1 100644
--- a/src/smtp.h
+++ b/src/smtp.h
@@ -271,7 +271,7 @@ enum smtp_status_code
smtp_attachment_add_mem(struct smtp *const smtp,
const char *const name,
const void *const data,
- ssize_t datasz);
+ long datasz);
void smtp_attachment_clear_all(struct smtp *const smtp);
@@ -414,9 +414,9 @@ struct str_getdelimfd{
* info from the @ref str_getdelimfd struct which can contain file pointer,
* socket connection, etc.
*/
- ssize_t (*getdelimfd_read)(struct str_getdelimfd *const gdfd,
- void *buf,
- size_t count);
+ long (*getdelimfd_read)(struct str_getdelimfd *const gdfd,
+ void *buf,
+ size_t count);
/**
* User data which gets sent to the read handler function.
diff --git a/test/seams.c b/test/seams.c
index 96a4536..7c3d20a 100644
--- a/test/seams.c
+++ b/test/seams.c
@@ -483,7 +483,7 @@ smtp_test_seam_realloc(void *ptr,
* @retval >=0 Number of bytes received.
* @retval -1 Failed to receive bytes over the network.
*/
-ssize_t
+long
smtp_test_seam_recv(int socket,
void *buffer,
size_t length,
@@ -545,7 +545,7 @@ smtp_test_seam_select(int nfds,
* @retval >=0 Number of bytes sent.
* @retval -1 Failed to send bytes over the network.
*/
-ssize_t
+long
smtp_test_seam_send(int socket,
const void *buffer,
size_t length,
diff --git a/test/test.c b/test/test.c
index ae21b7b..f0bc1fd 100644
--- a/test/test.c
+++ b/test/test.c
@@ -257,7 +257,7 @@ smtp_str_list_free(struct smtp_str_list *const list){
*/
static int
smtp_str_split(const char *const s,
- ssize_t slen,
+ long slen,
const char *const delimiter,
int limit,
struct smtp_str_list *slist){
@@ -328,8 +328,8 @@ smtp_str_split(const char *const s,
static size_t
smtp_ffile_put_contents(FILE *stream,
const void *const data,
- ssize_t datasz){
- ssize_t bytes_written;
+ long datasz){
+ long bytes_written;
bytes_written = 0;
@@ -366,7 +366,7 @@ smtp_ffile_put_contents(FILE *stream,
static size_t
smtp_file_put_contents(const char *const filename,
const void *const data,
- ssize_t datasz,
+ long datasz,
int flags){
FILE *fp;
size_t bytes_written;
@@ -420,9 +420,9 @@ smtp_test_sleep(unsigned int seconds){
static void
smtp_unit_test_base64_decode(const char *const buf,
const char *const expect_str,
- ssize_t expect_str_len){
+ long expect_str_len){
unsigned char *decode;
- ssize_t str_len;
+ long str_len;
str_len = smtp_base64_decode(buf, &decode);
if(expect_str){
@@ -471,7 +471,7 @@ smtp_unit_test_all_base64_decode(void){
*/
static void
smtp_unit_test_base64_encode(const char *const buf,
- ssize_t buflen,
+ long buflen,
const char *const expect){
char *result;
@@ -1199,7 +1199,7 @@ static int g_smtp_test_getdelimfd_fp_fail = 0;
* @retval >=0 Number of bytes read.
* @retval -1 Failed to read from the socket.
*/
-static ssize_t
+static long
smtp_unit_test_getdelimfd_fp(struct str_getdelimfd *const gdfd,
void *buf,
size_t count){
diff --git a/test/test.h b/test/test.h
index dce6105..97686ac 100644
--- a/test/test.h
+++ b/test/test.h
@@ -55,13 +55,13 @@ struct str_getdelimfd;
*/
#define SMTP_DATE_MAX_SZ 32
-ssize_t
+long
smtp_base64_decode(const char *const buf,
unsigned char **decode);
char *
smtp_base64_encode(const char *const buf,
- ssize_t buflen);
+ long buflen);
char *
smtp_bin2hex(const unsigned char *const s,
@@ -91,7 +91,7 @@ smtp_utf8_charlen(unsigned char c);
int
smtp_str_has_nonascii_utf8(const char *const s);
-ssize_t
+long
smtp_strnlen_utf8(const char *s,
size_t maxlen);
@@ -188,7 +188,7 @@ void *
smtp_test_seam_realloc(void *ptr,
size_t size);
-ssize_t
+long
smtp_test_seam_recv(int socket,
void *buffer,
size_t length,
@@ -201,7 +201,7 @@ smtp_test_seam_select(int nfds,
fd_set *errorfds,
struct timeval *timeout);
-ssize_t
+long
smtp_test_seam_send(int socket,
const void *buffer,
size_t length,