Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
f5468493
Commit
f5468493
authored
Nov 27, 2011
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fifo_buffer: add function fifo_buffer_realloc()
For growing FIFO buffers.
parent
a85af593
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
2 deletions
+47
-2
fifo_buffer.c
src/fifo_buffer.c
+34
-1
fifo_buffer.h
src/fifo_buffer.h
+13
-1
No files found.
src/fifo_buffer.c
View file @
f5468493
/*
* Copyright (C) 2003-201
0
The Music Player Daemon Project
* Copyright (C) 2003-201
1
The Music Player Daemon Project
* http://www.musicpd.org
*
* Redistribution and use in source and binary forms, with or without
...
...
@@ -58,6 +58,39 @@ fifo_buffer_new(size_t size)
return
buffer
;
}
static
void
fifo_buffer_move
(
struct
fifo_buffer
*
buffer
);
struct
fifo_buffer
*
fifo_buffer_realloc
(
struct
fifo_buffer
*
buffer
,
size_t
new_size
)
{
if
(
buffer
==
NULL
)
return
new_size
>
0
?
fifo_buffer_new
(
new_size
)
:
NULL
;
/* existing data must fit in new size */
assert
(
new_size
>=
buffer
->
end
-
buffer
->
start
);
if
(
new_size
==
0
)
{
fifo_buffer_free
(
buffer
);
return
NULL
;
}
/* compress the buffer when we're shrinking and the tail of
the buffer would exceed the new size */
if
(
buffer
->
end
>
new_size
)
fifo_buffer_move
(
buffer
);
/* existing data must fit in new size: second check */
assert
(
buffer
->
end
<=
new_size
);
buffer
=
g_realloc
(
buffer
,
sizeof
(
*
buffer
)
-
sizeof
(
buffer
->
buffer
)
+
new_size
);
buffer
->
size
=
new_size
;
return
buffer
;
}
void
fifo_buffer_free
(
struct
fifo_buffer
*
buffer
)
{
...
...
src/fifo_buffer.h
View file @
f5468493
/*
* Copyright (C) 2003-201
0
The Music Player Daemon Project
* Copyright (C) 2003-201
1
The Music Player Daemon Project
* http://www.musicpd.org
*
* Redistribution and use in source and binary forms, with or without
...
...
@@ -57,6 +57,18 @@ struct fifo_buffer *
fifo_buffer_new
(
size_t
size
);
/**
* Change the capacity of the #fifo_buffer, while preserving existing
* data.
*
* @param buffer the old buffer, may be NULL
* @param new_size the requested new size of the #fifo_buffer; must
* not be smaller than the data which is stored in the old buffer
* @return the new buffer, may be NULL if the requested new size is 0
*/
struct
fifo_buffer
*
fifo_buffer_realloc
(
struct
fifo_buffer
*
buffer
,
size_t
new_size
);
/**
* Frees the resources consumed by this #fifo_buffer object.
*/
void
...
...
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