(performance_android.c) Cleanup

This commit is contained in:
twinaphex 2015-09-05 15:38:33 +02:00
parent 7f4ddc6775
commit c762ea024e

View File

@ -100,9 +100,8 @@ static INLINE void cpu_x86_cpuid(int func, int values[4])
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 fd, len; int len;
int fd = open(pathname, O_RDONLY);
fd = open(pathname, O_RDONLY);
if (fd < 0) if (fd < 0)
return -1; return -1;
@ -124,21 +123,23 @@ cpu_read_file(const char* pathname, char* buffer, size_t buffsize)
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;
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;
int len;
const char *p, *q;
/* Look for first field occurence, and ensures it starts the line. /* Look for first field occurence, and ensures it starts the line.
*/ */
p = buffer; const char *p = buffer;
bufend = buffer + buflen; bufend = buffer + buflen;
for (;;) for (;;)
{ {
p = memmem(p, bufend-p, field, fieldlen); p = memmem(p, bufend-p, field, fieldlen);
if (p == NULL) if (p == NULL)
goto EXIT; goto end;
if (p == buffer || p[-1] == '\n') if (p == buffer || p[-1] == '\n')
break; break;
@ -150,7 +151,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 EXIT; goto end;
/* Find the end of the line */ /* Find the end of the line */
p += 2; p += 2;
@ -162,12 +163,12 @@ 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 EXIT; goto end;
memcpy(result, p, len); memcpy(result, p, len);
result[len] = '\0'; result[len] = '\0';
EXIT: end:
return result; return result;
} }