terom@17: #include "error.h" terom@17: terom@18: /* terom@18: * Mapping for error codes terom@18: */ terom@17: const char *error_names[PT_ERR_MAX] = { terom@17: [PT_SUCCESS] = "Success", terom@65: [PT_ERR] = "Unspecified error", terom@17: [PT_ERR_MEM] = "malloc()", terom@17: terom@17: [PT_ERR_PATH] = "path", terom@17: [PT_ERR_OPEN_MODE] = "open_mode", terom@17: terom@17: [PT_ERR_IMG_STAT] = "stat(.png)", terom@69: [PT_ERR_IMG_OPEN] = "open(.png)", terom@69: [PT_ERR_IMG_FORMAT] = "Unknown image format", terom@17: terom@17: [PT_ERR_PNG_CREATE] = "png_create()", terom@17: [PT_ERR_PNG] = "png_*()", terom@17: terom@17: [PT_ERR_CACHE_STAT] = "stat(.cache)", terom@17: [PT_ERR_CACHE_OPEN_READ] = "open(.cache)", terom@17: [PT_ERR_CACHE_OPEN_TMP] = "open(.tmp)", terom@17: [PT_ERR_CACHE_SEEK] = "seek(.cache)", terom@17: [PT_ERR_CACHE_READ] = "read(.cache)", terom@17: [PT_ERR_CACHE_WRITE] = "write(.cache)", terom@17: [PT_ERR_CACHE_TRUNC] = "truncate(.cache)", terom@17: [PT_ERR_CACHE_MMAP] = "mmap(.cache)", terom@17: [PT_ERR_CACHE_RENAME_TMP] = "rename(.tmp, .cache)", terom@56: [PT_ERR_CACHE_VERSION] = "Incompatible .cache version", terom@59: [PT_ERR_CACHE_MUNMAP] = "munmap(cache->file)", terom@59: [PT_ERR_CACHE_CLOSE] = "close(cache->fd)", terom@17: terom@19: [PT_ERR_PTHREAD_CREATE] = "pthread_create", terom@19: [PT_ERR_CTX_SHUTDOWN] = "pt_ctx is shutting down", terom@19: terom@86: [PT_ERR_TILE_DIM] = "Invalid tile dimensions", terom@17: [PT_ERR_TILE_CLIP] = "Tile outside of image", terom@86: [PT_ERR_TILE_ZOOM] = "Invalid zoom level", terom@17: }; terom@17: terom@17: const char *pt_strerror (int err) terom@17: { terom@17: if (err < 0) terom@17: err = -err; terom@17: terom@17: if (err < PT_SUCCESS || err >= PT_ERR_MAX) terom@65: return "Invalid error code"; terom@65: terom@65: else if (!error_names[err]) terom@65: return "Missing string for error code"; terom@65: terom@17: else terom@17: return error_names[err]; terom@17: }