| OLD | NEW |
| 1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/data_pack.h" | 5 #include "base/data_pack.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 | 8 |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/string_piece.h" | 11 #include "base/string_piece.h" |
| 12 | 12 |
| 13 // For details of the file layout, see | 13 // For details of the file layout, see |
| 14 // http://dev.chromium.org/developers/design-documents/linuxresourcesandlocalize
dstrings | 14 // http://dev.chromium.org/developers/design-documents/linuxresourcesandlocalize
dstrings |
| 15 | 15 |
| 16 namespace { | 16 namespace { |
| 17 | 17 |
| 18 // A word is four bytes. | 18 // A word is four bytes. |
| 19 static const size_t kWord = 4; | 19 static const size_t kWord = 4; |
| 20 | 20 |
| 21 static const uint32 kFileFormatVersion = 1; | 21 static const uint32 kFileFormatVersion = 1; |
| 22 // Length of file header: version and entry count. | 22 // Length of file header: version and entry count. |
| 23 static const size_t kHeaderLength = 2 * sizeof(uint32); | 23 static const size_t kHeaderLength = 2 * sizeof(uint32); |
| 24 | 24 |
| 25 #pragma pack(push,1) | |
| 26 struct DataPackEntry { | 25 struct DataPackEntry { |
| 27 uint32 resource_id; | 26 uint32 resource_id; |
| 28 uint32 file_offset; | 27 uint32 file_offset; |
| 29 uint32 length; | 28 uint32 length; |
| 30 | 29 |
| 31 static int CompareById(const void* void_key, const void* void_entry) { | 30 static int CompareById(const void* void_key, const void* void_entry) { |
| 32 uint32 key = *reinterpret_cast<const uint32*>(void_key); | 31 uint32 key = *reinterpret_cast<const uint32*>(void_key); |
| 33 const DataPackEntry* entry = | 32 const DataPackEntry* entry = |
| 34 reinterpret_cast<const DataPackEntry*>(void_entry); | 33 reinterpret_cast<const DataPackEntry*>(void_entry); |
| 35 if (key < entry->resource_id) { | 34 if (key < entry->resource_id) { |
| 36 return -1; | 35 return -1; |
| 37 } else if (key > entry->resource_id) { | 36 } else if (key > entry->resource_id) { |
| 38 return 1; | 37 return 1; |
| 39 } else { | 38 } else { |
| 40 return 0; | 39 return 0; |
| 41 } | 40 } |
| 42 } | 41 } |
| 43 }; | 42 }; |
| 44 #pragma pack(pop) | |
| 45 | 43 |
| 46 COMPILE_ASSERT(sizeof(DataPackEntry) == 12, size_of_header_must_be_twelve); | 44 COMPILE_ASSERT(sizeof(DataPackEntry) == 12, size_of_header_must_be_twelve); |
| 47 | 45 |
| 48 } // anonymous namespace | 46 } // anonymous namespace |
| 49 | 47 |
| 50 namespace base { | 48 namespace base { |
| 51 | 49 |
| 52 // In .cc for MemoryMappedFile dtor. | 50 // In .cc for MemoryMappedFile dtor. |
| 53 DataPack::DataPack() : resource_count_(0) { | 51 DataPack::DataPack() : resource_count_(0) { |
| 54 } | 52 } |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 return false; | 185 return false; |
| 188 } | 186 } |
| 189 } | 187 } |
| 190 | 188 |
| 191 file_util::CloseFile(file); | 189 file_util::CloseFile(file); |
| 192 | 190 |
| 193 return true; | 191 return true; |
| 194 } | 192 } |
| 195 | 193 |
| 196 } // namespace base | 194 } // namespace base |
| OLD | NEW |