Wing Commander II
Reconstructed Win32 source (1996)
Loading...
Searching...
No Matches
datafile.c
Go to the documentation of this file.
1/*
2 * Data file I/O.
3 *
4 * Retail object 0x45A010-0x45A2BF (link order; see docs/ORDER.md).
5 */
6/* This unit owns storage declared in globals.h as statics. */
7#define DATAFILE_C
8#include "game.h"
9
10short g_nPacketError = 0; /* 0x0049ca90 */
11
12/* Function start: 0x45A010 */
13short OpenDataFileOrDie(const char *path)
14{
15 short fd = (short)_open(path, 0x8002);
16
17 g_nPacketError = (short)errno;
18 return fd;
19}
20
21/* Function start: 0x45A04A */
22void CloseDataFile(unsigned short fd)
23{
24 g_nPacketError = (short)_close(fd & 0xffff);
25}
26
27/* Function start: 0x45A06C */
28short WriteDataFileAtOffset(unsigned short fd, int offset,
29 unsigned int length, const void *data)
30{
32 if (offset != -1 && _lseek(fd, offset, SEEK_SET) == -1) {
33 sprintf(g_szWriteDataFileError, "!lseek %d\n", offset);
34 g_nPacketError = (short)errno;
35 return 0;
36 }
37 if (_write(fd, data, length) == -1) {
38 sprintf(g_szWriteDataFileError, "!write %d\n", offset);
39 g_nPacketError = (short)errno;
40 return 0;
41 }
42 return 1;
43}
44
45/* Function start: 0x45A12D */
46short CreateDataFile(const char *path)
47{
48 unsigned short fd;
49
50 fd = (unsigned short)_open(path, 0x8101, 0x180);
51 if ((unsigned int)fd == (unsigned int)-1) {
52 sprintf(g_szCreateBlockFileError, "!_open '%s'\n", path);
53 g_nPacketError = (short)errno;
54 return 0;
55 }
56 return (short)fd;
57}
58
59/* Function start: 0x45A19B */
60int ReadDataFileAtOffset(unsigned short fd, int offset,
61 unsigned int length, void *data)
62{
64 if (offset != -1 && _lseek(fd, offset, SEEK_SET) == -1) {
65 sprintf(g_1_szReadDataFileFault, "!lseek %d\n", offset);
66 g_nPacketError = (short)errno;
67 return 0;
68 }
69 if (_read(fd, data, length) == -1) {
70 sprintf(g_1_szReadDataFileFault, "!lseek %d\n", offset);
71 g_nPacketError = (short)errno;
72 return 0;
73 }
74 return 1;
75}
76
77/* Function start: 0x45A259 */
78int SeekDataFile(unsigned short fd, int offset,
79 unsigned int origin)
80{
81 int position;
82
83 position = _lseek(fd, offset, origin & 0xffff);
84 if (position == -1) {
85 sprintf(g_szSeekDataFileFailure, "!lseek %d\n", offset);
86 g_nPacketError = (short)errno;
87 }
88 return position;
89}
int SeekDataFile(unsigned short fd, int offset, unsigned int origin)
Definition datafile.c:78
short WriteDataFileAtOffset(unsigned short fd, int offset, unsigned int length, const void *data)
Definition datafile.c:28
int ReadDataFileAtOffset(unsigned short fd, int offset, unsigned int length, void *data)
Definition datafile.c:60
short OpenDataFileOrDie(const char *path)
Definition datafile.c:13
short CreateDataFile(const char *path)
Definition datafile.c:46
void CloseDataFile(unsigned short fd)
Definition datafile.c:22
Shared Win32 declarations, types and library interfaces.
DATAFILE_STATIC char g_szWriteDataFileError[0x40]
Definition globals.h:921
DATAFILE_STATIC char g_szSeekDataFileFailure[0x48]
Definition globals.h:922
DATAFILE_STATIC char g_1_szReadDataFileFault[0x40]
Definition globals.h:919
DATAFILE_STATIC char g_szCreateBlockFileError[0x40]
Definition globals.h:920
short g_nPacketError
Definition datafile.c:10