Continue working on pipeline

This commit is contained in:
Piotr Krygier committed 2025-06-20 13:44:33 +02:00
1 parent 45be08019e
commit bd05c03a12
28 files changed
+453 -423

No files matched your search

+74 -8
View File
@@ -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;
}