| 229 | |
| 230 | |
| 231 | static path_key_entry * path_key( OBJECT * const path, |
| 232 | int const known_to_be_canonic ) |
| 233 | { |
| 234 | path_key_entry * result; |
| 235 | int found; |
| 236 | |
| 237 | if ( !path_key_cache ) |
| 238 | path_key_cache = hashinit( sizeof( path_key_entry ), "path to key" ); |
| 239 | |
| 240 | result = (path_key_entry *)hash_insert( path_key_cache, path, &found ); |
| 241 | if ( !found ) |
| 242 | { |
| 243 | OBJECT * normalized; |
| 244 | int32_t normalized_size; |
| 245 | path_key_entry * nresult; |
| 246 | result->path = path; |
| 247 | { |
| 248 | string buf[ 1 ]; |
| 249 | string_copy( buf, object_str( path ) ); |
| 250 | normalize_path( buf ); |
| 251 | normalized = object_new( buf->value ); |
| 252 | normalized_size = buf->size; |
| 253 | string_free( buf ); |
| 254 | } |
| 255 | nresult = (path_key_entry *)hash_insert( path_key_cache, normalized, |
| 256 | &found ); |
| 257 | if ( !found || nresult == result ) |
| 258 | { |
| 259 | nresult->path = normalized; |
| 260 | if ( known_to_be_canonic ) |
| 261 | { |
| 262 | nresult->key = object_copy( path ); |
| 263 | nresult->exists = 1; |
| 264 | } |
| 265 | else |
| 266 | { |
| 267 | string canonic_path[ 1 ]; |
| 268 | string_new( canonic_path ); |
| 269 | if ( canonicWindowsPath( object_str( normalized ), normalized_size, |
| 270 | canonic_path ) ) |
| 271 | nresult->exists = 1; |
| 272 | else |
| 273 | nresult->exists = 0; |
| 274 | nresult->key = object_new( canonic_path->value ); |
| 275 | string_free( canonic_path ); |
| 276 | } |
| 277 | } |
| 278 | else |
| 279 | object_free( normalized ); |
| 280 | if ( nresult != result ) |
| 281 | { |
| 282 | result->path = object_copy( path ); |
| 283 | result->key = object_copy( nresult->key ); |
| 284 | result->exists = nresult->exists; |
| 285 | } |
| 286 | } |
| 287 | |
| 288 | return result; |
no test coverage detected