* @brief Inserts a string into another string at a given index * * @param Str the original string (will be reallocated) * @param InputIdx the index at which to insert * @param Buf the string to insert * @return char * the new string, or the original on allocation failure */
| 70 | * @return char * the new string, or the original on allocation failure |
| 71 | */ |
| 72 | char * |
| 73 | InsertStrNew(char * Str, int InputIdx, const char * Buf) |
| 74 | { |
| 75 | SIZE_T LenStr = strlen(Str); |
| 76 | SIZE_T LenBuf = strlen(Buf); |
| 77 | |
| 78 | if (InputIdx < 0 || (SIZE_T)InputIdx > LenStr) |
| 79 | return Str; |
| 80 | |
| 81 | char * NewStr = (char *)realloc(Str, LenStr + LenBuf + 1); |
| 82 | if (!NewStr) |
| 83 | return Str; |
| 84 | |
| 85 | memmove(NewStr + InputIdx + LenBuf, |
| 86 | NewStr + InputIdx, |
| 87 | LenStr - InputIdx + 1); |
| 88 | |
| 89 | memcpy(NewStr + InputIdx, Buf, LenBuf); |
| 90 | |
| 91 | return NewStr; |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * @brief Checks whether a file path is absolute |