blob: d4402997d672e423b4abc153b303d84884daed75 (
plain)
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
50
51
52
53
54
55
56
57
58
59
60
61
62
|
/**
* @file op_string.c
* general purpose C string handling implementation.
*
* @remark Copyright 2003 OProfile authors
* @remark Read the file COPYING
*
* @author John Levon
* @author Philippe Elie
*/
#include <string.h>
#include "op_libiberty.h"
char * op_xstrndup(char const * s, size_t len)
{
return xmemdup(s, len, len + 1);
}
size_t op_hash_string(char const * str)
{
size_t hash = 0;
for (; *str; ++str)
hash ^= (hash << 16) ^ (hash >> 8) ^ *str;
return hash;
}
int strisprefix(char const * str, char const * prefix)
{
return strstr(str, prefix) == str;
}
char const * skip_ws(char const * c)
{
while (*c == ' ' || *c == '\t' || *c == '\n')
++c;
return c;
}
char const * skip_nonws(char const * c)
{
while (*c && *c != ' ' && *c != '\t' && *c != '\n')
++c;
return c;
}
int empty_line(char const * c)
{
return !*skip_ws(c);
}
int comment_line(char const * c)
{
return *skip_ws(c) == '#';
}
|