Skip to content

Any chance std::fopen() call can be changed to std::fopen_s()? #199

@misuo

Description

@misuo

In sendfile_defs_default.hpp the restinio open_file() function uses std::fopen().

Is there any chance this can be changed to using std::fopen_s()?

Should be a simple change:

inline file_descriptor_t
open_file( const char * file_path )
{
	file_descriptor_t file_descriptor;
        std::fopen_s( &file_descriptor, file_path, "rb" ); // return code ignored.
  ...
}

Background

I'm using MSVC and want to build with security enhancements in the CRT library, in which fopen_s() is prefered, see MS documentation.

When compiling my code with "treat warnings as errors" and using restinio, I see...

...\restinio\sendfile_defs_default.hpp(42,43): error C2220: the following warning is treated as an error
	file_descriptor_t file_descriptor = std::fopen( file_path, "rb" );
...\sendfile_defs_default.hpp(42,43): warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. (compiling source file 

I do not want to define the _CRT_SECURE_NO_WARNINGS as this will disable security enhancements for the rest of the code. I think part of the problem is that open_file() is an inline function.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions