* Duplicate a string. */
| 151 | * Duplicate a string. |
| 152 | */ |
| 153 | static const char *dupString(const char *str) |
| 154 | { |
| 155 | static std::set<const char *, CStrCmp> cache; |
| 156 | auto i = cache.find(str); |
| 157 | if (i != cache.end()) |
| 158 | return *i; |
| 159 | |
| 160 | char *new_str = strdup(str); |
| 161 | if (new_str == nullptr) |
| 162 | error("failed to duplicate string \"%s\": %s", str, strerror(ENOMEM)); |
| 163 | cache.insert(new_str); |
| 164 | return new_str; |
| 165 | } |
| 166 | |
| 167 | /* |
| 168 | * Duplicate bytes. |
no test coverage detected