#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <math.h>

#define FILE_MODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)

int main (int argc, char *argv[])
{
  int i = 0;
  int iterations;
  double x;
  FILE *fp;
  int fd;
  int n;
  char buf[] = "a";

  if (argc == 2) {
    iterations = atoi (argv[1]);
  } else {
    printf ("Usage: loop [iterations]\n");
    exit (-1);
  }

  fd = creat ("temp", FILE_MODE);

  for (i=0; i<iterations/7; i++) {
    n = write (fd, buf, 1);
    if (n != 1) {
      perror ("error");
    }
    n = fsync (fd);
    if (n != 0) {
      perror ("error");
    }
  } 
  close (fd);
}
