-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcout.cpp
47 lines (37 loc) · 847 Bytes
/
cout.cpp
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
#include <err.h>
#include <signal.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <iostream>
static bool loop = true;
static void
signal_handler(int sig)
{
if (sig == SIGALRM)
loop = false;
}
#define LOOP(seconds, counter) \
if (alarm(seconds) == (unsigned int)-1) \
err(EXIT_FAILURE, "alarm"); \
for (loop = true, counter = 0; loop; counter++)
int
main(void)
{
size_t counter;
unsigned int seconds = 5;
signal(SIGALRM, signal_handler);
FILE *fh_printf = stderr;
FILE *fh_printfs = stderr;
FILE *fh_puts = stderr;
size_t size = BUFSIZ;
char str[size];
memset(str, 'a', sizeof str);
str[size - 1] = '\0';
LOOP(seconds, counter)
std::cout << str;
fprintf(fh_puts, "%zu %zu std::cout << str\n", size, counter / seconds);
return EXIT_SUCCESS;
}