Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
varnish-cache
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
varnishcache
varnish-cache
Commits
3f6a2517
Commit
3f6a2517
authored
Aug 31, 2021
by
Dridi Boukelmoune
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
vnum: New VNUM_uint() and VNUM_hex() functions
With the hex table suggested by fgs.
parent
b47e278a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
65 additions
and
0 deletions
+65
-0
vnum.h
include/vnum.h
+2
-0
vnum.c
lib/libvarnish/vnum.c
+63
-0
No files found.
include/vnum.h
View file @
3f6a2517
...
...
@@ -37,6 +37,8 @@ vtim_dur VNUM_duration(const char *p);
int64_t
VNUM_bytes_unit
(
double
r
,
const
char
*
b
,
const
char
*
e
,
uintmax_t
rel
,
const
char
**
errtxt
);
const
char
*
VNUM_2bytes
(
const
char
*
p
,
uintmax_t
*
r
,
uintmax_t
rel
);
ssize_t
VNUM_uint
(
const
char
*
b
,
const
char
*
e
,
const
char
**
p
);
ssize_t
VNUM_hex
(
const
char
*
b
,
const
char
*
e
,
const
char
**
p
);
int64_t
SF_Parse_Integer
(
const
char
**
ipp
,
const
char
**
errtxt
);
double
SF_Parse_Decimal
(
const
char
**
ipp
,
int
strict
,
const
char
**
errtxt
);
...
...
lib/libvarnish/vnum.c
View file @
3f6a2517
...
...
@@ -33,6 +33,9 @@
#include "config.h"
#include <sys/types.h>
#include <limits.h>
#include <math.h>
#include <stdint.h>
#include <stdio.h>
...
...
@@ -353,6 +356,66 @@ VNUM_2bytes(const char *p, uintmax_t *r, uintmax_t rel)
return
(
NULL
);
}
/**********************************************************************/
static
const
uint8_t
hex_table
[]
=
{
0
,
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
127
,
127
,
127
,
127
,
127
,
127
,
127
,
10
,
11
,
12
,
13
,
14
,
15
,
127
,
127
,
127
,
127
,
127
,
127
,
127
,
127
,
127
,
127
,
127
,
127
,
127
,
127
,
127
,
127
,
127
,
127
,
127
,
127
,
127
,
127
,
127
,
127
,
127
,
127
,
10
,
11
,
12
,
13
,
14
,
15
};
static
ssize_t
vnum_uint
(
const
char
*
b
,
const
char
*
e
,
const
char
**
p
,
unsigned
base
)
{
ssize_t
u
;
unsigned
n
;
AN
(
b
);
AN
(
p
);
if
(
e
==
NULL
)
e
=
strchr
(
b
,
'\0'
);
u
=
0
;
if
(
!
vct_ishex
(
*
b
)
||
hex_table
[
*
b
-
'0'
]
>=
base
)
{
*
p
=
b
;
return
(
-
1
);
}
for
(;
b
<
e
&&
vct_ishex
(
*
b
)
&&
hex_table
[
*
b
-
'0'
]
<
base
;
b
++
)
{
if
(
u
>
(
SSIZE_MAX
/
base
))
{
u
=
-
2
;
break
;
}
u
*=
base
;
n
=
hex_table
[
*
b
-
'0'
];
if
(
u
>
(
SSIZE_MAX
-
n
))
{
u
=
-
2
;
break
;
}
u
+=
n
;
}
*
p
=
b
;
return
(
u
);
}
ssize_t
VNUM_uint
(
const
char
*
b
,
const
char
*
e
,
const
char
**
p
)
{
return
(
vnum_uint
(
b
,
e
,
p
,
10
));
}
ssize_t
VNUM_hex
(
const
char
*
b
,
const
char
*
e
,
const
char
**
p
)
{
return
(
vnum_uint
(
b
,
e
,
p
,
16
));
}
#ifdef NUM_C_TEST
/*
* Compile with:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment