]> icculus.org git repositories - btb/d2x.git/blob - misc/d_io.c
allow arbitrary resolutions to be specified on command line (d1x r1.2, r1.29, r1...
[btb/d2x.git] / misc / d_io.c
1 /* $Id: d_io.c,v 1.8 2004-05-19 02:20:34 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 #if defined(_WIN32) && !defined(_WIN32_WCE)
22 #include <windows.h>
23 #define lseek(a,b,c) _lseek(a,b,c)
24 #endif
25
26 #if 0
27 long filelength(int fd) {
28         long old_pos, size;
29
30         if ((old_pos = lseek(fd, 0, SEEK_CUR)) == -1 ||
31             (size = lseek(fd, 0, SEEK_END)) == -1 ||
32             (lseek(fd, old_pos, SEEK_SET)) == -1)
33                 return -1L;
34         return size;
35 }
36 #endif
37
38 long ffilelength(FILE *file)
39 {
40         long old_pos, size;
41
42         if ((old_pos = ftell(file)) == -1 ||
43             fseek(file, 0, SEEK_END) == -1 ||
44             (size = ftell(file)) == -1 ||
45             fseek(file, old_pos, SEEK_SET) == -1)
46                 return -1L;
47         return size;
48 }
49
50
51 unsigned long d_getdiskfree()
52 {
53 #ifdef __MSDOS__
54   return getdiskfree();
55 #else
56 #if 0//def __WINDOWS__
57         DWORD cbCluster = 0;
58         DWORD cClusters = 0;
59
60         GetDiskFreeSpace (
61                 NULL,
62                 &cbCluster,
63                 NULL,
64                 &cClusters,
65                 NULL);
66         
67         return cbCluster * cClusters;
68 #else
69   // FIXME:
70   return 999999999;
71 #endif
72 #endif
73 }
74
75 unsigned long GetDiskFree()
76 {
77  return d_getdiskfree();
78 }
79
80 // remove extension from filename, doesn't work with paths.
81 void removeext(const char *filename, char *out) {
82         char *p;
83         if ((p = strrchr(filename, '.'))) {
84                 strncpy(out, filename, p - filename);
85                 out[p - filename] = 0;
86         } else
87                 strcpy(out, filename);
88 }