Skip to content
Snippets Groups Projects
Commit 1b313e25 authored by William F Godoy's avatar William F Godoy
Browse files

Additional changes

Restoring std:: for cstdio functions
Removing warnings explicitly with pragmas
parent 81bcb116
No related branches found
No related tags found
1 merge request!212Solve Issue #211 and made changes due to Windows warnings and bugs
......@@ -20,11 +20,8 @@
#include "adios2/helper/adiosString.h"
// remove ctime warning on Windows
#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_DEPRECATE
#define _SCL_SECURE_NO_WARNINGS
#define _SCL_SECURE_NO_DEPRECATE
#ifdef _WIN32
#pragma warning(disable : 4996)
#endif
namespace adios2
......
......@@ -33,11 +33,10 @@
#include <chrono>
#include <string>
#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_DEPRECATE
#define _SCL_SECURE_NO_WARNINGS
#define _SCL_SECURE_NO_DEPRECATE
// remove warnings on Windows
#ifdef _WIN32
#pragma warning(disable : 4996) // fopen
#pragma warning(disable : 4477) // strcpy, sprintf
#endif
namespace adios2
......@@ -302,7 +301,7 @@ int MPI_File_open(MPI_Comm /*comm*/, const char *filename, int amode,
}
mode += "b";
*fh = fopen(filename, mode.c_str());
*fh = std::fopen(filename, mode.c_str());
if (!*fh)
{
std::snprintf(mpierrmsg, MPI_MAX_ERROR_STRING, "File not found: %s",
......@@ -316,10 +315,10 @@ int MPI_File_close(MPI_File *fh) { return fclose(*fh); }
int MPI_File_get_size(MPI_File fh, MPI_Offset *size)
{
long curpos = ftell(fh);
long curpos = std::ftell(fh);
fseek(fh, 0, SEEK_END); // go to end, returned is the size in bytes
long endpos = ftell(fh);
fseek(fh, curpos, SEEK_SET); // go back where we were
long endpos = std::ftell(fh);
std::fseek(fh, curpos, SEEK_SET); // go back where we were
*size = static_cast<MPI_Offset>(endpos);
// printf("MPI_File_get_size: fh=%d, size=%lld\n", fh, *size);
return MPI_SUCCESS;
......@@ -331,7 +330,7 @@ int MPI_File_read(MPI_File fh, void *buf, int count, MPI_Datatype datatype,
// FIXME: int count can read only 2GB (*datatype size) array at max
size_t bytes_to_read = static_cast<size_t>(count) * datatype;
size_t bytes_read;
bytes_read = fread(buf, 1, bytes_to_read, fh);
bytes_read = std::fread(buf, 1, bytes_to_read, fh);
if (bytes_read != bytes_to_read)
{
std::snprintf(mpierrmsg, MPI_MAX_ERROR_STRING,
......@@ -348,7 +347,7 @@ int MPI_File_read(MPI_File fh, void *buf, int count, MPI_Datatype datatype,
int MPI_File_seek(MPI_File fh, MPI_Offset offset, int whence)
{
return fseek(fh, offset, whence) == MPI_SUCCESS;
return std::fseek(fh, offset, whence) == MPI_SUCCESS;
}
int MPI_Get_count(const MPI_Status *status, MPI_Datatype, int *count)
......
......@@ -41,10 +41,10 @@ void STLVector::ResizeData(const size_t size)
{
m_Data.resize(size);
}
catch (std::bad_alloc &e)
catch (...)
{
std::throw_with_nested(
std::runtime_error("ERROR: bad_alloc detected when resizing "
std::runtime_error("ERROR: possible overflow when resizing "
"data buffer with size " +
std::to_string(size) + "\n"));
}
......@@ -63,10 +63,10 @@ void STLVector::ResizeMetadata(const size_t size)
{
m_Metadata.resize(size);
}
catch (std::bad_alloc &e)
catch (...)
{
std::throw_with_nested(
std::runtime_error("ERROR: bad_alloc detected when resizing "
std::runtime_error("ERROR: possible overflow when resizing "
"metadata buffer with size " +
std::to_string(size) + "\n"));
}
......
......@@ -15,11 +15,8 @@
/// \endcond
// removes fopen warning on Windows
#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_DEPRECATE
#define _SCL_SECURE_NO_WARNINGS
#define _SCL_SECURE_NO_DEPRECATE
#ifdef _WIN32
#pragma warning(disable : 4996) // fopen
#endif
namespace adios2
......@@ -36,7 +33,7 @@ FilePointer::~FilePointer()
{
if (m_IsOpen)
{
fclose(m_File);
std::fclose(m_File);
}
}
......@@ -56,16 +53,16 @@ void FilePointer::Open(const std::string &name, const OpenMode openMode)
if (m_OpenMode == OpenMode::Write)
{
m_File = fopen(name.c_str(), "wb");
m_File = std::fopen(name.c_str(), "wb");
}
else if (m_OpenMode == OpenMode::Append)
{
// need to change when implemented
m_File = fopen(name.c_str(), "ab");
m_File = std::fopen(name.c_str(), "ab");
}
else if (m_OpenMode == OpenMode::Read)
{
m_File = fopen(name.c_str(), "rb");
m_File = std::fopen(name.c_str(), "rb");
}
if (ferror(m_File))
......@@ -80,7 +77,7 @@ void FilePointer::Open(const std::string &name, const OpenMode openMode)
void FilePointer::SetBuffer(char *buffer, size_t size)
{
const int status = setvbuf(m_File, buffer, _IOFBF, size);
const int status = std::setvbuf(m_File, buffer, _IOFBF, size);
if (!status)
{
......@@ -98,7 +95,7 @@ void FilePointer::Write(const char *buffer, size_t size)
{
m_Profiler.Timers.at("write").Resume();
}
auto writtenSize = fwrite(buffer, sizeof(char), size, m_File);
auto writtenSize = std::fwrite(buffer, sizeof(char), size, m_File);
if (m_Profiler.IsActive)
{
......@@ -141,7 +138,7 @@ void FilePointer::Write(const char *buffer, size_t size)
void FilePointer::Flush()
{
const int status = fflush(m_File);
const int status = std::fflush(m_File);
if (status == EOF)
{
......@@ -157,7 +154,7 @@ void FilePointer::Close()
m_Profiler.Timers.at("close").Resume();
}
const int status = fclose(m_File);
const int status = std::fclose(m_File);
if (m_Profiler.IsActive)
{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment