Cod sursa(job #2473674)

Utilizator Kln1000Ciobanu Bogdan Kln1000 Data 14 octombrie 2019 02:07:08
Problema A+B Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.05 kb
// Copyright 2019 Ciobanu Bogdan-Calin
// [email protected]

#include <iostream>
//#include "./Parser.h"
//#include "./Writer.h"

#include <cstdio>
#include <cstring>
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>

int main() {
    int fd = open("adunare.out", O_RDWR | O_CREAT, (mode_t)0600);
    const char* text = "2\n";
    size_t textsize = strlen(text) + 1;
    lseek(fd, textsize-1, SEEK_SET);
    write(fd, "", 1);
    char* map = (char*)mmap(0, textsize, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
    memcpy(map, text, strlen(text));
    msync(map, textsize, MS_SYNC);
    munmap(map, textsize);
    close(fd);
    return 0;
}


/*
int main() {
    mapping_writer t("test.txt");
    mapping_parser f("test.in");
    int x = 10;
    uint8_t y = 100;
    uint64_t z = 10000000000022;
    bool m = false;
    int o = 0;
    f >> x;
    f >> y;
    t << x << "\n";
    t << y << "\n";
    t << z << "\n";
    t << m << "\n";
    t << o << "\n";
    return 0;
}
*/