-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest.cpp
More file actions
39 lines (35 loc) · 718 Bytes
/
test.cpp
File metadata and controls
39 lines (35 loc) · 718 Bytes
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
#include <iostream>
#include <fstream>
#include <unistd.h>
#include <fcntl.h>
#include "TarStream.h"
#include "stdio.h"
const int CHUNK = 10000;
using namespace std;
int main(int argc, char *argv[])
{
if (argc < 3)
{
cout << "Usage: " << argv[0] << " basedir file1 [file2] [...]" << endl;
return 1;
}
TarStream tar;
for (int i=2; i < argc; i++)
{
cout << argv[i] << endl;
tar.putFile(argv[i], argv[i]);
}
int f = open("test.tar", O_WRONLY|O_CREAT, 0644);
int i;
char buf[CHUNK];
for (i = 0; i < tar.getSize(); i+=CHUNK)
{
tar.getChunk(buf, CHUNK);
if (tar.getSize() - i >= CHUNK)
write(f, (void*)buf, CHUNK);
else
write(f, (void*)buf, tar.getSize() - i);
}
close(f);
return 0;
}