This is the mail archive of the glibc-linux@ricardo.ecn.wfu.edu mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: open() and fopen()


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]