Continue working on pipeline
This commit is contained in:
1 parent
45be08019e
commit
bd05c03a12
28 files changed
+453
-423
No files matched your search
@@ -1,3 +1,5 @@
|
||||
find_package(Intl)
|
||||
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Werror")
|
||||
|
||||
add_library(utilities SHARED)
|
||||
@@ -12,4 +14,4 @@ target_sources(utilities PRIVATE
|
||||
)
|
||||
|
||||
target_link_libraries(utilities PRIVATE
|
||||
pthread)
|
||||
Intl::Intl)
|
||||
@@ -26,6 +26,8 @@ enum common_error_t
|
||||
RSE_ERROR_NULL_POINTER,
|
||||
RSE_ERROR_ALREADY_INITIALIZED,
|
||||
RSE_COMMON_ERROR_MALLLOC_FAILED,
|
||||
RSE_ERROR_INVALID_PARAM,
|
||||
RSE_ERROR_INTERNAL_ERROR,
|
||||
};
|
||||
|
||||
#define ERRORS_COMMON_H
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define FILE_UTILS_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include "utilities/commons.h"
|
||||
|
||||
/**
|
||||
* @brief Reads file and puts its content into char buffer. If NULL is provided as buffer, than just bytes_count
|
||||
@@ -15,5 +16,7 @@ void read_file(const char* file_path, size_t* bytes_count, char* buffer);
|
||||
|
||||
void write_to_file(const char* file_name, size_t bytes_count, char* buffer);
|
||||
|
||||
rse_err_t get_curr_path(char* path, size_t max_path_length);
|
||||
|
||||
#endif /* FILE_UTILS_H */
|
||||
|
||||
+10
-10
@@ -30,21 +30,21 @@
|
||||
}
|
||||
|
||||
#define RSE_LINKED_LIST_PUSH_FRONT(list, value) \
|
||||
typeof(list) new_node = NULL; \
|
||||
__typeof__(list) new_node = NULL; \
|
||||
rse_malloc(new_node, sizeof(*(list))); \
|
||||
new_node->data = value; \
|
||||
new_node->next = list; \
|
||||
list = new_node
|
||||
|
||||
#define RSE_LINKED_LIST_PUSH_BACK(list, value) \
|
||||
typeof(list) new_node = NULL; \
|
||||
__typeof__((list)) new_node = NULL; \
|
||||
rse_malloc(new_node, sizeof(*(list))); \
|
||||
new_node->data = value; \
|
||||
new_node->next = NULL; \
|
||||
if (list == NULL) { \
|
||||
list = new_node; \
|
||||
} else { \
|
||||
typeof(list) current = list; \
|
||||
__typeof__(list) current = list; \
|
||||
while (current->next != NULL) { \
|
||||
current = current->next; \
|
||||
} \
|
||||
@@ -53,7 +53,7 @@
|
||||
|
||||
#define RSE_LINKED_LIST_POP_FRONT(list) \
|
||||
if (list != NULL) { \
|
||||
typeof(list) temp = list; \
|
||||
__typeof__(list) temp = list; \
|
||||
list = list->next; \
|
||||
rse_free(temp); \
|
||||
}
|
||||
@@ -64,7 +64,7 @@
|
||||
rse_free(list); \
|
||||
list = NULL; \
|
||||
} else { \
|
||||
typeof(list) *current = list; \
|
||||
__typeof__(list) *current = list; \
|
||||
while (current->next->next != NULL) { \
|
||||
current = current->next; \
|
||||
} \
|
||||
@@ -78,7 +78,7 @@
|
||||
|
||||
#define RSE_LINKED_LIST_BACK(list) \
|
||||
if (list != NULL) { \
|
||||
typeof(list) *current = list; \
|
||||
__typeof__(list) *current = list; \
|
||||
while (current->next != NULL) { \
|
||||
current = current->next; \
|
||||
} \
|
||||
@@ -91,7 +91,7 @@
|
||||
#define RSE_LINKED_LIST_SIZE(list) \
|
||||
({ \
|
||||
int size = 0; \
|
||||
typeof(list) current = list; \
|
||||
__typeof__(list) current = list; \
|
||||
while (current != NULL) { \
|
||||
size++; \
|
||||
current = current->next; \
|
||||
@@ -101,17 +101,17 @@
|
||||
|
||||
#define RSE_LINKED_LIST_CLEAR(list) \
|
||||
while (list != NULL) { \
|
||||
typeof(list) temp = list; \
|
||||
__typeof__(list) temp = list; \
|
||||
list = list->next; \
|
||||
rse_free(temp); \
|
||||
}
|
||||
|
||||
#define RSE_LINKED_LIST_FOREACH(list, i) \
|
||||
for (typeof(list) i = list; i != NULL; i = i->next)
|
||||
for (__typeof__(list) i = list; i != NULL; i = i->next)
|
||||
|
||||
|
||||
#define RSE_LINKED_LIST_FOREACH_REVERSE(list, i) \
|
||||
for (typeof(list) i = list; i != NULL; i = i->next)
|
||||
for (__typeof__(list) i = list; i != NULL; i = i->next)
|
||||
|
||||
#define RSE_LINKED_LIST_TO_ARRAY(list, array) \
|
||||
({ \
|
||||
|
||||
@@ -2,16 +2,27 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "utilities/commons.h"
|
||||
#include "utilities/errors_common.h"
|
||||
#include "utilities/localization.h"
|
||||
#include "utilities/logger.h"
|
||||
|
||||
#ifdef __linux__
|
||||
#include <unistd.h>
|
||||
#include <limits.h>
|
||||
#endif /* ifndef __linux */
|
||||
|
||||
#define MAX_PATH_LENGTH (4096U)
|
||||
|
||||
void read_file(const char* file_name, size_t* bytes_count, char* buffer)
|
||||
{
|
||||
errno_t err = 0;
|
||||
FILE* file = NULL;
|
||||
|
||||
err = fopen_s(&file, file_name, "rb");
|
||||
file = fopen(file_name, "rb");
|
||||
|
||||
if (0 != err) {
|
||||
perror("Failed to open file");
|
||||
if (NULL == file) {
|
||||
LOGE(_("Failed to open file for read: %s\n"), file_name);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -33,16 +44,71 @@ void read_file(const char* file_name, size_t* bytes_count, char* buffer)
|
||||
|
||||
void write_to_file(const char* file_name, size_t bytes_count, char* buffer)
|
||||
{
|
||||
errno_t err = 0;
|
||||
FILE* file = NULL;
|
||||
|
||||
err = fopen_s(&file, file_name, "wb");
|
||||
file = fopen(file_name, "wb");
|
||||
|
||||
if (0 != err) {
|
||||
perror("Failed to open file.");
|
||||
if (NULL == file) {
|
||||
LOGE(_("Failed to open file for write: %s\n"), file_name);
|
||||
return;
|
||||
}
|
||||
|
||||
fwrite(buffer, bytes_count, 1, file);
|
||||
fclose(file);
|
||||
}
|
||||
|
||||
rse_err_t get_curr_path(char* path, size_t path_size)
|
||||
{
|
||||
char* last_sep = NULL;
|
||||
char* tmp_path = NULL;
|
||||
size_t binary_path_length = 0U;
|
||||
size_t directory_path_length = 0U;
|
||||
|
||||
if (NULL == path) {
|
||||
LOGE(_("Failed to get path. Provided pointer is NULL\n"));
|
||||
|
||||
return RSE_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
if (0 == path_size) {
|
||||
LOGE(_("Max path length cannot be 0\n"));
|
||||
|
||||
return RSE_ERROR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
rse_memset(path, '\0', path_size);
|
||||
rse_malloc(tmp_path, MAX_PATH_LENGTH);
|
||||
|
||||
#ifdef __linux__
|
||||
binary_path_length = readlink("/proc/self/exe", tmp_path, MAX_PATH_LENGTH - 1);
|
||||
if (binary_path_length == -1) {
|
||||
LOGF(_("Failed to read current binary path\n"));
|
||||
|
||||
return RSE_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
tmp_path[binary_path_length] = '\0';
|
||||
#endif /* ifdef __linux__ */
|
||||
|
||||
last_sep = strrchr(tmp_path, '/') + 1;
|
||||
|
||||
if (NULL == last_sep) {
|
||||
LOGE(_("Failed to get last separator in path\n"));
|
||||
|
||||
return RSE_ERROR_INTERNAL_ERROR;
|
||||
}
|
||||
|
||||
directory_path_length = last_sep - tmp_path;
|
||||
|
||||
if (directory_path_length > path_size) {
|
||||
LOGE(_("Provided path buffer is too small\n"));
|
||||
|
||||
return RSE_ERROR_INTERNAL_ERROR;
|
||||
}
|
||||
|
||||
strncpy(path, tmp_path, directory_path_length);
|
||||
|
||||
free(tmp_path);
|
||||
|
||||
return RSE_ERROR_NO_ERROR;
|
||||
}
|
||||
Reference in new issue
Block a user