#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>


char *fname = "test.tmp";

void main()
{
  int fd;

  /* create a readonly file */
  unlink(fname);
  if ((fd=open(fname,O_RDWR|O_CREAT,0444)) == -1) {
    printf("first open failed : %s\n",strerror(errno));
    exit(1);
  }
  close(fd);

  /* try and open it for reading. This should work. Under linux 2.0 it doesn't */
  if ((fd=open(fname,O_RDONLY|O_CREAT,0666)) == -1) {
    printf("2nd open failed : %s\n",strerror(errno));
    exit(1);
  }
  close(fd);

  /* it worked - clean up */
  unlink(fname);

  printf("all OK\n");
}
