aboutsummaryrefslogtreecommitdiffstats
path: root/test/dropcount.c
blob: 1345b73339f80ec05b3edee047f8016ddf497a7b (plain) (blame)
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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main( int argc, char* argv[] )
{
    FILE *fd;
    char buffer[ 256 ];
    int msg_index = 1, drop_count = 0;

    if( argc < 2 )
    {
        puts( "required filename" );
        return 1;
    }

    fd = fopen( argv[1], "r" );
    if( !fd )
    {
        perror( "fopen" );
        return 1;
    }
    while( fgets( buffer, sizeof(buffer), fd ) )
    {
        char *p;
        int i;

        p = buffer + strlen( buffer );
        while( *p != ' ' ) p--;
        i = strtoul( p, NULL, 10 );
        while( msg_index < i )
        {
            msg_index++;
            drop_count++;
        }
        msg_index++;
    }
    printf( "dropped %d message(s)\n", drop_count );
    fclose( fd );
    return 0;
}