Wrong documentation for open()

Eric Blake eblake@redhat.com
Thu Apr 9 16:02:00 GMT 2015

On 04/09/2015 09:20 AM, Friedrich Lobenstock wrote:
> Hello!
> The documentation, eg. the online version at
> <https://sourceware.org/newlib/libc.html#index-open>, is wrong in
> regards to the implementation of open().
> In the documentation the signature of open() is defined as:
>     int open(const char *name, int flags, int mode)

That's documented merely as a minimum implementation; it always fails,
so it doesn't matter whether va_args is parsed compatibly or anything
else.  I see nothing wrong with that documentation being a bare minimum,
although you could go even further and write it as just:

int open(const char *ignored1, int ignored2) {
  return -1;

and still get the same linking behavior.

> BUT in the library in sys/_default_fcntl.h (included via fcntl.h) its
> signature is defined as follows:
>     int open (const char *, int, ...)

This is the correct form standardized by POSIX.

> For a minimal implementation which just returns -1 this doesn't matter,
> but not when one want's evaluate the other options after parameter "name".
> For libgloss/open.c it doesn't actually matter, but it's interface
> should also be updated, I guess.

Patches welcome.

> PS: I came across this "bug" after looking at the compilers assembly
> code and wondering why on earth it is passing parameters on the stack,
> while the called function is expecting parameters in registers.

va_arg passing often involves the stack, even when registers are
otherwise sufficient, based on platform ABI rules.  As long as you
aren't going to use the arguments, it doesn't matter ABI-wise if your
signature for those unused arguments differs from the callers idea; but
you are right that if the parameters are going to be used, then the
correct signature should be used.

Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 604 bytes
Desc: OpenPGP digital signature
URL: <http://sourceware.org/pipermail/newlib/attachments/20150409/184e1f8d/attachment.sig>

More information about the Newlib mailing list