include stdlib include stdio include unistd include sys types include

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int main(int argc, char ** argv)
{
unsigned long blocksize;
char *buffer;
int file;
int i;
if (argc != 3) {
printf("%s: <filename> <block size>\n", argv[0]);
exit(1);
}
blocksize = atol(argv[2]);
file = open(argv[1], O_RDONLY);
if (file < 0) {
perror("Failed to open file for reading");
exit(1);
}
buffer = malloc(blocksize);
do {
i = read(file, buffer, blocksize);
} while (i > 0);
return 0;
}