aboutsummaryrefslogtreecommitdiff
path: root/sword2/tony_gsdk.cpp
blob: 118a0c90e7721fdd89470fb77b30dc18b62956e7 (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
59
60
61
/* Copyright (C) 1994-2003 Revolution Software Ltd
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * $Header$
 */

// general odds and ends

#include "stdafx.h"
#include "bs2/driver/driver96.h"
#include "bs2/debug.h"
#include "bs2/memory.h"
#include "bs2/tony_gsdk.h"
#include "bs2/sword2.h"

namespace Sword2 {

uint32 Read_file(const char *name, mem **membloc, uint32 uid) {
	// read the file in and place into an allocated MEM_float block

	// FIXME: As far as I can see, this function is only used in debug
	// builds, so maybe it should be removed completely?

	File fh;
	uint32 size;

	if (!fh.open(name)) {
		debug(5, "Read_file cannot open %s", name);
		return 0;
	}

	size = fh.size();

	// reserve enough floating memory for the file
	*membloc = memory.allocMemory(size, MEM_float, uid);
	
	if (fh.read((*membloc)->ad, size) != size) {
		debug(5, "Read_file read fail %d", name);
		return 0;
	}

	fh.close();

	//ok, done it - return bytes read
	return size;
}

} // End of namespace Sword2