1 | #include <stdlib.h>
|
---|
2 | #include <stdio.h>
|
---|
3 | #include <io.h>
|
---|
4 | #include <string.h>
|
---|
5 | #include <fcntl.h>
|
---|
6 |
|
---|
7 | #ifdef WIN32
|
---|
8 | #define sleep(sec) _sleep(sec*1000)
|
---|
9 | #endif
|
---|
10 |
|
---|
11 | static int bail (const char *msg)
|
---|
12 | {
|
---|
13 | fprintf (stderr, "TEST ERROR: %s: %s (%d)\n", msg, strerror(errno), errno);
|
---|
14 | return errno;
|
---|
15 | }
|
---|
16 |
|
---|
17 | #define BUF_SIZE 4096
|
---|
18 |
|
---|
19 | int main(int argc, char *argv[])
|
---|
20 | {
|
---|
21 | #if 1
|
---|
22 |
|
---|
23 | //sleep(3);
|
---|
24 | int rc = write(fileno(stdout), "test-test", 9);
|
---|
25 | fprintf(stderr, "rc=%d %s\n", rc, strerror(errno));
|
---|
26 | //sleep(3);
|
---|
27 | rc = write(fileno(stdout), "\nend", 4);
|
---|
28 | fprintf(stderr, "rc=%d %s\n", rc, strerror(errno));
|
---|
29 | //sleep(3);
|
---|
30 | return 0;
|
---|
31 |
|
---|
32 | #else
|
---|
33 |
|
---|
34 | int rc;
|
---|
35 |
|
---|
36 | setmode(fileno(stdout), O_BINARY);
|
---|
37 |
|
---|
38 | const char *fname = "D:\\Users\\dmik\\fingerabdruck.mpg";
|
---|
39 |
|
---|
40 | int fd = open(fname, O_RDONLY | O_BINARY);
|
---|
41 | if (fd == -1)
|
---|
42 | return bail("open");
|
---|
43 |
|
---|
44 | timeval timeStart;
|
---|
45 | gettimeofday(&timeStart, 0);
|
---|
46 |
|
---|
47 | int size = 0;
|
---|
48 | char buf[BUF_SIZE];
|
---|
49 | do {
|
---|
50 | rc = read(fd, buf, sizeof(buf));
|
---|
51 | if (rc == -1) {
|
---|
52 | bail("read");
|
---|
53 | break;
|
---|
54 | }
|
---|
55 | if (rc == 0)
|
---|
56 | break;
|
---|
57 | // fprintf(stderr, ".");
|
---|
58 | size += rc;
|
---|
59 | rc = write(fileno(stdout), buf, rc);
|
---|
60 | if (rc == -1) {
|
---|
61 | bail("read");
|
---|
62 | break;
|
---|
63 | }
|
---|
64 | } while (true);
|
---|
65 |
|
---|
66 | timeval timeEnd;
|
---|
67 | gettimeofday(&timeEnd, 0);
|
---|
68 |
|
---|
69 | close(fd);
|
---|
70 |
|
---|
71 | // fprintf(stderr, "\n");
|
---|
72 |
|
---|
73 | unsigned long long elapsed = timeEnd.tv_sec * 1000ll + timeEnd.tv_usec / 1000ll;
|
---|
74 | elapsed -= (timeStart.tv_sec * 1000ll + timeStart.tv_usec / 1000ll);
|
---|
75 |
|
---|
76 | unsigned long long speed = size * 1000ull;
|
---|
77 | speed /= elapsed;
|
---|
78 |
|
---|
79 | if (rc != -1) {
|
---|
80 | fprintf(stderr, "Wrote %s\n", fname);
|
---|
81 | fprintf(stderr, "Size %d bytes\n", size);
|
---|
82 | fprintf(stderr, "Time %llu ms\n", elapsed);
|
---|
83 | fprintf(stderr, "Speed %llu bytes/sec\n", speed);
|
---|
84 | }
|
---|
85 |
|
---|
86 | #endif
|
---|
87 | }
|
---|