summaryrefslogtreecommitdiff
path: root/plugins/gme/game-music-emu-0.6pre/gme/blargg_common.cpp
blob: 91d2c8825966b40863aab6dab4653deb1ddfaa1c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Game_Music_Emu 0.6-pre. http://www.slack.net/~ant/

#include "blargg_common.h"

/* Copyright (C) 2008-2009 Shay Green. This module is free software; you
can redistribute it and/or modify it under the terms of the GNU Lesser
General Public License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version. This
module is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
details. You should have received a copy of the GNU Lesser General Public
License along with this module; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */

#include "blargg_source.h"

BLARGG_NAMESPACE_BEGIN

// defined here to avoid need for blargg_errors.cpp in simple programs
blargg_err_def_t blargg_err_memory = BLARGG_ERR_MEMORY;

void blargg_vector_::init()
{
	begin_ = NULL;
	size_  = 0;
}

void blargg_vector_::clear()
{
	void* p = begin_;
	begin_  = NULL;
	size_   = 0;
	free( p );
}

blargg_err_t blargg_vector_::resize_( size_t n, size_t elem_size )
{
	if ( n != size_ )
	{
		if ( n == 0 )
		{
			// Simpler to handle explicitly. Realloc will handle a size of 0,
			// but then we have to avoid raising an error for a NULL return.
			clear();
		}
		else
		{
			void* p = realloc( begin_, n * elem_size );
			CHECK_ALLOC( p );
			begin_ = p;
			size_  = n;
		}
	}
	return blargg_ok;
}

BLARGG_NAMESPACE_END