Question

open() is a variable length argument function in POSIX prototype, and mode=0 when two argument version is called. The third argument mode works when O_CREAT bit is set in flags.

What i cannot get is : What does the wrapper do when open(fname, flags) is called where flags contains O_CREAT, in other words, how the wrapper know i did't pass the third argument mode as the va_arg thing cannot determine whether there is argument passed to or not and only one version of open exists as it's a C function?

Was it helpful?

Solution

It doesn't.

The implementation will evaluate the third argument whenever it sees the O_CREAT flag. If you didn't pass the third argument, behaviour is undefined, much in the same way as when you lie to printf about its arguments (e.g. pass %s as the format string, but forget to actually pass a string to be inserted).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top