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

#define NUM_ITER 1024

int main ( int argc, char **argv ) {
	const char data[] = "Liberate";
	size_t data_len = strlen ( data );
	const char *filename;
	int fd; 
	unsigned int i;

	if ( argc != 2 ) {
		fprintf ( stderr, "Syntax: %s output_file\n", argv[0] );
		exit ( 1 );
	}
	filename = argv[1];
	fd = open ( filename, ( O_WRONLY | O_CREAT | O_EXCL ), 0666 );
	if ( fd < 0 ) {
		fprintf ( stderr, "Could not create \"%s\": %s\n",
			  filename, strerror ( errno ) );
		exit ( 1 );
	}

	for ( i = 0 ; i < NUM_ITER ; i++ ) {
		if ( write ( fd, data, data_len ) != data_len ) {
			fprintf ( stderr, "Could not write: %s\n",
				  strerror ( errno ) );
			exit ( 1 );
		}
		if ( fdatasync ( fd ) != 0 ) {
			fprintf ( stderr, "Could not fdatasync: %s\n",
				  strerror ( errno ) );
			exit ( 1 );
		}
	}
	return 0;
}

