Today I stumbled to MSDN's documents about Visual C++'s C runtime (example: http://msdn.microsoft.com/en-us/library/8syseb29.aspx) and find to my surprise a lot of functions that look just like POSIX syscalls: dup2
, fdopen
, stat
, execlp
, ..., except being prefixed with _
or _w
. Are these functions just wrappers to Windows API? Are they only usable with the POSIX subsystem? Are they deprecated/going to be deprecated?
POSIX Library Functions This is a reference of the POSIX functions which are not part of the Standard C Library. The POSIX 1003.1 specification was developed at the same time as the ANSI C standard. Although the POSIX standard is language-independent it is closely related to C and UNIX.
Some effort was made to ensure that the C and POSIX libraries were compatible, but in fact there are functions which are part of the POSIX standard but were never introduced into ANSI C. This is a very condensed list, consult your operating system's man-pages for a detailed information about each function.
This is a reference of the POSIX functions which are not part of the Standard C Library. The POSIX 1003.1 specification was developed at the same time as the ANSI C standard.
To provide an example of using the Posix Open function with C programming in Linux Mint 20, we have created a program that attempts to open a file. If that file already exists, then this function will simply open it; otherwise, the function will create a file with the specified name.
These functions are wrappers around Win32 APIs. You don't need to have the POSIX subsystem to use them. They are not likely to disappear - Microsoft takes backwards compatibility very seriously.
You can find the source code of the MS CRT in "\Program Files (x86)\Microsoft Visual Studio X.0\VC\crt\src". E.g. you can see that _dup2
is calling DuplicateHandle
and _stat
is using FindFirstFileEx
.
As for why they got the underscores, I could not find an official reason, but I suspect it's probably because these functions don't provide full POSIX compliance.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With