I know that a call to the glibc "write" function calls in it's turn to the sys_call write function which is a kernel function.
because sys_call is a kernel function the CPU has to change the ring to zero store the processes registers and so on.
But does it always switches to kernel mode? for example, if i do


does it still tries to find it in the file descriptors array?
I see in the glibc source code that it does check for fd>0 but i don't see any jump to the sys_call there (it seems like the baracks for main() ends before any call to the alias_write.

/* Write NBYTES of BUF to FD. Return the number written, or -1. */
__libc_write (int fd, const void *buf, size_t nbytes)
if (nbytes == 0)
return 0;
if (fd < 0)
__set_errno (EBADF);
return -1;
if (buf == NULL)
__set_errno (EINVAL);
return -1;

__set_errno (ENOSYS);
return -1;
libc_hidden_def (__libc_write)
stub_warning (write)

weak_alias (__libc_write, __write)
libc_hidden_weak (__write)
weak_alias (__libc_write, write)
#include <stub-tag.h>

So the question is both:

Where does the glibc actually calls the sys_write
Is it true that glibc doesn't call the sys_write if fd<0?