| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2009, Google Inc. | 2 * Copyright 2009, Google Inc. |
| 3 * All rights reserved. | 3 * All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
| 7 * met: | 7 * met: |
| 8 * | 8 * |
| 9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 // File mode | 100 // File mode |
| 101 ::snprintf(p + kFileModeOffset, 8, "%07o", is_directory ? 0755 : 0644); | 101 ::snprintf(p + kFileModeOffset, 8, "%07o", is_directory ? 0755 : 0644); |
| 102 | 102 |
| 103 // UserID | 103 // UserID |
| 104 ::snprintf(p + kUserIDOffset, 8, "%07o", 0765); | 104 ::snprintf(p + kUserIDOffset, 8, "%07o", 0765); |
| 105 | 105 |
| 106 // GroupID | 106 // GroupID |
| 107 ::snprintf(p + kGroupIDOffset, 8, "%07o", 0204); | 107 ::snprintf(p + kGroupIDOffset, 8, "%07o", 0204); |
| 108 | 108 |
| 109 // File size | 109 // File size |
| 110 ::snprintf(p + kFileSizeOffset, 12, "%011o", file_size); | 110 ::snprintf(p + kFileSizeOffset, 12, "%011o", |
| 111 static_cast<unsigned int>(file_size)); |
| 111 | 112 |
| 112 // Modification time | 113 // Modification time |
| 113 // TODO: write the correct current time here... | 114 // TODO: write the correct current time here... |
| 114 ::snprintf(p + kModifyTimeOffset, 12, "%07o", 011131753141); | 115 ::snprintf(p + kModifyTimeOffset, 12, "%07o", 011131753141); |
| 115 | 116 |
| 116 // Initialize Header checksum so check sum can be computed | 117 // Initialize Header checksum so check sum can be computed |
| 117 // by ComputeCheckSum() which will fill in the value here | 118 // by ComputeCheckSum() which will fill in the value here |
| 118 ::memset(p + kHeaderCheckSumOffset, 32, 8); | 119 ::memset(p + kHeaderCheckSumOffset, 32, 8); |
| 119 | 120 |
| 120 // We only support ordinary files and directories, which is fine | 121 // We only support ordinary files and directories, which is fine |
| (...skipping 20 matching lines...) Expand all Loading... |
| 141 } | 142 } |
| 142 } | 143 } |
| 143 | 144 |
| 144 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 145 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 145 void TarGenerator::ComputeCheckSum(uint8 *header) { | 146 void TarGenerator::ComputeCheckSum(uint8 *header) { |
| 146 unsigned int checksum = 0; | 147 unsigned int checksum = 0; |
| 147 for (int i = 0; i < TAR_HEADER_SIZE; ++i) { | 148 for (int i = 0; i < TAR_HEADER_SIZE; ++i) { |
| 148 checksum += header[i]; | 149 checksum += header[i]; |
| 149 } | 150 } |
| 150 snprintf(reinterpret_cast<char*>(header + kHeaderCheckSumOffset), | 151 snprintf(reinterpret_cast<char*>(header + kHeaderCheckSumOffset), |
| 151 8, "%06o\0\0", checksum); | 152 8, "%06o%c%c", checksum, 0, 0); |
| 152 } | 153 } |
| 153 | 154 |
| 154 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 155 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 155 int TarGenerator::AddFileBytes(MemoryReadStream *stream, size_t n) { | 156 int TarGenerator::AddFileBytes(MemoryReadStream *stream, size_t n) { |
| 156 if (callback_client_) { | 157 if (callback_client_) { |
| 157 FlushDataBuffer(false); // flush any old data sitting around | 158 FlushDataBuffer(false); // flush any old data sitting around |
| 158 | 159 |
| 159 // we'll directly write as much of the data as we can, writing full blocks | 160 // we'll directly write as much of the data as we can, writing full blocks |
| 160 int nblocks = n / TAR_BLOCK_SIZE; | 161 int nblocks = n / TAR_BLOCK_SIZE; |
| 161 size_t direct_bytes_to_write = nblocks * TAR_BLOCK_SIZE; | 162 size_t direct_bytes_to_write = nblocks * TAR_BLOCK_SIZE; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 190 data_buffer_stream_.Seek(0); | 191 data_buffer_stream_.Seek(0); |
| 191 } | 192 } |
| 192 } | 193 } |
| 193 | 194 |
| 194 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 195 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 195 void TarGenerator::Finalize() { | 196 void TarGenerator::Finalize() { |
| 196 FlushDataBuffer(true); | 197 FlushDataBuffer(true); |
| 197 } | 198 } |
| 198 | 199 |
| 199 } // namespace o3d | 200 } // namespace o3d |
| OLD | NEW |