-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathslow.c
More file actions
55 lines (44 loc) · 845 Bytes
/
Copy pathslow.c
File metadata and controls
55 lines (44 loc) · 845 Bytes
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
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include "arg.h"
char *argv0;
static void usage(void);
void
usage()
{
fprintf(stderr, "usage: %s [-t usec] [-f]\n", argv0);
exit(1);
}
int
main(int argc, char *argv[])
{
char buffer;
size_t nread;
useconds_t useconds = 1000000; // default 1 second
unsigned int flush = 0;
ARGBEGIN {
case 't':
useconds = atoi(EARGF(usage()));
break;
case 'f':
flush = 1;
break;
default:
usage();
} ARGEND;
while ((nread = fread(&buffer, 1, sizeof buffer, stdin)) > 0) {
usleep(useconds);
if (fwrite(&buffer, 1, nread, stdout) != nread) {
fprintf(stderr, "stdout: write error");
exit(1);
}
if (flush)
fflush(stdout);
}
if (ferror(stdin)) {
fprintf(stderr, "stdin: read error");
exit(1);
}
return 0;
}