Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/quicknes/fex/blargg_common.cpp
2 views
1
// File_Extractor 1.0.0. http://www.slack.net/~ant/
2
3
#include "blargg_common.h"
4
5
/* Copyright (C) 2008-2009 Shay Green. This module is free software; you
6
can redistribute it and/or modify it under the terms of the GNU Lesser
7
General Public License as published by the Free Software Foundation; either
8
version 2.1 of the License, or (at your option) any later version. This
9
module is distributed in the hope that it will be useful, but WITHOUT ANY
10
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12
details. You should have received a copy of the GNU Lesser General Public
13
License along with this module; if not, write to the Free Software Foundation,
14
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */
15
16
#include "blargg_source.h"
17
18
void blargg_vector_::init()
19
{
20
begin_ = NULL;
21
size_ = 0;
22
}
23
24
void blargg_vector_::clear()
25
{
26
void* p = begin_;
27
begin_ = NULL;
28
size_ = 0;
29
free( p );
30
}
31
32
blargg_err_t blargg_vector_::resize_( size_t n, size_t elem_size )
33
{
34
if ( n != size_ )
35
{
36
if ( n == 0 )
37
{
38
// Simpler to handle explicitly. Realloc will handle a size of 0,
39
// but then we have to avoid raising an error for a NULL return.
40
clear();
41
}
42
else
43
{
44
void* p = realloc( begin_, n * elem_size );
45
CHECK_ALLOC( p );
46
begin_ = p;
47
size_ = n;
48
}
49
}
50
return blargg_ok;
51
}
52
53