This is the mail archive of the
glibc-linux@ricardo.ecn.wfu.edu
mailing list for the glibc project.
Re: open() and fopen()
- From: Nix <nix at esperi dot demon dot co dot uk>
- To: glibc-linux at ricardo dot ecn dot wfu dot edu
- Date: 23 Nov 2001 08:56:12 +0000
- Subject: Re: open() and fopen()
- References: <3BFDF860.3050301@bilten.metu.edu.tr>
- Reply-to: glibc-linux at ricardo dot ecn dot wfu dot edu
On Fri, 23 Nov 2001, Muzaffer Ozakca muttered drunkenly:
> As you know, there are 2 different open() calls:
>
> a) open(char *path, int flags, mode_t mode)
> b) open(char *path, int flags)
>
> How does the compiler distinguish between two? I guess stdarg stuff
> cannot be used, as we should know beforehand the number and types of
> the arguments.
stdarg stuff is used, because we do know that at argument parse time.
,----[ open(2) ]
| mode should always be specified when O_CREAT is in the
| flags, and is ignored otherwise.
`----
so if (flags | O_CREAT), then you'd better have passed a mode too.
> Anybody knows what fopen() does call? is it open() in the C library or directly the system call SYS_open, using syscall().
stdio/fopen.c:fopen() calls sysdeps/generic/sysd-stdio.c:__stdio_open()
(the HURD has its own version), which sanitizes the arguments and calls
__open() (the syscall).
(btw, does anyone know why libio is in glibc? Is it just called by
libstdc++'s iostreams normally --- and why on earth doesn't libstdc++
just call stdio?)
--
`Many people have tried whispering in his ear, and indeed bellowing
with megaphones but up to now he's seemed to be completely
clue-immune.' --- John Winters