I have to write a function that accepts a variable number of arguments, similar to the open() function
int open (const char *filename, int flags[, mode_t mode])
-
I had a look at the va_list functionality, but how can I find out how many arguments the user has supplied? I dont want to have a parameter in the function that indicates this.
-
Being a sort of newbie, where can I look how the open() function is implemented? How does open() know whether the user has supplied the mode argument or not?
Thanks in advance.
You cannot. The caller must either supply a trailing sentinel argument (e.g. a
0), or explicitly tell the function how many arguments to expect (e.g. the format fields inprintf).openknows to expect the third argument because you will have set theO_CREATflag in theflagsargument.