[8712] in Athena Bugs

home help back first fref pref prev next nref lref last post

vax 7.3P: open() or open(2), take your pick

daemon@ATHENA.MIT.EDU (cfields@Athena.MIT.EDU)
Wed Dec 4 19:56:59 1991

From: cfields@Athena.MIT.EDU
To: bugs@Athena.MIT.EDU
Date: Wed, 04 Dec 91 19:56:48 EST

System name:		get-a-life
Type and version:	CVAXSTAR 7.3P
Display type:		SM

What were you trying to do?

#include <sys/types.h>
#include <sys/uio.h>
#include <sys/file.h>
#include <sys/errno.h>

main()
{
  int fd, len;

  fd = open("/tmp/foobar", O_CREAT | O_APPEND, 0666);
  len = write(fd, "test", 4);
  close(fd);
}


What's wrong:

  open() is stupid.  O_APPEND does not imply to it that you're
interested in writing to the file. You must also specify O_WRONLY
or O_RDWR to be able to actually write the thing.

  When you do attempt to write the file, write() returns EBADF
(bad file descriptor) in errno. This is not very helpful.

What should have happened:

  One of the following, in order of most unrealistic fantasy:

    1.) O_APPEND should imply O_WRONLY if none of the
	other flags have been set, and this should be
	documented.

    2.) open() should return EHUH?, implying that it's
	actually the programmer who has done something
	stupid, and this should be documented. Reading
	in append mode is clearly a useful feature.

    3.) write() should return an error message indicating
	that the file was opened read-only, instead of
	EBADF.

    4.) The man page should mention that O_APPEND only
	specifies how writes would occur, assuming they
	could, and does not in any way imply they can,
	contrary to (IMHO) expectation.

Please describe any relevant documentation references:

  open(2), write(2)

home help back first fref pref prev next nref lref last post