forked from bloomberg/comdb2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparse_lsn.c
55 lines (46 loc) · 1.16 KB
/
parse_lsn.c
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
#include <stdlib.h>
#include "parse_lsn.h"
#define skipws(p) \
{ \
while (*p != '\0' && *p == ' ') \
p++; \
}
#define isnum(p) (*p >= '0' && *p <= '9')
int char_to_lsn(const char *lsnstr, unsigned int *file, unsigned int *offset)
{
const char *p = lsnstr;
while (*p != '\0' && *p == ' ')
p++;
skipws(p);
/* Parse opening '{' */
if (*p != '{')
return -1;
p++;
skipws(p);
if (!isnum(p))
return -1;
/* Parse file */
*file = (unsigned int)atol(p);
while (isnum(p))
p++;
skipws(p);
if (*p != ':')
return -1;
p++;
skipws(p);
if (!isnum(p))
return -1;
/* Parse offset */
*offset = (unsigned int)atol(p);
while (isnum(p))
p++;
skipws(p);
/* Parse closing '}' */
if (*p != '}')
return -1;
p++;
skipws(p);
if (*p != '\0')
return -1;
return 0;
}