0

I'm reviewing man(2) pages on NetBSD 9, and have seen that all of the documents (write(2), open(2), pipe(2)) mention the Standard C Library at the top.

My understanding was that system calls were independent of library functions (such as those in libc). I don't see a similar mention in the Linux System call Manual. Does this mean that invoking these methods is calling some wrapper function included in libc, instead of directly calling a kernel function? Is this generally true, or just a feature of NetBSD?

1
  • 3
    You can only do system calls from assembly, not from C, so yes, any of those "system calls" from section 2 of the manual is actually a wrapper implemented in the standard C library (libc), which is linked either statically or dynamically into your program. Commented Jan 16, 2021 at 7:06

1 Answer 1

1

open(), for example, is a C standard library function.

The implementation is dependent on the OS. On Unix-like systems it's typically implemented as a syscall.

So the application calls open(), and that calls syscall() on Unix-like systems.

C has been ported to a lot of platforms, and not all of them have syscall functionality. Their implementation is different.

So we say that things like open() are part of the standard C library, because the library abstracts from the underlying OS implementation.

3
  • 1
    They aren't part of the library defined by the C standard(s) ('highlevel' calls like fopen fwrite fputc are, 'lowlevel' calls like open write pipe aren't), but most C implementations especially on Unix for convenience bundle them in the same library file canonically libc.whatever (OTOH some math routines, even though in standard C, are traditionally in a separate file -lmath) Commented Jan 16, 2021 at 4:56
  • 1
    @dave_thompson_085 "Standard C Library" here means libc, the library linked by -lc. I.e. it means the library implementing the majority of C language functionality (and POSIX extensions to that language). It has less to do with actual standards. See e.g. the pipe(2) manual. Commented Jan 16, 2021 at 7:01
  • open(2) does not call the syscall(2) wrapper. (On x86-64, system calls happen through a processor instruction called just syscall, but that's a different thing). Also, on Linux, open(2) is implemented as a wrapper for openat(2) -- the open system call is only kept for binary compatibility, and only on older platforms. Commented Jan 16, 2021 at 7:15

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.