| 176 | } |
| 177 | |
| 178 | std::optional<CachingIncludeHandler::IncludedFile> CachingIncludeHandler::AddPrefix( const char* fileName, const char* prefix ) |
| 179 | { |
| 180 | std::lock_guard scope( m_cs ); |
| 181 | |
| 182 | std::string fullPath; |
| 183 | if( PathIsRelative( fileName ) ) |
| 184 | { |
| 185 | if( auto joined = JoinPath( "", fileName ) ) |
| 186 | { |
| 187 | fullPath = *joined; |
| 188 | } |
| 189 | else |
| 190 | { |
| 191 | return std::nullopt; |
| 192 | } |
| 193 | } |
| 194 | else |
| 195 | { |
| 196 | fullPath = fileName; |
| 197 | } |
| 198 | FileFromPath::iterator fileFromPath = m_fileFromPath.find( fullPath ); |
| 199 | if( fileFromPath == m_fileFromPath.end() ) |
| 200 | { |
| 201 | return std::nullopt; |
| 202 | } |
| 203 | |
| 204 | auto& info = fileFromPath->second; |
| 205 | auto length = strlen( prefix ); |
| 206 | auto data = malloc( info.size + length + 2 ); |
| 207 | if( data == NULL ) |
| 208 | { |
| 209 | return std::nullopt; |
| 210 | } |
| 211 | *static_cast<char*>( data ) = '\n'; |
| 212 | memcpy( static_cast<char*>( data ) + 1, prefix, length ); |
| 213 | memcpy( static_cast<char*>( data ) + 1 + length, info.data, info.size + 1 ); |
| 214 | info.size += length; |
| 215 | |
| 216 | m_pathFromFile[data] = m_pathFromFile[info.data - 1]; |
| 217 | m_pathFromFile.erase( info.data - 1 ); |
| 218 | free( (void*)( info.data - 1 ) ); |
| 219 | info.data = static_cast<const char*>( data ) + 1; |
| 220 | |
| 221 | return info; |
| 222 | } |
| 223 | |
| 224 | // -------------------------------------------------------------------------------------- |
| 225 | // Description: |
no test coverage detected