[A] Add ft_strerror function

This commit is contained in:
seleznevae
2020-02-08 12:15:35 +03:00
parent bff48549de
commit 58a63f90f2
9 changed files with 137 additions and 0 deletions

View File

@@ -3614,6 +3614,25 @@ void ft_set_memory_funcs(void *(*f_malloc)(size_t size), void (*f_free)(void *pt
set_memory_funcs(f_malloc, f_free);
}
const char *ft_strerror(int error_code)
{
switch (error_code) {
case FT_MEMORY_ERROR:
return "Libfort error (out of memory)";
case FT_ERROR:
return "Libfort error (general error)";
case FT_EINVAL:
return "Libfort error (invalid argument)";
case FT_INTERN_ERROR:
return "Libfort error (internal logic error)";
default:
if (error_code < 0)
return "Libfort unknown error";
else
return "Libfort success";
}
}
int ft_set_cell_span(ft_table_t *table, size_t row, size_t col, size_t hor_span)
{
assert(table);

View File

@@ -73,10 +73,33 @@ SOFTWARE.
/*****************************************************************************
* RETURN CODES
*****************************************************************************/
/**
* Operation successfully ended.
*/
#define FT_SUCCESS 0
/**
* Memory allocation failed.
*/
#define FT_MEMORY_ERROR -1
/**
* General error.
*/
#define FT_ERROR -2
/**
* Invalid argument.
*/
#define FT_EINVAL -3
/**
* Libfort internal logic error.
*/
#define FT_INTERN_ERROR -4
#define FT_IS_SUCCESS(arg) ((arg) >= 0)
#define FT_IS_ERROR(arg) ((arg) < 0)
@@ -937,6 +960,16 @@ int ft_set_cell_span(ft_table_t *table, size_t row, size_t col, size_t hor_span)
void ft_set_memory_funcs(void *(*f_malloc)(size_t size), void (*f_free)(void *ptr));
/**
* Return string describing the `error_code`.
*
* @param error_code
* Error code returned by the library.
* @return
* String describing the error.
*/
const char *ft_strerror(int error_code);
#ifdef FT_HAVE_WCHAR