| 902 | #endif |
| 903 | |
| 904 | char* NormalizePath( const char* path ) |
| 905 | { |
| 906 | if( path[0] != '/' ) return nullptr; |
| 907 | |
| 908 | const char* ptr = path; |
| 909 | const char* end = path + strlen( path ); |
| 910 | |
| 911 | char* res = (char*)tracy_malloc( end - ptr + 1 ); |
| 912 | size_t rsz = 0; |
| 913 | |
| 914 | while( ptr < end ) |
| 915 | { |
| 916 | const char* next = ptr; |
| 917 | while( next < end && *next != '/' ) next++; |
| 918 | size_t lsz = next - ptr; |
| 919 | switch( lsz ) |
| 920 | { |
| 921 | case 2: |
| 922 | if( memcmp( ptr, "..", 2 ) == 0 ) |
| 923 | { |
| 924 | const char* back = res + rsz - 1; |
| 925 | while( back > res && *back != '/' ) back--; |
| 926 | rsz = back - res; |
| 927 | ptr = next + 1; |
| 928 | continue; |
| 929 | } |
| 930 | break; |
| 931 | case 1: |
| 932 | if( *ptr == '.' ) |
| 933 | { |
| 934 | ptr = next + 1; |
| 935 | continue; |
| 936 | } |
| 937 | break; |
| 938 | case 0: |
| 939 | ptr = next + 1; |
| 940 | continue; |
| 941 | } |
| 942 | if( rsz != 1 ) res[rsz++] = '/'; |
| 943 | memcpy( res+rsz, ptr, lsz ); |
| 944 | rsz += lsz; |
| 945 | ptr = next + 1; |
| 946 | } |
| 947 | |
| 948 | if( rsz == 0 ) |
| 949 | { |
| 950 | memcpy( res, "/", 2 ); |
| 951 | } |
| 952 | else |
| 953 | { |
| 954 | res[rsz] = '\0'; |
| 955 | } |
| 956 | return res; |
| 957 | } |
| 958 | |
| 959 | void InitCallstackCritical() |
| 960 | { |