1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
18 #define BUFFERSIZE 4096
20 /* This flag controls termination of the main loop. */
21 volatile sig_atomic_t keep_going = 1;
23 /* The signal handler just clears the flag and re-enables itself. */
24 void catch_alarm(int sig)
27 signal(sig, catch_alarm);
30 int main(int argc, char **argv)
33 unsigned char buf[BUFFERSIZE];
35 unsigned int test_time;
36 mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH;
39 printf("Invalid number of arguments.\n");
40 printf("Usage %s <file> <test_time_in_seconds>\n", argv[0]);
45 test_time = atoi(argv[2]);
47 /* Establish a handler for SIGALRM signals. */
48 signal(SIGALRM, catch_alarm);
50 /* Set an alarm to go off in a little while. */
53 fd = open(file, O_RDWR|O_TRUNC|O_CREAT|O_SYNC|O_LARGEFILE, mode);
55 fprintf(stderr, "Error: Cannot open file named ");
60 memset(buf, 1, BUFFERSIZE);
62 for (i = 0; i < 1024; i++) {
63 rc = write(fd, buf, BUFFERSIZE);
65 fprintf(stderr, "Error: Write error ");
68 } else if (rc != BUFFERSIZE) {
69 fprintf(stderr, "Error: Ddidn't write all data \n");
73 if (ftruncate(fd, 0) < 0) {
74 fprintf(stderr, "Error: Truncate error ");
81 fprintf(stderr, "Error: Cannot close ");