1 // Emacs style mode select -*- C++ -*-
2 //-----------------------------------------------------------------------------
4 // Copyright(C) 1993-1996 Id Software, Inc.
5 // Copyright(C) 2008 Simon Howard
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License
9 // as published by the Free Software Foundation; either version 2
10 // of the License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
25 //-----------------------------------------------------------------------------
39 extern wad_file_class_t stdc_wad_file
;
41 static wad_file_t
*W_StdC_OpenFile(char *path
)
43 stdc_wad_file_t
*result
;
46 fstream
= fopen(path
, "rb");
53 // Create a new stdc_wad_file_t to hold the file handle.
55 result
= Z_Malloc(sizeof(stdc_wad_file_t
), PU_STATIC
, 0);
56 result
->wad
.file_class
= &stdc_wad_file
;
57 result
->wad
.mapped
= NULL
;
58 result
->wad
.length
= M_FileLength(fstream
);
59 result
->fstream
= fstream
;
64 static void W_StdC_CloseFile(wad_file_t
*wad
)
66 stdc_wad_file_t
*stdc_wad
;
68 stdc_wad
= (stdc_wad_file_t
*) wad
;
70 fclose(stdc_wad
->fstream
);
74 // Read data from the specified position in the file into the
75 // provided buffer. Returns the number of bytes read.
77 size_t W_StdC_Read(wad_file_t
*wad
, unsigned int offset
,
78 void *buffer
, size_t buffer_len
)
80 stdc_wad_file_t
*stdc_wad
;
83 stdc_wad
= (stdc_wad_file_t
*) wad
;
85 // Jump to the specified position in the file.
87 fseek(stdc_wad
->fstream
, offset
, SEEK_SET
);
89 // Read into the buffer.
91 result
= fread(buffer
, 1, buffer_len
, stdc_wad
->fstream
);
97 wad_file_class_t stdc_wad_file
=