]> icculus.org git repositories - btb/d2x.git/blob - misc/d_io.c
oops, can't get rid of main INCLUDE yet...
[btb/d2x.git] / misc / d_io.c
1 /* $Id: d_io.c,v 1.5 2003-02-18 20:35:35 btb Exp $ */
2 /*
3  * some misc. file/disk routines
4  * Arne de Bruijn, 1998
5  */
6
7 #ifdef HAVE_CONFIG_H
8 #include <conf.h>
9 #endif
10
11 #include <stdio.h>
12 #include <string.h>
13 #include "d_io.h"
14 #ifdef __DJGPP__
15 #include "dos_disk.h"
16 #endif
17 //added 05/17/99 Matt Mueller
18 #include "u_mem.h"
19 //end addition -MM
20
21 #ifdef __WINDOWS__
22 #include <windows.h>
23 #define lseek(a,b,c) _lseek(a,b,c)
24 #endif
25
26 long filelength(int fd) {
27         long old_pos, size;
28
29         if ((old_pos = lseek(fd, 0, SEEK_CUR)) == -1 ||
30             (size = lseek(fd, 0, SEEK_END)) == -1 ||
31             (lseek(fd, old_pos, SEEK_SET)) == -1)
32                 return -1L;
33         return size;
34 }
35
36 long ffilelength(FILE *fh)
37 {
38  return filelength(fileno(fh));
39 }
40
41
42 unsigned long d_getdiskfree()
43 {
44 #ifdef __MSDOS__
45   return getdiskfree();
46 #else
47 #ifdef __WINDOWS__
48         ULONG cbCluster = 0;
49         ULONG cClusters = 0;
50
51         GetDiskFreeSpace (
52                 NULL,
53                 (int *) &cbCluster,
54                 NULL,
55                 (int *) &cClusters,
56                 NULL);
57         
58         return cbCluster * cClusters;
59 #else
60   // FIXME:
61   return 999999999;
62 #endif
63 #endif
64 }
65
66 unsigned long GetDiskFree()
67 {
68  return d_getdiskfree();
69 }
70
71 // remove extension from filename, doesn't work with paths.
72 void removeext(const char *filename, char *out) {
73         char *p;
74         if ((p = strrchr(filename, '.'))) {
75                 strncpy(out, filename, p - filename);
76                 out[p - filename] = 0;
77         } else
78                 strcpy(out, filename);
79 }