File: mktestdata.c

package info (click to toggle)
gatling 0.13-6
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 1,196 kB
  • ctags: 1,115
  • sloc: ansic: 23,805; makefile: 143; sh: 71; perl: 30
file content (98 lines) | stat: -rw-r--r-- 2,377 bytes parent folder | download | duplicates (4)
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include "buffer.h"
#include "io.h"
#include "fmt.h"
#include "scan.h"
#include <sys/types.h>
#include <sys/mman.h>
#include <unistd.h>
#include <signal.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <stdlib.h>
#include <sys/stat.h>

#ifdef __i386__
#define rdtscl(low) \
     __asm__ __volatile__ ("rdtsc" : "=A" (low))
#endif

static void carp(const char* routine) {
  buffer_puts(buffer_2,routine);
  buffer_puts(buffer_2,": ");
  buffer_puterror(buffer_2);
  buffer_putnlflush(buffer_2);
}

static void panic(const char* routine) {
  carp(routine);
  exit(111);
}

int main(int argc,char* argv[]) {
  unsigned long count=10000;

  for (;;) {
    int i;
    int c=getopt(argc,argv,"hc:");
    if (c==-1) break;
    switch (c) {
    case 'c':
      i=scan_ulong(optarg,&count);
      if (i==0 || optarg[i]) {
	buffer_puts(buffer_2,"mktestdata: warning: could not parse count: ");
	buffer_puts(buffer_2,optarg+i+1);
	buffer_putsflush(buffer_2,"\n");
      }
      break;
    case 'h':
      buffer_putsflush(buffer_2,
		  "usage: mktestdata [-h] [-c count]\n"
		  "\n"
		  "\t-h\tprint this help\n"
		  "\t-c n\tcreate n small files (default: 10000)\n");
      return 0;
    }
  }

  {
    unsigned long i,j;
    char buf[4096];
    char filename[256];
    if (mkdir("data",0700)==-1) panic("mkdir");
    for (i=0; i<(count+99)/100; ++i) {
      j=fmt_str(filename,"data/");
      j+=fmt_ulong(filename+j,i);
      filename[j]=0;
      if (mkdir(filename,0700)==-1) panic("mkdir");
    }
    for (i=0; i<count; ++i) {
      int64 fd;
      j=fmt_str(filename,"data/");
      j+=fmt_ulong(filename+j,i/100);
      j+=fmt_str(filename+j,"/");
      j+=fmt_ulong(filename+j,i);
      j+=fmt_str(filename+j,".html");
      filename[j]=0;
      if (!io_createfile(&fd,filename))
	panic("creat");
      j=fmt_str(buf,"<title>Page ");
      j+=fmt_ulong(buf+j,i);
      j+=fmt_str(buf+j,"</title><h1>Page ");
      j+=fmt_ulong(buf+j,i);
      j+=fmt_str(buf+j,"</h1>\nThis is a nice, small and clean web page.<p>\n");
      if (i==count)
	j+=fmt_str(buf+j,"This is the last page.\n");
      else {
	j+=fmt_str(buf+j,"And <a href=../");
	j+=fmt_ulong(buf+j,(i+1)/100);
	j+=fmt_str(buf+j,"/");
	j+=fmt_ulong(buf+j,i+1);
	j+=fmt_str(buf+j,"html>here</a> is the next one.");
      }
      write(fd,buf,j);
      close(fd);
    }
  }
  buffer_flush(buffer_1);
  return 0;
}