int main(void) { LinkedList* list = LinkedList_new(); char* elem1 = "cat"; LinkedList_add(list, &elem1); char* elem2 = "rat"; LinkedList_add(list, &elem2); char* elem3 = "dog"; LinkedList_add(list, &elem3); char* elem4 = "sheep"; LinkedList_add(list, &elem4); char* elem5 = "goat"; LinkedList_add(list, &elem5); char* elem6 = "kebab"; LinkedList_add(list, &elem6); char* elem7 = "pig"; LinkedList_add(list, &elem7); char* elem8 = "cow"; LinkedList_add(list, &elem8); char* elem9 = "chicken"; LinkedList_add(list, &elem9); char* elem10 = "duck"; LinkedList_add(list, &elem10); char* elem11 = "fox"; LinkedList_add(list, &elem11); char* elem12 = "rabbit"; LinkedList_add(list, &elem12); char* elem13 = "mouse"; LinkedList_add(list, &elem13); char* elem14 = "hedgehog"; LinkedList_add(list, &elem14); printf("list before: \n"); for (int i = 0; i < LinkedList_size(list); i++) { if (LinkedList_get(list, i) != NULL) { printf("%d: %s \n", i, *(char**)LinkedList_get(list, i)); } } printf("\nremoving element 5, %s\n", *(char**)LinkedList_get(list, 5)); LinkedList_remove(list, 5); printf("\nlist after: \n"); for (int i = 0; i < LinkedList_size(list); i++) { if (LinkedList_get(list, i) != NULL) { printf("%d: %s \n", i, *(char**)LinkedList_get(list, i)); } } LinkedList_destroy(list); free(list); }
END_TEST START_TEST(test_RemovingElementFromListDoesNotFreeItFromMemory) { LinkedList* list = LinkedList_new(); int* elem = malloc(sizeof (int)); *elem = 35; LinkedList_add(list, elem); ck_assert_int_eq(*(int*) LinkedList_get(list, 0), 35); LinkedList_remove(list, 0); ck_assert_int_eq(*elem, 35); }
void LinkedList_Destroy(LinkedList * self) { if (self != NULL) { void * a; int * size = (self->size); int i; for (i = *size; i > 0; i-- ) { a = LinkedList_remove(&self); } free(size); free(self); self = NULL; size = NULL; } }
static void removeClientConnection(IsoServer self, IsoConnection connection) { #if (CONFIG_MAXIMUM_TCP_CLIENT_CONNECTIONS == -1) LinkedList_remove(self->openClientConnections, connection); #else int i; for (i = 0; i < CONFIG_MAXIMUM_TCP_CLIENT_CONNECTIONS; i++) { if (self->openClientConnections[i] == connection) { if (DEBUG_ISO_SERVER) printf("ISO_SERVER: removed connection (%p) index:%i\n", connection, i); self->openClientConnections[i] = NULL; break; } } #endif }
END_TEST START_TEST(test_RemovingElementFromListWorks) { LinkedList* list = LinkedList_new(); int elem1 = 1337; LinkedList_add(list, &elem1); char* elem2 = "theeta"; LinkedList_add(list, &elem2); int elem3 = 74; LinkedList_add(list, &elem3); ck_assert_int_eq(*(int*) LinkedList_get(list, 0), 1337); ck_assert_str_eq(*(char**) LinkedList_get(list, 1), "theeta"); ck_assert_int_eq(*(int*) LinkedList_get(list, 2), 74); LinkedList_remove(list, 1); ck_assert_int_eq(*(int*) LinkedList_get(list, 0), 1337); ck_assert_int_eq(*(int*) LinkedList_get(list, 1), 74); ck_assert_int_eq(LinkedList_size(list), 2); }
static void removeClientConnection(IsoServer self, IsoConnection connection) { #if (CONFIG_MAXIMUM_TCP_CLIENT_CONNECTIONS == -1) #if (CONFIG_MMS_SINGLE_THREADED == 0) #if (CONFIG_MMS_THREADLESS_STACK != 1) lockClientConnections(self); #endif LinkedList_remove(self->openClientConnections, connection); #if (CONFIG_MMS_THREADLESS_STACK != 1) unlockClientConnections(self); #endif #endif /* (CONFIG_MMS_SINGLE_THREADED == 0) */ #else int i; for (i = 0; i < CONFIG_MAXIMUM_TCP_CLIENT_CONNECTIONS; i++) { if (self->openClientConnections[i] == connection) { if (DEBUG_ISO_SERVER) printf("ISO_SERVER: removed connection (%p) index:%i\n", connection, i); self->openClientConnections[i] = NULL; break; } } #endif /* (CONFIG_MAXIMUM_TCP_CLIENT_CONNECTIONS == -1) */ }
void private_IedConnection_removeControlClient(IedConnection self, ControlObjectClient control) { LinkedList_remove(self->clientControls, control); }
void private_IedServer_removeClientConnection(IedServer self, ClientConnection clientConnection) { LinkedList_remove(self->clientConnections, clientConnection); }
PathName* PathName_new(String* string, BOOL isFile) { PathName* newPn; int pos; String* pathWoRoot; String* separators; String* fileName; // Validate the path. if (!_validPath(string)) return NULL; separators = String_new("\\/"); newPn = (PathName*)malloc(sizeof(PathName)); // Check the root. pos = String_findChar(string, ':'); if (1 == pos) { // This is a Windows absolute path. newPn->root = String_newSubString(string, 0, 3); pos = 3; } else if (String_findChar(string, '/') == 0 || String_findChar(string, '\\') == 0) { // This is a Unix absolute path. newPn->root = String_new("/"); pos = 1; } else { // This is a relative path. newPn->root = NULL; pos = 0; } // Parse the rest of the path. pathWoRoot = String_newSubString(string, pos, -1); newPn->path = String_splitMultiSep(pathWoRoot, separators); String_delete(pathWoRoot); if (isFile) { // Get the file name. if (String_isEmpty((String*)newPn->path->last->item)) { // This was supposed to be a file, but the path ended in '/' or '\' String_delete(separators); PathName_delete(newPn); return NULL; } fileName = (String*)newPn->path->last->item; LinkedList_remove(newPn->path, newPn->path->last); // Find the extension, if there is one. pos = String_findCharReverse(fileName, '.'); if (-1 == pos) { // No extension (no '.' in file name). newPn->bareName = fileName; newPn->extension = NULL; } else { // At least one '.' in file name. Separate out extension. newPn->bareName = String_newSubString(fileName, 0, pos); newPn->extension = String_newSubString(fileName, pos + 1, -1); String_delete(fileName); } } else { // No file name. newPn->bareName = NULL; newPn->extension = NULL; if (String_isEmpty((String*)newPn->path->last->item)) { // The string ended in '/' or '\'. Last path element is empty, so remove it. String_delete((String*)newPn->path->last->item); LinkedList_remove(newPn->path, newPn->path->last); } } String_delete(separators); smug_assert(_invariant(newPn)); return newPn; }
void GooseReceiver_removeSubscriber(GooseReceiver self, GooseSubscriber subscriber) { LinkedList_remove(self->subscriberList, (void*) subscriber); }