-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhtml_creator.c
More file actions
106 lines (73 loc) · 1.72 KB
/
html_creator.c
File metadata and controls
106 lines (73 loc) · 1.72 KB
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
99
100
101
102
103
104
105
106
/*
compile: gcc -Wall html_creator.c -o html_creator -lm
duplicates file, but doubling the next ones size
usage: experimenting with a multi-server application over multi-port hop
to test efficiency of a XDP filter, vs tradition nftables and iptable filters
ls -al; check whether each file is double the size of the previous file
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/types.h>
#include <unistd.h>
#include <math.h>
#define BUFFSIZE 4096
#define MAXLENGTH 10
/*create 100 files of doubling size*/
#define NUMFILES 20
void itoa(int n, char s[]);
void reverse(char s[]);
int main(int argc, char* argv[]){
int i = 1;
if (argc != 2) {
fprintf (stderr, "usage: ./html_creator <file_to_dup>\n");
exit(1);
}
int fd_read, fd_write;
for (int i = 1; i <= NUMFILES; ++i) {
char s[MAXLENGTH];
char *tmpname = malloc (strlen(argv[1] + 7));
strcpy (tmpname,argv[1]);
itoa (i,s);
strcat (tmpname, s);
strcat (tmpname, ".html");
fd_write = open (tmpname, O_RDWR | O_CREAT, 0666);
for (int j = 0; j < pow(2,i); ++j) {
fd_read = open (argv[1], O_RDONLY, S_IRWXU);
int n;
char buf[BUFFSIZE];
while (n = read(fd_read, buf, BUFFSIZE)) {
write (fd_write, buf, n);
}
close(fd_read);
}
free (tmpname);
close (fd_write);
}
return 0;
}
void itoa(int n, char s[]){
int i, sign;
sign = n;
i = 0;
do {
s[i++] = abs(n%10) + '0';
} while((n/=10));
if(sign < 0)
s[i++] = '-';
s[i] = '\0';
reverse(s);
}
void reverse(char s[])
{
int length = strlen(s) ;
int c, i, j;
for (i = 0, j = length - 1; i < j; i++, j--)
{
c = s[i];
s[i] = s[j];
s[j] = c;
}
}