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
/**
* duplica il contenuto di un file specificato, concatenandone
* una copia del precedente contenuto
*/
/* necessario per utilizzare la funzionalita' non-POSIX mremap: */
#define _GNU_SOURCE
#include
#include
#include
#include
#include
#include
#include
int main(int argc, char *argv[]) {
struct stat sb;
char *p;
int fd, size, i;
if (argc < 2) {
fprintf(stderr, "uso: %s \n", argv[0]);
exit(1);
}
if ((fd = open(argv[1], O_RDWR)) == -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);
}
/* mappa il contenuto originale del file */
size = sb.st_size;
if ((p = (char *)mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0)) == MAP_FAILED) {
perror("mmap");
exit(1);
}
/* raddoppia la dimensione del file */
if (ftruncate(fd, size * 2) == -1) {
perror("ftruncate");
exit(1);
}
/* estende la mappatura alla nuova dimensione */
if ((p = (char *)mremap(p, size, size * 2, MREMAP_MAYMOVE)) == MAP_FAILED) {
perror("mremap");
exit(1);
}
/* duplica il precedene contenuto sulla seconda parte */
for (i = 0; i < size; i++)
p[i + size] = p[i];
size *= 2;
printf("File '%s' duplicato!\n", argv[1]);
if (close(fd) == -1) {
perror("close");
exit(1);
}
if (munmap(p, size) == -1) {
perror("munmap");
exit(1);
}
}