Open () system call polymorphism

I just discovered that the open () system call (man 2 open) has two versions:

int open(const char *pathname, int flags); int open(const char *pathname, int flags, mode_t mode); 

Indeed, it can be used either in a single C file, and both will work. How can standard C achieve this?

+8
c system-calls
source share
2 answers

Actually, this is not an overload of a C ++ style function. It is just that open() is a variable:

 int open(const char *fname, int flags, ...); 

And only if flags are required for this, will he look for a third argument.

+4
source share

This can be done as a variable function of the argument.

The POSIX documentation for open defines this as follows:

 int open(const char *path, int oflag, ...); 
+4
source share

All Articles