#include <sys/mman.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
long long somma(FILE *f)
{
int fd;
struct stat sb;
char* p;
fd = fileno(f);
if (fd == -1) {
return 1;
}
if (fstat(fd, &sb) == -1) {
return 2;
}
p = mmap(NULL, sb.st_size * 512, PROT_READ, MAP_PRIVATE, fd, 0);
int i = 0;
long long somma = 0;
int segno = 1;
for(i=0;i<sb.st_size;i++)
{
if(p[i]==32)
{
i++;
}
if(p[i]==45)
{
segno = -1;
i++;
}
else
{
segno = 1;
}
while(p[i] >= 48 && p[i] <= 57)
{
somma += segno * (p[i] - '0');
i++;
}
}
return somma;
}