Warning:  Undefined array key "view" in /var/www/html/wp-content/uploads/classes/so/1920/lab-examples/index.php on line 2
Warning:  Cannot modify header information - headers already sent by (output started at /var/www/html/wp-content/uploads/classes/so/1920/lab-examples/index.php:2) in /var/www/html/wp-content/uploads/classes/so/1920/lab-examples/index.php on line 47
Warning:  Cannot modify header information - headers already sent by (output started at /var/www/html/wp-content/uploads/classes/so/1920/lab-examples/index.php:2) in /var/www/html/wp-content/uploads/classes/so/1920/lab-examples/index.php on line 48
Warning:  Cannot modify header information - headers already sent by (output started at /var/www/html/wp-content/uploads/classes/so/1920/lab-examples/index.php:2) in /var/www/html/wp-content/uploads/classes/so/1920/lab-examples/index.php on line 49
Warning:  Cannot modify header information - headers already sent by (output started at /var/www/html/wp-content/uploads/classes/so/1920/lab-examples/index.php:2) in /var/www/html/wp-content/uploads/classes/so/1920/lab-examples/index.php on line 50
Warning:  Cannot modify header information - headers already sent by (output started at /var/www/html/wp-content/uploads/classes/so/1920/lab-examples/index.php:2) in /var/www/html/wp-content/uploads/classes/so/1920/lab-examples/index.php on line 51
/**
 *  legge il contenuto di un file utilizzando il meccanismo di
 *  mappatura dei file in memoria
 */
#include 
#include 
#include 
#include 
#include 
#include 
#include 
int main(int argc, char *argv[]) {
    struct stat sb;
    off_t i;
    char *p;
    int fd;
    if (argc < 2) {
        fprintf(stderr, "uso: %s \n", argv[0]);
        exit(1);
    }
    if ((fd = open(argv[1], O_RDONLY)) == -1) {
        perror(argv[1]);
        exit(1);
    }
    if (fstat(fd, &sb) == -1) {
        perror("fstat");
        exit(1);
    }
    if (!S_ISREG(sb.st_mode)) {
        fprintf(stderr, "%s non รจ un file\n", argv[1]);
        exit(1);
    }
    if ((p = mmap(NULL, sb.st_size, PROT_READ, MAP_SHARED, fd, 0)) ==
        MAP_FAILED) {
        perror("mmap");
        exit(1);
    }
    if (close(fd) == -1) {
        perror("close");
        exit(1);
    }
    // printf("puntatore: %p\n", p);
    // p[4]=55; // tentativo di modificare una pagina su una mappatura in sola lettura
    
    for (i = 0; i < sb.st_size; i++)
        putchar(p[i]);
    if (munmap(p, sb.st_size) == -1) {
        perror("munmap");
        exit(1);
    }
}