]> icculus.org git repositories - btb/d2x.git/blob - misc/fileutil.c
Removed duplicate files, and unified input headers.
[btb/d2x.git] / misc / fileutil.c
1 /*
2 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
3 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
4 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
5 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
6 IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
7 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
8 FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
9 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
10 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.  
11 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
12 */
13  
14 #include <stdio.h>
15 #include <stdlib.h>
16
17 #include "pstypes.h"
18 #include "fileutil.h"
19 #include "cfile.h"
20 #include "fix.h"
21 #include "byteswap.h"
22
23 int filelength(int fd)
24 {
25         int cur_pos, end_pos;
26         
27         cur_pos = lseek(fd, 0, SEEK_CUR);
28         lseek(fd, 0, SEEK_END);
29         end_pos = lseek(fd, 0, SEEK_CUR);
30         lseek(fd, cur_pos, SEEK_SET);
31         return end_pos;
32 }
33 #if 0
34 byte read_byte(CFILE *fp)
35 {
36         byte b;
37         
38         cfread(&b, sizeof(byte), 1, fp);
39         return b;
40 }
41
42 short read_short(CFILE *fp)
43 {
44         short s;
45         
46         cfread(&s, sizeof(short), 1, fp);
47         return (s);
48 }
49
50 short read_short_swap(CFILE *fp)
51 {
52         short s;
53         
54         cfread(&s, sizeof(short), 1, fp);
55         return swapshort(s);
56 }
57
58 int read_int(CFILE *fp)
59 {
60         uint i;
61         
62         cfread(&i, sizeof(uint), 1, fp);
63         return i;
64 }
65
66 int read_int_swap(CFILE *fp)
67 {
68         uint i;
69         
70         cfread(&i, sizeof(uint), 1, fp);
71         return swapint(i);
72 }
73
74 fix read_fix(CFILE *fp)
75 {
76         fix f;
77         
78         cfread(&f, sizeof(fix), 1, fp);
79         return f;
80 }
81
82 fix read_fix_swap(CFILE *fp)
83 {
84         fix f;
85         
86         cfread(&f, sizeof(fix), 1, fp);
87         return (fix)swapint((uint)f);
88 }
89
90 int write_byte(FILE *fp, byte b)
91 {
92         return (fwrite(&b, sizeof(byte), 1, fp));
93 }
94
95 int write_short(FILE *fp, short s)
96 {
97         return (fwrite(&s, sizeof(short), 1, fp));
98 }
99
100 int write_short_swap(FILE *fp, short s)
101 {
102         s = swapshort(s);
103         return (fwrite(&s, sizeof(short), 1, fp));
104 }
105
106 int write_int(FILE *fp, int i)
107 {
108         return (fwrite(&i,sizeof(int), 1, fp));
109 }
110
111 int write_int_swap(FILE *fp, int i)
112 {
113         i = swapint(i);
114         return (fwrite(&i,sizeof(int), 1, fp));
115 }
116
117 int write_fix(FILE *fp, fix f)
118 {
119         return (fwrite(&f, sizeof(fix), 1, fp));
120 }
121
122 int write_fix_swap(FILE *fp, fix f)
123 {
124         f = (fix)swapint((int)f);
125         return (fwrite(&f, sizeof(fix), 1, fp));
126 }
127
128 #endif