Push
| 105 | |
| 106 | // Push |
| 107 | cmd_error* cmd_error_push(cmd_error* l, cmd_error* e, int max_size) { |
| 108 | if (max_size < 1) { |
| 109 | cmd_error_destroy_rec(l); |
| 110 | cmd_error_destroy(e); |
| 111 | return NULL; |
| 112 | } |
| 113 | |
| 114 | if (!l) return e; |
| 115 | |
| 116 | cmd_error* h = l; |
| 117 | int i = 1; |
| 118 | |
| 119 | while (h->next) { |
| 120 | h = h->next; |
| 121 | ++i; |
| 122 | } |
| 123 | |
| 124 | h->next = e; |
| 125 | |
| 126 | // Remove first element if list is too big |
| 127 | if (i > max_size) { |
| 128 | cmd_error* ptr = l; |
| 129 | l = l->next; |
| 130 | cmd_error_destroy(ptr); |
| 131 | } |
| 132 | |
| 133 | return l; |
| 134 | } |
no test coverage detected