C – Why are both fstat(2) and fstat(3) present and which one should I use?

Why are both fstat(2) and fstat(3) present and which one should I use?… here is a solution to the problem.

Why are both fstat(2) and fstat(3) present and which one should I use?

I tried to read the man page for fstat and I got fstat(2) , > fstat(3) and fstat(3P).

Having used the system(2)

command in the past, I know the difference is that I have to write a prototype myself to announce the functionality (this is reflected in the fstat(2) man page).

But I’ve never seen a function that is both C (3) and system (2). What are the benefits of using one over the other? C even how to tell if I’m using (2) or (3).

Also, I know that sys/stat.h is platform-specific, so which of (2) and (3) is more secure for cross-platform use? Because I wrote in Windows page I don’t see the prototype line in the example, I’m assuming it’s (3).

Please explain that this is because I can’t understand why both exist.

Solution

Web-based online help pages are always the next best choice because they only show you a generic View of the interface. If you use the man command on your own system (at least for Unix-like systems), the result should reflect your actual installation, assuming you have installed your distribution’s documentation correctly.

Part 2 of the manual is intended to describe system calls rather than standard library APIs. However, at least in the case of Linux documentation, Section 2 is also used to describe the library wrapper around system calls, which effectively documents the specific functionality implemented by standard C libraries (usually glibc). In this case, Section 3P is used to document documents extracted or adapted from the POSIX standard. Therefore, if you want to write portable code, use only the features documented in the 3P section. If you are happy to use all the extensions available on your system, use Part 2.

<a href=”https://www.man7.org/linux/man-pages/” rel=”noreferrer noopener nofollow”>man7.org and linux.die.net use a different repository of online help pages; For the latter, Part 3P does not exist, and the Posix Programming Manual is in Part 3. So https://www.man7.org/linux/man-pages/man3/fstat.3p.html sum https://linux.die.net/man/3/fstat contains the same information. If you use a Linux distribution, you may find that man 3 fstat actually provides you with the pages from section 3p.

In any case, there is only one interface in the C library, which should conform to the Posix standard, but can be extended.

Related Problems and Solutions