Fledasty/Src/Core/Queue.c

66 lines
No EOL
2 KiB
C

/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* -----------------------------------------------------------------------------
* File: Main.c
* Description:
* Executes all tests.
*
* Author: Mineplay
* -----------------------------------------------------------------------------
*/
#include "../../Include/Fledasty/Core/Queue.h"
#include <Hallocy/Core/Allocator.h>
#include <Hallocy/Utils/Error.h>
FledastyError fledasty_queue_initialize(FledastyQueue *new_queue) {
if (new_queue == NULL) {
return FLEDASTY_ERROR_INVALID_POINTER;
}
new_queue->size = 0;
new_queue->start = NULL;
new_queue->end = NULL;
return FLEDASTY_ERROR_NONE;
}
FledastyError fledasty_queue_destroy(FledastyQueue *current_queue) {
if (current_queue == NULL) {
return FLEDASTY_ERROR_INVALID_POINTER;
}
FledastyQueueNode *previousNode = NULL;
FledastyQueueNode *current_node = current_queue->start;
while (current_node != NULL) {
previousNode = current_node;
current_node = current_node->next;
HallocyError error = hallocy_free(previousNode->value);
if (error != HALLOCY_ERROR_NONE) {
return FLEDASTY_ERROR_ALLOCATION;
}
error = hallocy_free(previousNode);
if (error != HALLOCY_ERROR_NONE) {
return FLEDASTY_ERROR_ALLOCATION;
}
}
current_queue->size = 0;
current_queue->start = NULL;
current_queue->end = NULL;
return FLEDASTY_ERROR_NONE;
}