#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>

int main(int argc, char**argv)
{
  int fd;
  off_t i = 1 << 20;
  static const char buf[2 << 10];

  if (argc != 2) {
    fprintf(stderr, "usage: %s filename", *argv);
    return 1;
  }

  fd= open(argv[1], O_CREAT | O_EXCL | O_APPEND | O_WRONLY, 0666);
  if (fd == -1) {
    perror("open");
    return 2;
  }

  while (i--) {
    if (write(fd, buf, sizeof buf) != sizeof buf) {
      perror("write");
      return 3;
    }
  }

  fdatasync(fd);
  close(fd);
}
