MCPcopy Create free account
hub / github.com/cesanta/mongoose / entry_remove

Function entry_remove

tutorials/device-dashboard/array/dashboard.c:36–49  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

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
36static 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

Callers 1

arr_fnFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected