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

int main(void)
{
	char* zero;
	int fd;
	ssize_t bw;
	int fs;
	struct stat sb;
	int cl;

	zero = calloc(0xFFFF, 0x1);
	if (zero == NULL) {
		printf("Error calloc'ing memory\n");
	}
	zero = memset(zero, 0x30, 0xFFFF);

	fd = open("foo.txt", O_WRONLY|O_CREAT|O_TRUNC, S_IRUSR|S_IWUSR);
	if (fd == -1) {
		perror("open");
	}
	bw = write(fd, zero, 0xFFFF);
	if (bw == -1) {
		perror("write");
	} else if (bw == 0) {
		perror("write");
	} else if (bw != 0xFFFF) {
		printf("Did not write entire file = %lx\n", bw);
	}
	if (fsync(fd) == -1) {
		perror("fsync");
	}
	if (fstat(fd,&sb) == -1) {
		perror("fstat");
	}
	if (close(fd) == -1) {
		perror("close");
	}
	free(zero);

	return 0;
}
