mirror of
https://github.com/guanzhi/GmSSL.git
synced 2026-05-23 00:36:28 +08:00
Remove warnings on WIN32
This commit is contained in:
35
src/file.c
Normal file
35
src/file.c
Normal file
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright 2014-2022 The GmSSL Project. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the License); you may
|
||||
* not use this file except in compliance with the License.
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/stat.h>
|
||||
#include <gmssl/error.h>
|
||||
|
||||
|
||||
int file_size(FILE *fp, size_t *size)
|
||||
{
|
||||
int fd;
|
||||
struct stat st;
|
||||
|
||||
#ifdef WIN32
|
||||
fd = _fileno(fp);
|
||||
#else
|
||||
fd = fileno(fp);
|
||||
#endif
|
||||
if (fstat(fd, &st) < 0) {
|
||||
error_print();
|
||||
return -1;
|
||||
}
|
||||
*size = st.st_size;
|
||||
return 1;
|
||||
}
|
||||
@@ -18,6 +18,7 @@
|
||||
#include <gmssl/pem.h>
|
||||
#include <gmssl/asn1.h>
|
||||
#include <gmssl/rsa.h>
|
||||
#include <gmssl/file.h>
|
||||
#include <gmssl/x509_oid.h>
|
||||
#include <gmssl/x509_str.h>
|
||||
#include <gmssl/x509_alg.h>
|
||||
@@ -1660,14 +1661,14 @@ int x509_cert_new_from_file(uint8_t **out, size_t *outlen, const char *file)
|
||||
{
|
||||
int ret = -1;
|
||||
FILE *fp = NULL;
|
||||
struct stat st;
|
||||
size_t fsize;
|
||||
uint8_t *buf = NULL;
|
||||
size_t buflen;
|
||||
|
||||
if (!(fp = fopen(file, "r"))
|
||||
|| fstat(fileno(fp), &st) < 0
|
||||
|| (buflen = (st.st_size * 3)/4 + 1) < 0
|
||||
|| (buf = malloc((st.st_size * 3)/4 + 1)) == NULL) {
|
||||
|| file_size(fp, &fsize) != 1
|
||||
|| (buflen = (fsize * 3)/4 + 1) < 0
|
||||
|| (buf = malloc((fsize * 3)/4 + 1)) == NULL) {
|
||||
error_print();
|
||||
goto end;
|
||||
}
|
||||
@@ -1688,14 +1689,14 @@ int x509_certs_new_from_file(uint8_t **out, size_t *outlen, const char *file)
|
||||
{
|
||||
int ret = -1;
|
||||
FILE *fp = NULL;
|
||||
struct stat st;
|
||||
size_t fsize;
|
||||
uint8_t *buf = NULL;
|
||||
size_t buflen;
|
||||
|
||||
if (!(fp = fopen(file, "r"))
|
||||
|| fstat(fileno(fp), &st) < 0
|
||||
|| (buflen = (st.st_size * 3)/4 + 1) < 0
|
||||
|| (buf = malloc((st.st_size * 3)/4 + 1)) == NULL) {
|
||||
|| file_size(fp, &fsize) != 1
|
||||
|| (buflen = (fsize * 3)/4 + 1) < 0
|
||||
|| (buf = malloc((fsize * 3)/4 + 1)) == NULL) {
|
||||
error_print();
|
||||
goto end;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user