Merge branches 'perf/powerpc' and 'perf/bench' into perf/core
[deliverable/linux.git] / tools / perf / util / string.c
CommitLineData
a2a99e8e 1#include <string.h>
ea5cc87c
ACM
2#include "string.h"
3
4static int hex(char ch)
5{
6 if ((ch >= '0') && (ch <= '9'))
7 return ch - '0';
8 if ((ch >= 'a') && (ch <= 'f'))
9 return ch - 'a' + 10;
10 if ((ch >= 'A') && (ch <= 'F'))
11 return ch - 'A' + 10;
12 return -1;
13}
14
15/*
16 * While we find nice hex chars, build a long_val.
17 * Return number of chars processed.
18 */
9cffa8d5 19int hex2u64(const char *ptr, u64 *long_val)
ea5cc87c
ACM
20{
21 const char *p = ptr;
22 *long_val = 0;
23
24 while (*p) {
25 const int hex_val = hex(*p);
26
27 if (hex_val < 0)
28 break;
29
30 *long_val = (*long_val << 4) | hex_val;
31 p++;
32 }
33
34 return p - ptr;
35}
a2a99e8e
ACM
36
37char *strxfrchar(char *s, char from, char to)
38{
39 char *p = s;
40
41 while ((p = strchr(p, from)) != NULL)
42 *p++ = to;
43
44 return s;
45}
This page took 0.048067 seconds and 5 git commands to generate.