this repo has no description
1// CFLAGS: -O3
2#include <fstream>
3#include <iostream>
4#include <unistd.h>
5#include <cstring>
6#include <cstdio>
7#include <ext/stdio_filebuf.h>
8
9void printFile(const char* path);
10void test1();
11void test2();
12void test3();
13
14char text[8001] = "";
15const char* file = "/tmp/__test123";
16
17int main()
18{
19 //__gnu_cxx::stdio_filebuf<char> out;
20 const char* file = "/tmp/__test123";
21
22 for (int i = 0; i < 800; i++)
23 memcpy(text+i*10, "1234567890", 11);
24
25 test1();
26 test2();
27 test3();
28
29 return 0;
30}
31
32void test1()
33{
34 __gnu_cxx::stdio_filebuf<char> out(fopen(file, "w+b"), std::ios_base::out|std::ios_base::binary);
35 out.sputn(text, strlen(text));
36 out.close();
37
38 printFile(file);
39}
40
41void test2()
42{
43 std::filebuf out2;
44 size_t len;
45 out2.open(file, std::ios_base::binary|std::ios_base::in|std::ios_base::out|std::ios_base::trunc);
46 len = strlen(text);
47 printf("Len %d\n", len);
48 out2.sputn(text, len);
49 out2.close();
50
51 printFile(file);
52}
53
54void test3()
55{
56 std::ofstream of(file, std::ios_base::binary|std::ios_base::in|std::ios_base::out|std::ios_base::trunc);
57 of.write(text, strlen(text));
58 of.close();
59
60 printFile(file);
61}
62
63void printFile(const char* path)
64{
65 std::ifstream in;
66 char buf[8001];
67
68 in.open(path);
69 in.getline(buf, sizeof(buf));
70 in.close();
71
72 std::cout << buf << std::endl;
73 unlink(path);
74}
75