ulib uprintf to pipe not termdev, ulib Add stringbuffer and linearlist, tb Capture subshell output
This commit is contained in:
@ -118,3 +118,33 @@ void ufree(void *ptr_) {
|
||||
}
|
||||
}
|
||||
|
||||
void *urealloc(void *ptr, size_t newsize) {
|
||||
void *new;
|
||||
|
||||
UmBlock *block = (UmBlock *)(ptr - sizeof(UmBlock));
|
||||
if (block->magic != BLOCK_MAGIC || block->data != ptr) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (!ptr) {
|
||||
new = umalloc(newsize);
|
||||
if (!new) {
|
||||
goto err;
|
||||
}
|
||||
} else {
|
||||
if (block->size < newsize) {
|
||||
new = umalloc(newsize);
|
||||
if (!new) {
|
||||
goto err;
|
||||
}
|
||||
string_memcpy(new, ptr, block->size);
|
||||
ufree(ptr);
|
||||
} else {
|
||||
new = ptr;
|
||||
}
|
||||
}
|
||||
return new;
|
||||
|
||||
err:
|
||||
return NULL;
|
||||
}
|
||||
|
@ -6,5 +6,6 @@
|
||||
|
||||
void *umalloc(size_t size);
|
||||
void ufree(void *ptr_);
|
||||
void *urealloc(void *ptr, size_t newsize);
|
||||
|
||||
#endif // ULIB_UMALLOC_UMALLOC_H_
|
||||
|
Reference in New Issue
Block a user