| 244 | #endif |
| 245 | |
| 246 | static void makeCleanPathInPlace( char* path ) |
| 247 | { |
| 248 | U32 pathDepth = 0; |
| 249 | char* fromPtr = path; |
| 250 | char* toPtr = path; |
| 251 | |
| 252 | bool isAbsolute = false; |
| 253 | if( *fromPtr == '/' ) |
| 254 | { |
| 255 | fromPtr ++; |
| 256 | toPtr ++; |
| 257 | isAbsolute = true; |
| 258 | } |
| 259 | else if( fromPtr[ 0 ] != '\0' && fromPtr[ 1 ] == ':' ) |
| 260 | { |
| 261 | toPtr += 3; |
| 262 | fromPtr += 3; |
| 263 | isAbsolute = true; |
| 264 | } |
| 265 | |
| 266 | while( *fromPtr ) |
| 267 | { |
| 268 | if( fromPtr[ 0 ] == '.' && fromPtr[ 1 ] == '.' && fromPtr[ 2 ] == '/' ) |
| 269 | { |
| 270 | // Back up from '../' |
| 271 | |
| 272 | if( pathDepth > 0 ) |
| 273 | { |
| 274 | pathDepth --; |
| 275 | toPtr -= 2; |
| 276 | while( toPtr >= path && *toPtr != '/' ) |
| 277 | toPtr --; |
| 278 | toPtr ++; |
| 279 | } |
| 280 | else if( !isAbsolute ) |
| 281 | { |
| 282 | dMemcpy( toPtr, fromPtr, 3 ); |
| 283 | toPtr += 3; |
| 284 | } |
| 285 | |
| 286 | fromPtr += 3; |
| 287 | } |
| 288 | else if( fromPtr[ 0 ] == '.' && fromPtr[ 1 ] == '/' ) |
| 289 | { |
| 290 | // Ignore. |
| 291 | fromPtr += 2; |
| 292 | } |
| 293 | else |
| 294 | { |
| 295 | if( fromPtr[ 0 ] == '/' ) |
| 296 | pathDepth ++; |
| 297 | |
| 298 | *toPtr ++ = *fromPtr ++; |
| 299 | } |
| 300 | } |
| 301 | |
| 302 | *toPtr = '\0'; |
| 303 | } |
no test coverage detected