1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
20 #define BUFFERSIZE 4096
22 /* This flag controls termination of the main loop. */
23 volatile sig_atomic_t keep_going = 1;
25 /* The signal handler just clears the flag and re-enables itself. */
26 void catch_alarm(int sig)
29 signal(sig, catch_alarm);
32 int main(int argc, char **argv)
35 unsigned char buf[BUFFERSIZE];
37 unsigned int test_time;
38 mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH;
41 printf("Invalid number of arguments.\n");
42 printf("Usage %s <file> <test_time_in_seconds>\n", argv[0]);
47 test_time = atoi(argv[2]);
49 /* Establish a handler for SIGALRM signals. */
50 signal(SIGALRM, catch_alarm);
52 /* Set an alarm to go off in a little while. */
55 fd = open(file, O_RDWR|O_TRUNC|O_CREAT|O_SYNC|O_LARGEFILE, mode);
57 fprintf(stderr, "Error: Cannot open file named ");
62 memset(buf, 1, BUFFERSIZE);
64 for (i = 0; i < 1024; i++) {
65 rc = write(fd, buf, BUFFERSIZE);
67 fprintf(stderr, "Error: Write error ");
70 } else if (rc != BUFFERSIZE) {
71 fprintf(stderr, "Error: Ddidn't write all data \n");
75 if (ftruncate(fd, 0) < 0) {
76 fprintf(stderr, "Error: Truncate error ");
83 fprintf(stderr, "Error: Cannot close ");