Remove the entry at the given index, shifting the tail down and shrinking s_arr by one slot. False if the index is out of range
| 34 | // Remove the entry at the given index, shifting the tail down and shrinking |
| 35 | // s_arr by one slot. False if the index is out of range |
| 36 | static bool entry_remove(int index) { |
| 37 | if (index < 0 || (size_t) index >= s_count) return false; |
| 38 | memmove(&s_arr[index], &s_arr[index + 1], |
| 39 | (s_count - (size_t) index - 1) * sizeof(*s_arr)); |
| 40 | s_count--; |
| 41 | if (s_count == 0) { |
| 42 | free(s_arr); |
| 43 | s_arr = NULL; |
| 44 | } else { |
| 45 | struct entry *arr = (struct entry *) realloc(s_arr, s_count * sizeof(*arr)); |
| 46 | if (arr != NULL) s_arr = arr; |
| 47 | } |
| 48 | return true; |
| 49 | } |
| 50 | |
| 51 | // Read, write, delete or append an array element. The framework sets s_index |
| 52 | // before the call: a negative value asks for the total count, an |