diff options
Diffstat (limited to 'firmware/buflib.c')
-rw-r--r-- | firmware/buflib.c | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/firmware/buflib.c b/firmware/buflib.c index 2ceb7fcb16..1aa7404ece 100644 --- a/firmware/buflib.c +++ b/firmware/buflib.c | |||
@@ -647,9 +647,9 @@ free_space_at_end(struct buflib_context* ctx) | |||
647 | return 0; | 647 | return 0; |
648 | } | 648 | } |
649 | 649 | ||
650 | /* Return the maximum allocatable memory in bytes */ | 650 | /* Return the maximum allocatable contiguous memory in bytes */ |
651 | size_t | 651 | size_t |
652 | buflib_available(struct buflib_context* ctx) | 652 | buflib_allocatable(struct buflib_context* ctx) |
653 | { | 653 | { |
654 | union buflib_data *this; | 654 | union buflib_data *this; |
655 | size_t free_space = 0, max_free_space = 0; | 655 | size_t free_space = 0, max_free_space = 0; |
@@ -687,6 +687,29 @@ buflib_available(struct buflib_context* ctx) | |||
687 | return 0; | 687 | return 0; |
688 | } | 688 | } |
689 | 689 | ||
690 | /* Return the amount of unallocated memory in bytes (even if not contiguous) */ | ||
691 | size_t | ||
692 | buflib_available(struct buflib_context* ctx) | ||
693 | { | ||
694 | union buflib_data *this; | ||
695 | size_t free_space = 0; | ||
696 | |||
697 | /* now look if there's free in holes */ | ||
698 | for(this = find_first_free(ctx); this < ctx->alloc_end; this += abs(this->val)) | ||
699 | { | ||
700 | if (this->val < 0) | ||
701 | { | ||
702 | free_space += -this->val; | ||
703 | continue; | ||
704 | } | ||
705 | } | ||
706 | |||
707 | free_space *= sizeof(union buflib_data); /* make it bytes */ | ||
708 | free_space += free_space_at_end(ctx); | ||
709 | |||
710 | return free_space; | ||
711 | } | ||
712 | |||
690 | /* | 713 | /* |
691 | * Allocate all available (as returned by buflib_available()) memory and return | 714 | * Allocate all available (as returned by buflib_available()) memory and return |
692 | * a handle to it | 715 | * a handle to it |