1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
#include "spm.h"
int spmerrno = 0;
static char spmerrbuf[255];
static char spmerrbuf_reason[255];
const char *SPM_ERR_STRING[] = {
"Success",
"No root record",
"Dangerous root path",
"Package not found",
"Invalid package",
"Bad package checksum",
"Failed to fetch package",
"Manifest has no header",
"Manifest has no data",
NULL,
};
void spmerrno_cause(const char *reason) {
char *buf = spmerrbuf_reason;
sprintf(buf, " (%s)", reason);
return;
}
/**
*
* @param code
* @return
*/
char *spm_strerror(int code) {
char *buf = spmerrbuf;
int is_spm_error = SPM_ERR_CONFIRM(code);
memset(buf, '\0', sizeof(spmerrbuf));
if (is_spm_error == 0) {
strcpy(buf, strerror(code));
} else {
strcpy(buf, SPM_ERR_STRING[SPM_ERR_INDEX(code)]);
}
if (strlen(spmerrbuf_reason)) {
strcat(buf, spmerrbuf_reason);
}
return buf;
}
void spm_perror(const char *msg) {
fprintf(stderr, "%s: %s\n", msg ? msg : "", spm_strerror(spmerrno));
}
|