1 /*
2  *  Copyright (c) 2010 The WebM project authors. All Rights Reserved.
3  *
4  *  Use of this source code is governed by a BSD-style license
5  *  that can be found in the LICENSE file in the root of the source
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10 
11 
12 /* This code is in the public domain.
13 ** Version: 1.1  Author: Walt Karas
14 */
15 
16 #include "hmm_intrnl.h"
17 
U(grow_chunk)18 void U(grow_chunk)(U(descriptor) *desc, void *end, U(size_bau) n_baus) {
19 #undef HEAD_PTR
20 #define HEAD_PTR ((head_record *) end)
21 
22   end = BAUS_BACKWARD(end, DUMMY_END_BLOCK_BAUS);
23 
24 #ifdef HMM_AUDIT_FAIL
25 
26   if (HEAD_PTR->block_size != 0)
27     /* Chunk does not have valid dummy end block. */
28     HMM_AUDIT_FAIL
29 
30 #endif
31 
32     /* Create a new block that absorbs the old dummy end block. */
33     HEAD_PTR->block_size = n_baus;
34 
35   /* Set up the new dummy end block. */
36   {
37     head_record *dummy = (head_record *) BAUS_FORWARD(end, n_baus);
38     dummy->previous_block_size = n_baus;
39     dummy->block_size = 0;
40   }
41 
42   /* Simply free the new block, allowing it to coalesce with any
43   ** free block at that was the last block in the chunk prior to
44   ** growth.
45   */
46   U(free)(desc, HEAD_TO_PTR_REC(end));
47 
48 #undef HEAD_PTR
49 }
50