1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- #include "cms_err.h"
- #include <stdio.h>
- #include <stdlib.h>
- #include <errno.h>
-
- static char* get_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_FILENOENT:
- return "File doesn't exist.";
- case CMS_ERR_DIRNOENT:
- return "Directory doesn't exist.";
- case CMS_ERR_NOTFILE:
- return "Not a file.";
- case CMS_ERR_NOTDIR:
- return "Not a directory.";
- 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)
- {
- if (err == CMS_ERR_NONE)
- return;
-
- if (msg == NULL)
- fprintf(stderr, "Error: %s\n", get_message(err));
- else
- fprintf(stderr, "Error: %s (%s)\n", get_message(err), msg);
-
- exit(1);
- }
-
- cms_err cms_err_from_std_err(int err)
- {
- 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_FILENOENT;
- case ENOMEM:
- return CMS_ERR_ALLOC;
- case ENOTDIR:
- return CMS_ERR_NOTDIR;
- case EROFS:
- return CMS_ERR_PERM;
- default:
- return CMS_ERR_UNKNOWN;
- }
- }
|