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

struct FileContents {
		long value1;
		long value2;
		char string100chars[100];
};

int main(int argc, char *argv[]) {
	if ( argc != 2 ) {
		printf( "wrong arguments\n");
		return 1;
	}
	int fd = open(argv[1], O_CREAT|O_RDWR|S_IRUSR|S_IWUSR);
	if ( fd < 0 ) {
		printf( "Could not open file ");
		return 2;
	}

	struct FileContents content;
	content.value1 = 12345;
	content.value2 = 54321;
	strncpy(content.string100chars, argv[1], 100);

	write(fd,(char*)&content, sizeof(content));
	{
		struct FileContents readContent;
		if(0 != lseek(fd,0,SEEK_SET)) perror("lseek error:");

		read(fd,(char*)&readContent, sizeof(readContent));
		if ( content.value1 != readContent.value1 || content.value2 != readContent.value2 ) {
			printf("Read values do not match with written data: %d and %d\n" , readContent.value1 ,readContent.value2 );
			return 6;
		}
	}
	return 0;
}
