pink26 0.1.1
Image processing and digital topology for teaching
Loading...
Searching...
No Matches
status.h File Reference

Status codes and error messages. More...

#include <stdint.h>

Go to the source code of this file.

Macros

#define P26_THREAD_LOCAL   _Thread_local
 Portability switch: storage class of the thread-local error buffer.
#define P26_PRINTF_LIKE(fmt_index, args_index)
 Portability switch: marks a printf-like function so that GCC and Clang check its format string against its arguments (-Wformat).

Typedefs

typedef int64_t p26_index
 Pixel index or size in pixels (64-bit, so large 3D images fit).

Enumerations

enum  p26_status {
  P26_OK = 0 , P26_E_INVALID_ARG , P26_E_TYPE , P26_E_NOMEM ,
  P26_E_FORMAT , P26_E_UNSUPPORTED , P26_E_IO , P26_E_OVERFLOW ,
  P26_E_INTERNAL
}
 Result of a pink26 function. More...

Functions

p26_status p26_fail (p26_status status, const char *format,...) P26_PRINTF_LIKE(2
 Records an error message for the calling thread and returns status.
p26_status const char * p26_last_error (void)
 Returns the last message recorded by p26_fail() in the calling thread.
void p26_clear_error (void)
 Empties the error message of the calling thread.
const char * p26_status_name (p26_status status)
 Returns the name of a status code, e.g.

Detailed Description

Status codes and error messages.

Every pink26 function that can fail returns a p26_status. On failure it also records a human-readable message (what was wrong, with which value) that p26_last_error() returns. The message buffer is thread-local, so concurrent calls from several threads do not mix their messages.

Macro Definition Documentation

◆ P26_PRINTF_LIKE

#define P26_PRINTF_LIKE ( fmt_index,
args_index )

Portability switch: marks a printf-like function so that GCC and Clang check its format string against its arguments (-Wformat).

fmt_index is the position of the format parameter, args_index that of the "...", both counted from 1. Other compilers ignore it.

Enumeration Type Documentation

◆ p26_status

enum p26_status

Result of a pink26 function.

P26_OK is 0; every error is non-zero.

Enumerator
P26_OK 

Success.

P26_E_INVALID_ARG 

NULL pointer, bad dimension, bad connectivity...

P26_E_TYPE 

Unknown or unsupported pixel type.

P26_E_NOMEM 

Memory allocation failed.

P26_E_FORMAT 

Malformed or truncated file content.

P26_E_UNSUPPORTED 

Valid input that pink26 does not handle (e.g.

16-bit data).

P26_E_IO 

A file could not be opened, read, written or closed.

P26_E_OVERFLOW 

A size does not fit in memory or in the integer types.

P26_E_INTERNAL 

Admitted legacy Pink code aborted (a former exit() call).

Function Documentation

◆ p26_fail()

p26_status p26_fail ( p26_status status,
const char * format,
... )

Records an error message for the calling thread and returns status.

Library code reports every failure with return p26_fail(...), so the status and its explanation always travel together.

Parameters
statusStatus to return (normally an error code).
formatprintf-style format of the message; then its arguments.
Returns
status, unchanged.

Messages longer than 511 characters are truncated.

◆ p26_last_error()

p26_status const char * p26_last_error ( void )

Returns the last message recorded by p26_fail() in the calling thread.

Returns
A NUL-terminated string owned by the library, valid until the next pink26 call in this thread; "" if no message was recorded or after p26_clear_error(). Never NULL.

◆ p26_status_name()

const char * p26_status_name ( p26_status status)

Returns the name of a status code, e.g.

"P26_E_FORMAT".

Parameters
statusAny value, valid or not.
Returns
A static string; "P26_UNKNOWN" for a value outside the enum.