Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the POSIX like functions in MSVC's C runtime?

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?

like image 250
Siyuan Ren Avatar asked May 05 '14 16:05

Siyuan Ren


People also ask

Are POSIX functions in C library?

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.

Is POSIX compatible with ANSI C?

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.

Which functions are not part of the standard C library?

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.

How to use POSIX open with C programming in Linux Mint 20?

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.


1 Answers

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.

like image 138
Igor Skochinsky Avatar answered Sep 17 '22 00:09

Igor Skochinsky