1 /* Various file utility functions.
2    Copyright 2004 Brian R. Gaeke.
3 
4 This file is part of VMIPS.
5 
6 VMIPS is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; either version 2 of the License, or (at your
9 option) any later version.
10 
11 VMIPS is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14 for more details.
15 
16 You should have received a copy of the GNU General Public License along
17 with VMIPS; if not, write to the Free Software Foundation, Inc.,
18 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
19 
20 #include "fileutils.h"
21 #include <cassert>
22 
can_read_file(char * filename)23 bool can_read_file (char *filename) {
24 	assert (filename && "Null pointer passed to can_read_file ()");
25 	FILE *f = fopen (filename, "r");
26 	if (!f)
27 		return false;
28 	fclose (f);
29 	return true;
30 }
31 
get_file_size(FILE * fp)32 uint32 get_file_size (FILE *fp) {
33 	long orig_pos, here, there;
34 
35 	assert (fp && "Null pointer passed to get_file_size ()");
36 	orig_pos = ftell (fp);
37 	fseek (fp, 0, SEEK_SET);
38 	here = ftell (fp);
39 	fseek (fp, 0, SEEK_END);
40 	there = ftell (fp);
41 	fseek (fp, orig_pos, SEEK_SET);
42 	return there - here;
43 }
44 
45