OpenCores
URL https://opencores.org/ocsvn/ao486/ao486/trunk

Subversion Repositories ao486

[/] [ao486/] [trunk/] [sim/] [logSplitter/] [main.cpp] - Blame information for rev 3

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 alfik
#include <cstdio>
2
 
3
#include <sys/types.h>
4
#include <sys/stat.h>
5
#include <fcntl.h>
6
#include <unistd.h>
7
 
8
int main() {
9
    int index=0;
10
    char buf[65536];
11
    char name[256];
12
 
13
    int flags = fcntl(0, F_GETFL);
14
    fcntl(0, F_SETFL, flags | O_NONBLOCK);
15
 
16
    while(true) {
17
        snprintf(name, 256, "out_%03d.txt", index);
18
        FILE *fp = fopen(name, "wb");
19
 
20
        int count = 0;
21
        while(true) {
22
            int rd = fread(buf, 1, sizeof(buf), stdin);
23
            if(rd > 0) {
24
                //printf("%d\n", rd);
25
                fwrite(buf, 1, rd, fp);
26
                fflush(fp);
27
                count += rd;
28
            }
29
            else {
30
                fflush(fp);
31
                usleep(10);
32
                //fclose(fp);
33
            }
34
            if(count > 10000000) break;
35
        }
36
        fclose(fp);
37
        index++;
38
        if(index == 1000) index = 0;
39
    }
40
 
41
    return 0;
42
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.