blob: 1d3025bcd9fc1ecf871fcb28f1546d74a424a659 (
plain)
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
int main (int argc, char **argv)
{
char *file = NULL;
int fd = -1;
char *buffer = NULL;
size_t buf_size = 0;
size_t written = 0;
int ret = 0;
off_t offset = 0;
int i = 0;
int loop_count = 5;
if (argc < 2) {
printf ("Usage:%s <filename>\n", argv[0]);
return -1;
}
file = argv[1];
buf_size = 1024;
buffer = calloc(1, buf_size);
if (!buffer) {
perror("calloc");
return -1;
}
memset (buffer, 'R', buf_size);
fd = open(file, O_WRONLY);
if (fd == -1) {
perror("open");
return -1;
}
for (i = 0; i < loop_count; i++) {
ret = write (fd, buffer, buf_size);
if (ret == -1) {
perror("write");
return ret;
} else {
written += ret;
}
offset = lseek (fd, 0 , SEEK_SET);
}
free(buffer);
return 0;
}
|