eaarl-io  1.0.1+71abbd4
EAARL Input/Output Library (Public API)
Enumerations | Functions
error.h File Reference

Error codes and handling. More...

#include <stdio.h>
#include <string.h>

Go to the source code of this file.

Enumerations

enum  eaarlio_error {
  EAARLIO_SUCCESS, EAARLIO_NULL, EAARLIO_BUFFER_SHORT, EAARLIO_VALUE_OUT_OF_RANGE,
  EAARLIO_CORRUPT, EAARLIO_STRING_UNTERMINATED, EAARLIO_FLIGHT_INVALID, EAARLIO_FLIGHT_RASTER_INVALID,
  EAARLIO_EDB_FILENAME_TOO_LONG, EAARLIO_TLD_TYPE_UNKNOWN, EAARLIO_TLD_OPENER_INVALID, EAARLIO_MEMORY_INVALID,
  EAARLIO_MEMORY_ALLOC_FAIL, EAARLIO_STREAM_INVALID, EAARLIO_STREAM_NOT_IMPL, EAARLIO_STREAM_OPEN_ERROR,
  EAARLIO_STREAM_CLOSE_ERROR, EAARLIO_STREAM_READ_ERROR, EAARLIO_STREAM_READ_SHORT, EAARLIO_STREAM_WRITE_ERROR,
  EAARLIO_STREAM_WRITE_SHORT, EAARLIO_STREAM_SEEK_ERROR, EAARLIO_STREAM_SEEK_INVALID, EAARLIO_STREAM_TELL_ERROR,
  EAARLIO_ERROR_UNKNOWN
}
 

Functions

char const * eaarlio_error_name (eaarlio_error err)
 Retrieve the symbolic name for an error. More...
 
char const * eaarlio_error_message (eaarlio_error err)
 Retrieve an error message for an error. More...
 
int eaarlio_error_check (eaarlio_error err, char *format,...)
 Check for errors and display error if needed. More...
 

Detailed Description

Error codes and handling.

This header defines the error codes that are used as return results throughout the library. It also provides two functions that can be used to provide human-readable information about error codes.

Enumeration Type Documentation

◆ eaarlio_error

Enumerator
EAARLIO_SUCCESS 

Success (no error was encountered)

EAARLIO_NULL 

An unexpected null pointer was encountered.

EAARLIO_BUFFER_SHORT 

A buffer's allocated size was too small.

EAARLIO_VALUE_OUT_OF_RANGE 

A value was encountered that was out of range for its type.

EAARLIO_CORRUPT 

Unable to complete an operation due to suspected corrupted data.

EAARLIO_STRING_UNTERMINATED 

Encountered a string that appeared unterminated.

EAARLIO_FLIGHT_INVALID 

Invalid flight configuration.

EAARLIO_FLIGHT_RASTER_INVALID 

An invalid raster number was specified.

EAARLIO_EDB_FILENAME_TOO_LONG 

Encountered a filename whose length exceeds what EDB supports.

EAARLIO_TLD_TYPE_UNKNOWN 

Encountered an unknown TLD record type.

EAARLIO_TLD_OPENER_INVALID 

Invalid TLD opener.

EAARLIO_MEMORY_INVALID 

Invalid memory handler.

EAARLIO_MEMORY_ALLOC_FAIL 

Unable to allocate memory.

EAARLIO_STREAM_INVALID 

Invalid stream configuration.

EAARLIO_STREAM_NOT_IMPL 

Attempted to use a stream operation that was not implemented.

EAARLIO_STREAM_OPEN_ERROR 

Unable to open file.

EAARLIO_STREAM_CLOSE_ERROR 

Unable to close file.

EAARLIO_STREAM_READ_ERROR 

Attempt to read failed.

EAARLIO_STREAM_READ_SHORT 

Fewer bytes read than requested (may signal end of file)

EAARLIO_STREAM_WRITE_ERROR 

Attempt to write failed.

EAARLIO_STREAM_WRITE_SHORT 

Fewer bytes written than expected.

EAARLIO_STREAM_SEEK_ERROR 

Unable to seek to position in file.

EAARLIO_STREAM_SEEK_INVALID 

Request to seek used invalid whence.

EAARLIO_STREAM_TELL_ERROR 

Unable to tell position in file.

EAARLIO_ERROR_UNKNOWN 

Unknown error.

This is not intended to be explicitly used. It primarily exists as a terminal value in the enum to support looping in test cases. If none of the existing enum values work for a new error situation, then a new value should be added to the enum.

Examples:
example_errors.c.

Function Documentation

◆ eaarlio_error_check()

int eaarlio_error_check ( eaarlio_error  err,
char *  format,
  ... 
)

Check for errors and display error if needed.

This is a simple handler for checking eaarlio_error codes and displaying error messages.

When err is EAARLIO_SUCCESS, this function does nothing except return 0.

When err is anything other than EAARLIO_SUCCESS, it prints an error message to stderr and returns 1. If format is provided, then fprintf will be used to print the supplied message (passing any additional parameters through to it). Then eaarlio_error_name and eaarlio_error_message are used to display the error code and a short description to stderr.

format can be null, in which case just the error code and description are output to stderr.

Parameters
[in]errError code from an eaarlio library function
[in]formatFormat string for message to print on error
[in]...Additional arguments to use when printing error
Return values
0if err is EAARLIO_SUCCESS
1if err is not EAARLIO_SUCCESS
Postcondition
If err is not EAARLIO_SUCCESS, then an error message is printed to stderr.

As an example, consider this sample code:

int raster_number = 42;
int failed = eaarlio_error_check(err,
"Failed to access raster %d", raster_number);

Because err is not EAARLIO_SUCCESS, this would print the following message to stderr and assign 1 to failed:

Failed to access raster 42
Error code: EAARLIO_NULL: Attempted to use a null pointer
Examples:
eaarlio_yaml.c, example_edb_read.c, example_edb_write.c, example_errors.c, example_file_tld_opener.c, example_flight_read_raster_pulse.c, and example_flight_read_rasters.c.

◆ eaarlio_error_message()

char const* eaarlio_error_message ( eaarlio_error  err)

Retrieve an error message for an error.

For example, eaarlio_error_message(EAARLIO_SUCCESS) will return "Success!".

Parameters
[in]errAn error code
Returns
A string containing a short message that describes the error code
Examples:
example_errors.c.

◆ eaarlio_error_name()

char const* eaarlio_error_name ( eaarlio_error  err)

Retrieve the symbolic name for an error.

For example, eaarlio_error_name(EAARLIO_SUCCESS) will return "EAARLIO_SUCCESS".

Parameters
[in]errAn error code
Returns
A string containing the name of the error code
Examples:
example_errors.c.