[205] | 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 | }
|
---|
| |
---|