Add weapon cycling bindings for mouse and joystick buttons. Add weapon cycling bindi...
[chocolate-doom.git] / src / w_file_stdc.c
blob04450e8b90c49bbd6b1b6d03ebc950dbff56ab73
1 // Emacs style mode select -*- C++ -*-
2 //-----------------------------------------------------------------------------
3 //
4 // Copyright(C) 1993-1996 Id Software, Inc.
5 // Copyright(C) 2008 Simon Howard
6 //
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
20 // 02111-1307, USA.
22 // DESCRIPTION:
23 // WAD I/O functions.
25 //-----------------------------------------------------------------------------
27 #include <stdio.h>
29 #include "m_misc.h"
30 #include "w_file.h"
31 #include "z_zone.h"
33 typedef struct
35 wad_file_t wad;
36 FILE *fstream;
37 } stdc_wad_file_t;
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;
44 FILE *fstream;
46 fstream = fopen(path, "rb");
48 if (fstream == NULL)
50 return NULL;
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;
61 return &result->wad;
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);
71 Z_Free(stdc_wad);
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;
81 size_t result;
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);
93 return result;
97 wad_file_class_t stdc_wad_file =
99 W_StdC_OpenFile,
100 W_StdC_CloseFile,
101 W_StdC_Read,