mirror of
https://github.com/fmtlib/fmt.git
synced 2025-02-05 00:40:12 +00:00
Fix warnings.
This commit is contained in:
parent
fb4ccac951
commit
e1c86f0b5d
@ -38,6 +38,14 @@
|
|||||||
// Check if format.h compiles with windows.h included.
|
// Check if format.h compiles with windows.h included.
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
# include <windows.h>
|
# include <windows.h>
|
||||||
|
|
||||||
|
// Fix MSVC warning about "unsafe" fopen.
|
||||||
|
FILE *FOpen(const char *filename, const char *mode) {
|
||||||
|
FILE *f = 0;
|
||||||
|
errno = fopen_s(&f, filename, mode);
|
||||||
|
return f;
|
||||||
|
}
|
||||||
|
#define fopen FOpen
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "format.h"
|
#include "format.h"
|
||||||
@ -1585,12 +1593,15 @@ TEST(FormatterTest, FormatExamples) {
|
|||||||
EXPECT_EQ("0123456789", s);
|
EXPECT_EQ("0123456789", s);
|
||||||
}
|
}
|
||||||
|
|
||||||
EXPECT_THROW({
|
const char *filename = "nonexistent";
|
||||||
const char *filename = "nonexistent";
|
FILE *ftest = fopen(filename, "r");
|
||||||
FILE *f = std::fopen(filename, "r");
|
int error_code = errno;
|
||||||
|
EXPECT_TRUE(ftest == 0);
|
||||||
|
EXPECT_SYSTEM_ERROR({
|
||||||
|
FILE *f = fopen(filename, "r");
|
||||||
if (!f)
|
if (!f)
|
||||||
fmt::ThrowSystemError(errno, "Cannot open file '{}'") << filename;
|
fmt::ThrowSystemError(errno, "Cannot open file '{}'") << filename;
|
||||||
}, fmt::SystemError);
|
}, error_code, "Cannot open file 'nonexistent'");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(FormatterTest, StrNamespace) {
|
TEST(FormatterTest, StrNamespace) {
|
||||||
|
@ -35,6 +35,7 @@
|
|||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
# include <crtdbg.h> // for _CrtSetReportMode
|
# include <crtdbg.h> // for _CrtSetReportMode
|
||||||
|
# define close _close
|
||||||
#endif // _WIN32
|
#endif // _WIN32
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
@ -258,7 +259,8 @@ bool IsClosed(int fd) {
|
|||||||
// Attempts to read count characters from a file.
|
// Attempts to read count characters from a file.
|
||||||
std::string Read(File &f, std::size_t count) {
|
std::string Read(File &f, std::size_t count) {
|
||||||
std::string buffer(count, '\0');
|
std::string buffer(count, '\0');
|
||||||
std::streamsize offset = 0, n = 0;
|
std::streamsize n = 0;
|
||||||
|
std::size_t offset = 0;
|
||||||
do {
|
do {
|
||||||
n = f.read(&buffer[offset], count - offset);
|
n = f.read(&buffer[offset], count - offset);
|
||||||
offset += n;
|
offset += n;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user