libs/libc/obstack: implement ptr and int growing functions

The new API is defined by GNU and implemented in other LibCs, such as
Musl.

This also modifies API of obstack_blank_fast and obstack_1grow_fast.
These are defined as returning void and thus return value here is
incompatibility with other implementations.
This commit is contained in:
Karel Kočí
2024-09-15 23:22:19 +02:00
committed by Xiang Xiao
parent 4d35c60ba6
commit b04da1892e
2 changed files with 110 additions and 7 deletions
+34
View File
@@ -91,3 +91,37 @@ void obstack_1grow(FAR struct obstack *h, char data)
obstack_make_room(h, 1);
obstack_1grow_fast(h, data);
}
/****************************************************************************
* Name: obstack_ptr_grow
*
* Description:
* Grow object by one pointer.
*
* Input Parameters:
* h: pointer to the handle to allocated object to
* ptr: pointer to be added to the growing object
*
****************************************************************************/
void obstack_ptr_grow(FAR struct obstack *h, const void *ptr)
{
obstack_grow(h, &ptr, sizeof(void *));
}
/****************************************************************************
* Name: obstack_int_grow
*
* Description:
* Grow object by one integer.
*
* Input Parameters:
* h: pointer to the handle to allocated object to
* data: integer to be added to the growing object
*
****************************************************************************/
void obstack_int_grow(FAR struct obstack *h, int data)
{
obstack_grow(h, &data, sizeof(int));
}