(performance_android.c) Cleanups

This commit is contained in:
twinaphex 2015-09-15 19:24:33 +02:00
parent 557347fba6
commit 6138596874
1 changed files with 14 additions and 25 deletions

View File

@ -97,8 +97,7 @@ static INLINE void cpu_x86_cpuid(int func, int values[4])
* zero-terminate the content. Will not read more * zero-terminate the content. Will not read more
* than 'buffsize' bytes. * than 'buffsize' bytes.
*/ */
static int static int cpu_read_file(const char *pathname, char *buffer, size_t buffsize)
cpu_read_file(const char* pathname, char* buffer, size_t buffsize)
{ {
int len; int len;
int fd = open(pathname, O_RDONLY); int fd = open(pathname, O_RDONLY);
@ -120,17 +119,14 @@ cpu_read_file(const char* pathname, char* buffer, size_t buffsize)
* *
* Return NULL if not found * Return NULL if not found
*/ */
static char* static char *extract_cpuinfo_field(char* buffer, int buflen, const char* field)
extract_cpuinfo_field(char* buffer, int buflen, const char* field)
{ {
int len; int len;
const char *q; const char *q;
int fieldlen = strlen(field); int fieldlen = strlen(field);
char* bufend = buffer + buflen; char* bufend = buffer + buflen;
char* result = NULL; char* result = NULL;
/* Look for first field occurence, and ensures it starts the line. */
/* Look for first field occurence, and ensures it starts the line.
*/
const char *p = buffer; const char *p = buffer;
bufend = buffer + buflen; bufend = buffer + buflen;
@ -139,7 +135,7 @@ extract_cpuinfo_field(char* buffer, int buflen, const char* field)
{ {
p = memmem(p, bufend-p, field, fieldlen); p = memmem(p, bufend-p, field, fieldlen);
if (p == NULL) if (p == NULL)
goto end; return result;
if (p == buffer || p[-1] == '\n') if (p == buffer || p[-1] == '\n')
break; break;
@ -151,7 +147,7 @@ extract_cpuinfo_field(char* buffer, int buflen, const char* field)
p += fieldlen; p += fieldlen;
p = memchr(p, ':', bufend-p); p = memchr(p, ':', bufend-p);
if (p == NULL || p[1] != ' ') if (p == NULL || p[1] != ' ')
goto end; return result;
/* Find the end of the line */ /* Find the end of the line */
p += 2; p += 2;
@ -163,13 +159,10 @@ extract_cpuinfo_field(char* buffer, int buflen, const char* field)
len = q-p; len = q-p;
result = malloc(len+1); result = malloc(len+1);
if (result == NULL) if (result == NULL)
goto end; return result;
memcpy(result, p, len); memcpy(result, p, len);
result[len] = '\0'; result[len] = '\0';
end:
return result;
} }
/* Checks that a space-separated list of items contains one given 'item'. /* Checks that a space-separated list of items contains one given 'item'.
@ -258,9 +251,9 @@ typedef struct {
*/ */
static void cpulist_parse(CpuList* list, const char* line, int line_len) static void cpulist_parse(CpuList* list, const char* line, int line_len)
{ {
const char* q;
const char* p = line; const char* p = line;
const char* end = p + line_len; const char* end = p + line_len;
const char* q;
/* NOTE: the input line coming from sysfs typically contains a /* NOTE: the input line coming from sysfs typically contains a
* trailing newline, so take care of it in the code below * trailing newline, so take care of it in the code below
@ -277,7 +270,7 @@ static void cpulist_parse(CpuList* list, const char* line, int line_len)
/* Get first value */ /* Get first value */
p = parse_decimal(p, q, &start_value); p = parse_decimal(p, q, &start_value);
if (p == NULL) if (p == NULL)
goto BAD_FORMAT; return;
end_value = start_value; end_value = start_value;
@ -303,14 +296,10 @@ static void cpulist_parse(CpuList* list, const char* line, int line_len)
if (p < end) if (p < end)
p++; p++;
} }
BAD_FORMAT:
;
} }
/* Read a CPU list from one sysfs file */ /* Read a CPU list from one sysfs file */
static void static void cpulist_read_from(CpuList* list, const char* filename)
cpulist_read_from(CpuList* list, const char* filename)
{ {
char file[64]; char file[64];
int filelen; int filelen;