MCPcopy Create free account
hub / github.com/bloomberg/comdb2 / serialise_string

Function serialise_string

tools/comdb2ar/serialise.cpp:73–116  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

71
72
73static void serialise_string(const std::string& filename,
74 const std::string& data)
75{
76 struct stat st;
77
78 st.st_mode = 0664;
79 st.st_uid = getuid();
80 st.st_gid = getgid();
81 st.st_mtime = time(NULL);
82 st.st_size = data.length();
83
84 // Write the header
85 TarHeader head;
86 head.set_filename(filename);
87 head.set_attrs(st);
88 head.set_checksum();
89
90 if(writeall(1, head.get().c, sizeof(tar_block_header))
91 != sizeof(tar_block_header)) {
92 std::ostringstream ss;
93 ss << "error writing tar block header: " << std::strerror(errno);
94 throw SerialiseError(filename, ss.str());
95 }
96
97 // Write the character data
98 if(writeall(1, data.data(), data.length()) != data.length()) {
99 std::ostringstream ss;
100 ss << "error writing text data: " << std::strerror(errno);
101 throw SerialiseError(filename, ss.str());
102 }
103
104 // Write out padding
105 off_t bytesleft = st.st_size & (512 - 1);
106 bytesleft = 512 - bytesleft;
107 if(bytesleft > 0 && bytesleft < 512) {
108 writepadding(bytesleft);
109 }
110
111 std::clog << "a " << filename << " size=" << st.st_size;
112 if(head.used_gnu()) {
113 std::clog << " (encoded using gnu extension)";
114 }
115 std::clog << std::endl;
116}
117
118
119/* dlmalloc clashes with malloc definitions, so can't include malloc.h

Callers 2

serialise_databaseFunction · 0.85
create_partialsFunction · 0.85

Calls 8

writeallFunction · 0.85
SerialiseErrorClass · 0.85
writepaddingFunction · 0.85
set_attrsMethod · 0.80
set_checksumMethod · 0.80
used_gnuMethod · 0.80
set_filenameMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected