This is the mail archive of the
glibc-linux@ricardo.ecn.wfu.edu
mailing list for the glibc project.
Re: open() and fopen()
- From: Urs Thuermann <urs at isnogud dot escape dot de>
- To: glibc-linux at ricardo dot ecn dot wfu dot edu
- Date: 23 Nov 2001 10:00:05 +0100
- Subject: Re: open() and fopen()
- References: <3BFDF860.3050301@bilten.metu.edu.tr>
- Reply-to: glibc-linux at ricardo dot ecn dot wfu dot edu
Muzaffer Ozakca <muzaffer.ozakca@bilten.metu.edu.tr> writes:
> a) open(char *path, int flags, mode_t mode)
> b) open(char *path, int flags)
>
> How does the compiler distinguish between two?
open(2) is declared as int open(const char *file, int flags, ...);
The ... is called ellipsis in ANSI C and means there may follow any
number of arguments of any type. The compiler just pushes these args
onto the stack without any checking.
> I guess stdarg stuff cannot be used, as we should know beforehand
> the number and types of the arguments.
open() could be implemented using stdarg. The flags argument tells
you whether there is a mode argument or not. The mode argument has to
be there iif O_CREAT is set in the flags argument.
> Anybody knows what fopen() does call? is it open() in the C library
> or directly the system call SYS_open, using syscall().
No. fopen(3) is a library function that implements buffered I/O
(together with fread(3), fwrite(3), fclose(3), etc.). Of course,
these functions must use the open(2), read(2), write(2), close(2),
etc. syscalls to do their job. RTFM.
urs