12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- #include "cms_err.h"
- #include <stdio.h>
- #include <stdlib.h>
- #include <errno.h>
-
- #ifdef DEBUG
- #include <error.h>
- #endif
-
- static char* get_error_message(cms_err err)
- {
- switch (err)
- {
- case CMS_ERR_NONE:
- return "";
- case CMS_ERR_UNKNOWN:
- return "Unknown error.";
- case CMS_ERR_ALLOC:
- return "Memory allocation failed.";
- case CMS_ERR_PARSE:
- return "Parse error.";
- case CMS_ERR_NOENT:
- return "No such file or directory.";
- case CMS_ERR_NOTFILE:
- return "Not a file.";
- case CMS_ERR_NOTDIR:
- return "Not a directory.";
- case CMS_ERR_FILEEXISTS:
- return "File exists.";
- case CMS_ERR_DIREXISTS:
- return "Directory exists.";
- case CMS_ERR_PERM:
- return "Permission denied.";
- case CMS_ERR_INITED:
- return "Already initiated.";
- case CMS_ERR_NOTINITED:
- return "Not initiated.";
- }
- }
-
- void _cms_err_panic(cms_err err, char* msg, const char* file, int line)
- {
- if (!err)
- return;
-
- #ifdef DEBUG
- fprintf(stderr, "File %s, line %i:\n\t", file, line);
- #endif
-
- if (msg == NULL)
- fprintf(stderr, "Error: %s\n", get_error_message(err));
- else
- fprintf(stderr, "Error: %s: %s\n", msg, get_error_message(err));
-
- exit(1);
- }
-
- cms_err cms_err_from_std_err(int err)
- {
- #ifdef DEBUG
- error(0, err, "converting to cms_err");
- #endif
-
- switch (err)
- {
- case EACCES:
- return CMS_ERR_PERM;
- case EEXIST:
- return CMS_ERR_FILEEXISTS;
- case EFAULT:
- return CMS_ERR_PERM;
- case EISDIR:
- return CMS_ERR_NOTFILE;
- case ENOENT:
- return CMS_ERR_NOENT;
- case ENOMEM:
- return CMS_ERR_ALLOC;
- case ENOTDIR:
- return CMS_ERR_NOTDIR;
- case EROFS:
- return CMS_ERR_PERM;
- default:
- return CMS_ERR_UNKNOWN;
- }
- }
|