Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
asn1c
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
asn1c
Commits
e3204e7d
Commit
e3204e7d
authored
Aug 23, 2017
by
Lev Walkin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
abuf_vprintf
parent
f75b8742
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
8 deletions
+43
-8
libasn1common/asn1_buffer.c
libasn1common/asn1_buffer.c
+38
-7
libasn1common/asn1_buffer.h
libasn1common/asn1_buffer.h
+5
-1
No files found.
libasn1common/asn1_buffer.c
View file @
e3204e7d
...
...
@@ -53,32 +53,48 @@ abuf_clear(abuf *ab) {
}
static
void
abuf_resize_by
(
abuf
*
ab
,
size_t
add_bytes
)
{
abuf_resize_by
(
abuf
*
ab
,
size_t
size
)
{
union
{
const
char
*
c_buf
;
char
*
nc_buf
;
}
const_cast
;
const_cast
.
c_buf
=
ab
->
buffer
;
assert
(
ab
->
buffer
[
ab
->
length
]
==
'\0'
);
assert
(
!
ab
->
buffer
||
ab
->
buffer
[
ab
->
length
]
==
'\0'
);
size_t
new_size
=
ab
->
length
+
add_bytes
;
size_t
new_size
=
ab
->
length
+
size
;
char
*
p
=
realloc
(
const_cast
.
nc_buf
,
new_size
);
assert
(
p
);
if
(
!
ab
->
buffer
)
{
assert
(
ab
->
length
==
0
);
*
p
=
'\0'
;
}
ab
->
buffer
=
p
;
assert
(
ab
->
buffer
[
ab
->
length
]
==
'\0'
);
ab
->
size
=
new_size
;
}
void
abuf_add_bytes
(
abuf
*
ab
,
const
char
*
str
,
size_t
size
)
{
abuf_resize_by
(
ab
,
size
+
1
);
union
{
const
char
*
c_buf
;
char
*
nc_buf
;
}
const_cast
;
const_cast
.
c_buf
=
ab
->
buffer
;
memcpy
(
&
const_cast
.
nc_buf
[
ab
->
length
],
str
,
size
);
ab
->
length
+=
size
;
const_cast
.
nc_buf
[
ab
->
length
]
=
'\0'
;
}
void
abuf_str
(
abuf
*
ab
,
const
char
*
str
)
{
abuf_
printf
(
ab
,
"%s"
,
str
);
abuf_
add_bytes
(
ab
,
str
,
strlen
(
str
)
);
}
void
abuf_buf
(
abuf
*
ab
,
const
abuf
*
buf
)
{
abuf_
printf
(
ab
,
"%s"
,
buf
->
buffer
);
abuf_
add_bytes
(
ab
,
buf
->
buffer
,
buf
->
length
);
}
void
abuf_printf
(
abuf
*
ab
,
const
char
*
fmt
,
...)
{
int
abuf_printf
(
abuf
*
ab
,
const
char
*
fmt
,
...)
{
va_list
ap
;
for
(;;)
{
...
...
@@ -95,10 +111,25 @@ void abuf_printf(abuf *ab, const char *fmt, ...) {
if
((
size_t
)
ret
<
ab
->
size
-
ab
->
length
)
{
ab
->
length
+=
ret
;
assert
(
ab
->
buffer
[
ab
->
length
]
==
'\0'
);
break
;
return
ret
;
}
const_cast
.
nc_buf
[
ab
->
length
]
=
'\0'
;
/* Restore order */
abuf_resize_by
(
ab
,
ret
+
1
);
}
}
int
abuf_vprintf
(
abuf
*
ab
,
const
char
*
fmt
,
va_list
ap
)
{
int
ret
;
char
*
str
=
0
;
ret
=
vasprintf
(
&
str
,
fmt
,
ap
);
assert
(
ret
>=
0
);
assert
(
str
!=
NULL
);
abuf_add_bytes
(
ab
,
str
,
ret
);
free
(
str
);
return
ret
;
}
libasn1common/asn1_buffer.h
View file @
e3204e7d
#ifndef ASN1_BUFFER_H
#define ASN1_BUFFER_H
#include <stdarg.h>
/*
* Your typical dynamic character string buffer.
*/
...
...
@@ -26,7 +28,9 @@ void abuf_clear(abuf *);
*/
void
abuf_str
(
abuf
*
,
const
char
*
str
);
void
abuf_buf
(
abuf
*
,
const
abuf
*
);
void
abuf_printf
(
abuf
*
,
const
char
*
fmt
,
...)
void
abuf_add_bytes
(
abuf
*
,
const
char
*
,
size_t
);
int
abuf_printf
(
abuf
*
,
const
char
*
fmt
,
...)
__attribute__
((
format
(
printf
,
2
,
3
)));
int
abuf_vprintf
(
abuf
*
,
const
char
*
fmt
,
va_list
);
#endif
/* ASN1_BUFFER_H */
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