#define _POSIX_C_SOURCE 200112L
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/mman.h>
#define SIZE 1080*4*1920*4*3
__attribute__((noreturn))
void fail (const char *const msg) {
perror(msg);
exit(-errno);
}
int main (int argc, char **argv) {
FILE *out;
char *buf;
if (NULL == (out = fopen("output.rgb", "w+")))
fail("Failed to fopen");
if (0 != ftruncate(fileno(out), SIZE))
fail("Failed to create file");
buf = mmap(NULL, SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fileno(out), 0);
if (MAP_FAILED == buf)
fail("Failed to mmap");
// use buf as if it was buf = malloc(SIZE)
munmap(buf, SIZE);
fclose(out);
return 0;
}