| 71 | |
| 72 | |
| 73 | static 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 |
no test coverage detected