Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the _sopen_s() equivalent for the open() function?

Tags:

c++

c

windows

Microsoft has deprecated _open in favor of _sopen_s. What are the recommended equivalent arguments?

like image 664
user281806 Avatar asked Aug 05 '11 23:08

user281806


1 Answers

Well now I can post my nicely formatted answer, so here it is:

For

int fd = _open(name,oflags);

Replace with

int fd;
errno_t errno = _sopen_s(&fd,name,oflags,_SH_DENYNO,0);

The reason I posted this Q&A is that it provides an important bit of non-obvious info that Microsoft didn't provide. I agree that the _sopen_s is a poor replacement for _open. I only researched this topic because I was fixing a bug caused by the wrong arguments being supplied to _sopen_s. The _sopen_s was only in the code to get rid of the compiler warnings; the original _open call was fine.

like image 101
user281806 Avatar answered Sep 20 '22 18:09

user281806