Cod sursa(job #1334618)

Utilizator crushackPopescu Silviu crushack Data 4 februarie 2015 15:29:22
Problema A+B Scor 0
Compilator cpp Status done
Runda Lista lui wefgef Marime 0.59 kb
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/mman.h>

#include <stdio.h>

const char IN[] = "adunare.in";

int fd, rc, size;
char * text;

int main() {

	fd = open(IN, O_RDWR | O_CREAT, 0644);
	if ( fd < 0 )
		return - 1;

	size = lseek(fd, 0, SEEK_END);
	lseek(fd, 0, SEEK_SET);

	text = (char *)mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0 );

	if ( (void *) text == MAP_FAILED )
		return -3;

	printf("%s\n", text);

	rc = munmap( (void *) text, size );
	if ( rc < 0 )
		return - 4;

	rc = close(fd);
	if ( rc < 0 )
		return - 2;

	return 0;
}