mirror of
https://github.com/guanzhi/GmSSL.git
synced 2026-05-07 00:46:17 +08:00
Remove warnings on WIN32
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/stat.h>
|
||||
#include <gmssl/file.h>
|
||||
#include <gmssl/x509.h>
|
||||
#include <gmssl/cms.h>
|
||||
|
||||
@@ -35,7 +35,7 @@ int cmsdecrypt_main(int argc, char **argv)
|
||||
FILE *outfp = stdout;
|
||||
uint8_t cert[1024];
|
||||
size_t certlen;
|
||||
struct stat st;
|
||||
size_t inlen;
|
||||
uint8_t *cms = NULL;
|
||||
size_t cmslen, cms_maxlen;
|
||||
SM2_KEY key;
|
||||
@@ -130,8 +130,11 @@ bad:
|
||||
goto end;
|
||||
}
|
||||
|
||||
fstat(fileno(infp), &st);
|
||||
cms_maxlen = (st.st_size * 3)/4 + 1;
|
||||
if (file_size(infp, &inlen) != 1) {
|
||||
fprintf(stderr, "%s: get input length failed\n", prog);
|
||||
goto end;
|
||||
}
|
||||
cms_maxlen = (inlen * 3)/4 + 1;
|
||||
if (!(cms = malloc(cms_maxlen))) {
|
||||
fprintf(stderr, "%s: malloc failure\n", prog);
|
||||
goto end;
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/stat.h>
|
||||
#include <gmssl/file.h>
|
||||
#include <gmssl/cms.h>
|
||||
#include <gmssl/x509.h>
|
||||
#include <gmssl/rand.h>
|
||||
@@ -58,7 +58,6 @@ static int get_files_size(int argc, char **argv, const char *option, size_t *len
|
||||
char *prog = argv[0];
|
||||
char *file = NULL;
|
||||
FILE *fp = NULL;
|
||||
struct stat st;
|
||||
|
||||
argc--;
|
||||
argv++;
|
||||
@@ -66,21 +65,24 @@ static int get_files_size(int argc, char **argv, const char *option, size_t *len
|
||||
*len = 0;
|
||||
while (argc > 1) {
|
||||
if (!strcmp(*argv, option)) {
|
||||
size_t fsize;
|
||||
|
||||
if (--argc < 1) {
|
||||
fprintf(stderr, "%s: '%s' option value missing\n", prog, *argv);
|
||||
return -1;
|
||||
}
|
||||
file = *(++argv);
|
||||
|
||||
if (!(fp = fopen(file, "rb"))) {
|
||||
fprintf(stderr, "%s: open '%s' failed : %s\n", prog, file, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
if (fstat(fileno(fp), &st) < 0) {
|
||||
if (file_size(fp, &fsize) != 1) {
|
||||
fprintf(stderr, "%s: access '%s' failed : %s\n", prog, file, strerror(errno));
|
||||
fclose(fp);
|
||||
return -1;
|
||||
}
|
||||
*len += st.st_size;
|
||||
*len += fsize;
|
||||
fclose(fp);
|
||||
}
|
||||
argc--;
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/stat.h>
|
||||
#include <gmssl/file.h>
|
||||
#include <gmssl/cms.h>
|
||||
#include <gmssl/x509.h>
|
||||
#include <gmssl/rand.h>
|
||||
@@ -26,7 +26,7 @@ int cmsparse_main(int argc, char **argv)
|
||||
char *prog = argv[0];
|
||||
char *infile = NULL;
|
||||
FILE *infp = stdin;
|
||||
struct stat st;
|
||||
size_t inlen;
|
||||
uint8_t *cms = NULL;
|
||||
size_t cms_maxlen, cmslen;
|
||||
|
||||
@@ -66,11 +66,11 @@ bad:
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (fstat(fileno(infp), &st) < 0) {
|
||||
if (file_size(infp, &inlen) != 1) { // FIXME: infp == stdin?
|
||||
fprintf(stderr, "%s: access '%s' failed : %s\n", prog, infile, strerror(errno));
|
||||
goto end;
|
||||
}
|
||||
cms_maxlen = (st.st_size * 3)/4 + 1;
|
||||
cms_maxlen = (inlen * 3)/4 + 1;
|
||||
if (!(cms = malloc(cms_maxlen))) {
|
||||
fprintf(stderr, "%s: malloc failure\n", prog);
|
||||
goto end;
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/stat.h>
|
||||
#include <gmssl/file.h>
|
||||
#include <gmssl/x509.h>
|
||||
#include <gmssl/cms.h>
|
||||
#include <gmssl/error.h>
|
||||
@@ -49,7 +49,6 @@ int cmssign_main(int argc, char **argv)
|
||||
SM2_KEY key;
|
||||
uint8_t cert[1024];
|
||||
size_t certlen;
|
||||
struct stat st;
|
||||
uint8_t *in = NULL;
|
||||
size_t inlen;
|
||||
uint8_t *cms = NULL;
|
||||
@@ -153,12 +152,8 @@ bad:
|
||||
cert_and_key.certs_len = certlen;
|
||||
cert_and_key.sign_key = &key;
|
||||
|
||||
if (fstat(fileno(infp), &st) < 0) {
|
||||
fprintf(stderr, "%s: access file error : %s\n", prog, strerror(errno));
|
||||
goto end;
|
||||
}
|
||||
if ((inlen = st.st_size) <= 0) {
|
||||
fprintf(stderr, "%s: invalid input length\n", prog);
|
||||
if (file_size(infp, &inlen) != 1) {
|
||||
fprintf(stderr, "%s: get input length failed\n", prog);
|
||||
goto end;
|
||||
}
|
||||
if (!(in = malloc(inlen))) {
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/stat.h>
|
||||
#include <gmssl/file.h>
|
||||
#include <gmssl/cms.h>
|
||||
#include <gmssl/x509.h>
|
||||
#include <gmssl/rand.h>
|
||||
@@ -29,10 +29,9 @@ int cmsverify_main(int argc, char **argv)
|
||||
char *outfile = NULL;
|
||||
FILE *infp = NULL;
|
||||
FILE *outfp = NULL;
|
||||
struct stat st;
|
||||
size_t inlen;
|
||||
uint8_t *cms = NULL;
|
||||
size_t cmslen, cms_maxlen;
|
||||
|
||||
int content_type;
|
||||
const uint8_t *content;
|
||||
size_t content_len;
|
||||
@@ -87,8 +86,11 @@ bad:
|
||||
fprintf(stderr, "%s: '-in' option required\n", prog);
|
||||
goto end;
|
||||
}
|
||||
fstat(fileno(infp), &st);
|
||||
cms_maxlen = (st.st_size * 3)/4 + 1;
|
||||
if (file_size(infp, &inlen) != 1) {
|
||||
fprintf(stderr, "%s: get input length failed\n", prog);
|
||||
goto end;
|
||||
}
|
||||
cms_maxlen = (inlen * 3)/4 + 1;
|
||||
if (!(cms = malloc(cms_maxlen))) {
|
||||
fprintf(stderr, "%s: malloc failure\n", prog);
|
||||
goto end;
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/stat.h>
|
||||
#include <gmssl/file.h>
|
||||
#include <gmssl/x509.h>
|
||||
#include <gmssl/x509_crl.h>
|
||||
|
||||
@@ -27,7 +27,6 @@ int crlparse_main(int argc, char **argv)
|
||||
char *outfile = NULL;
|
||||
FILE *infp = stdin;
|
||||
FILE *outfp = stdout;
|
||||
struct stat st;
|
||||
uint8_t *in = NULL;
|
||||
size_t inlen;
|
||||
const uint8_t *pin;
|
||||
@@ -76,12 +75,8 @@ bad:
|
||||
fprintf(stderr, "%s: '-in' option required\n", prog);
|
||||
goto end;
|
||||
}
|
||||
if (fstat(fileno(infp), &st) < 0) {
|
||||
fprintf(stderr, "%s: access file error : %s\n", prog, strerror(errno));
|
||||
goto end;
|
||||
}
|
||||
if ((inlen = st.st_size) <= 0) {
|
||||
fprintf(stderr, "%s: invalid input length\n", prog);
|
||||
if (file_size(infp, &inlen) != 1) {
|
||||
fprintf(stderr, "%s: get input length failed\n", prog);
|
||||
goto end;
|
||||
}
|
||||
if (!(in = malloc(inlen))) {
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/stat.h>
|
||||
#include <gmssl/file.h>
|
||||
#include <gmssl/x509.h>
|
||||
#include <gmssl/x509_crl.h>
|
||||
|
||||
@@ -29,7 +29,6 @@ int crlverify_main(int argc, char **argv)
|
||||
FILE *cacertfp = NULL;
|
||||
uint8_t *in = NULL;
|
||||
size_t inlen;
|
||||
struct stat st;
|
||||
const uint8_t *pin;
|
||||
const uint8_t *crl = NULL;
|
||||
size_t crllen;
|
||||
@@ -87,13 +86,8 @@ bad:
|
||||
goto end;
|
||||
}
|
||||
|
||||
|
||||
if (fstat(fileno(infp), &st) < 0) {
|
||||
fprintf(stderr, "%s: access file error : %s\n", prog, strerror(errno));
|
||||
goto end;
|
||||
}
|
||||
if ((inlen = st.st_size) <= 0) {
|
||||
fprintf(stderr, "%s: invalid input length\n", prog);
|
||||
if (file_size(infp, &inlen) != 1) {
|
||||
fprintf(stderr, "%s: get input length failed\n", prog);
|
||||
goto end;
|
||||
}
|
||||
if (!(in = malloc(inlen))) {
|
||||
|
||||
@@ -142,7 +142,10 @@ bad:
|
||||
|
||||
FD_ZERO(&fds);
|
||||
FD_SET(conn.sock, &fds);
|
||||
#ifdef WIN32
|
||||
#else
|
||||
FD_SET(fileno(stdin), &fds);
|
||||
#endif
|
||||
|
||||
if (select((int)(conn.sock + 1), &fds, NULL, NULL, NULL) < 0) {
|
||||
fprintf(stderr, "%s: select failed\n", prog);
|
||||
@@ -165,6 +168,8 @@ bad:
|
||||
}
|
||||
|
||||
}
|
||||
#ifdef WIN32
|
||||
#else
|
||||
if (FD_ISSET(fileno(stdin), &fds)) {
|
||||
memset(send_buf, 0, sizeof(send_buf));
|
||||
|
||||
@@ -181,6 +186,7 @@ bad:
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -141,7 +141,10 @@ bad:
|
||||
|
||||
FD_ZERO(&fds);
|
||||
FD_SET(conn.sock, &fds);
|
||||
#ifdef WIN32
|
||||
#else
|
||||
FD_SET(fileno(stdin), &fds);
|
||||
#endif
|
||||
|
||||
if (select((int)(conn.sock + 1), // In WinSock2, select() ignore the this arg
|
||||
&fds, NULL, NULL, NULL) < 0) {
|
||||
@@ -165,6 +168,8 @@ bad:
|
||||
}
|
||||
|
||||
}
|
||||
#ifdef WIN32
|
||||
#else
|
||||
if (FD_ISSET(fileno(stdin), &fds)) {
|
||||
memset(send_buf, 0, sizeof(send_buf));
|
||||
|
||||
@@ -181,6 +186,7 @@ bad:
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
end:
|
||||
|
||||
Reference in New Issue
Block a user