LCOV - code coverage report
Current view: top level - tools - mk-tdata.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 20 20 100.0 %
Date: 2016-09-12 13:01:59 Functions: 1 1 100.0 %

          Line data    Source code
       1             : /* mk-tdata.c -  Create some simple random testdata
       2             :  * Copyright (C) 1998, 1999, 2000, 2001, 2006 Free Software Foundation, Inc.
       3             :  *
       4             :  * This file is free software; as a special exception the author gives
       5             :  * unlimited permission to copy and/or distribute it, with or without
       6             :  * modifications, as long as this notice is preserved.
       7             :  *
       8             :  * This program is distributed in the hope that it will be useful, but
       9             :  * WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
      10             :  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
      11             :  */
      12             : 
      13             : #ifdef HAVE_CONFIG_H
      14             : #include <config.h>
      15             : #endif
      16             : #include <stdio.h>
      17             : #include <stdlib.h>
      18             : #include <string.h>
      19             : #include <unistd.h>
      20             : #include <fcntl.h>
      21             : 
      22             : 
      23             : #ifndef RAND_MAX   /* for SunOS */
      24             : #define RAND_MAX 32767
      25             : #endif
      26             : 
      27             : int
      28           7 : main(int argc, char **argv)
      29             : {
      30           7 :   int i, c = 0;
      31           7 :   int limit =0;
      32           7 :   int char_mode = 0;
      33             : 
      34             : #if HAVE_W32_SYSTEM
      35             :   if (setmode (fileno (stdout), O_BINARY) == -1)
      36             :     perror ("setmode");
      37             : #endif
      38             : 
      39           7 :   if (argc)
      40             :     {
      41           7 :       argc--;
      42           7 :       argv++;
      43             :     }
      44             : 
      45             :   /* Check for option --char N */
      46           7 :   if (argc > 1 && !strcmp (argv[0], "--char"))
      47             :     {
      48           2 :       char_mode = 1;
      49           2 :       c = strtol (argv[1], NULL, 0);
      50           2 :       argc -= 2;
      51           2 :       argv += 2;
      52             :     }
      53             : 
      54           7 :   limit = argc ? atoi(argv[0]) : 0;
      55             : 
      56           7 :   srand(getpid());
      57             : 
      58      122235 :   for (i=0; !limit || i < limit; i++ )
      59             :     {
      60      122228 :       if (char_mode)
      61             :         {
      62         128 :           putchar (c);
      63             :         }
      64             :       else
      65             :         {
      66             : #ifdef HAVE_RAND
      67      122100 :           c = ((unsigned)(1 + (int) (256.0*rand()/(RAND_MAX+1.0)))-1);
      68             : #else
      69             :           c = ((unsigned)(1 + (int) (256.0*random()/(RAND_MAX+1.0)))-1);
      70             : #endif
      71      122100 :           putchar (c);
      72             :         }
      73             :     }
      74           7 :   return 0;
      75             : }

Generated by: LCOV version 1.11