Cleanups and small fixes

This commit is contained in:
2016-08-09 14:16:30 +03:00
parent 0d5eeed758
commit 3fecfdbbc4
6 changed files with 51 additions and 49 deletions

View File

@@ -7,23 +7,26 @@
void enumtostr(char *scode, int code)
{
char line[128];
FILE *fd;
FILE *fp;
int bytes = 0;
snprintf(scode, 10, "%d", code);
fd = fopen("/usr/lib/rmps/resources/enum_codes", "r");
if (fd == NULL) {
fp = fopen("/usr/lib/rmps/resources/enum_codes", "r");
if (fp == NULL) {
log_trace(ERROR, "Failed to fetch error enum code!");
return;
}
while (fgets(line, sizeof(line), fd) != NULL)
while (fgets(line, sizeof(line), fp) != NULL)
if (strstr(line, scode) != NULL) {
sprintf(scode, "%s", line);
char *byte;
bytes = sprintf(scode, "%s", line);
byte = memchr(scode, '\n', bytes);
byte[-1] = '\0';
break;
}
strncpy( scode,
memchr(scode, '\"', strlen(scode)),
strlen(scode) );
fclose(fd);
strncpy(scode, (char*)memchr(scode, '\"', bytes) + 1, bytes);
fclose(fp);
return;
}