This commit was generated by cvs2svn to compensate for changes in r5,
[btb/d2x.git] / misc / d_io.c
1 // some misc. file/disk routines
2 // Arne de Bruijn, 1998
3 #include <conf.h>
4 #include <stdio.h>
5 #include <string.h>
6 #include "d_io.h"
7 #ifdef __ENV_DJGPP__
8 #include "dos_disk.h"
9 #endif
10 //added 05/17/99 Matt Mueller
11 #include "u_mem.h"
12 //end addition -MM
13
14 #ifdef __ENV_WINDOWS__
15 #include <windows.h>
16 #define lseek(a,b,c) _lseek(a,b,c)
17 #endif
18
19 long filelength(int fd) {
20         long old_pos, size;
21
22         if ((old_pos = lseek(fd, 0, SEEK_CUR)) == -1 ||
23             (size = lseek(fd, 0, SEEK_END)) == -1 ||
24             (lseek(fd, old_pos, SEEK_SET)) == -1)
25                 return -1L;
26         return size;
27 }
28
29 long ffilelength(FILE *fh)
30 {
31  return filelength(fileno(fh));
32 }
33
34
35 unsigned long d_getdiskfree()
36 {
37 #ifdef __ENV_MSDOS__
38   return getdiskfree();
39 #else
40 #ifdef __ENV_WINDOWS__
41         ULONG cbCluster = 0;
42         ULONG cClusters = 0;
43
44         GetDiskFreeSpace (
45                 NULL,
46                 (int *) &cbCluster,
47                 NULL,
48                 (int *) &cClusters,
49                 NULL);
50         
51         return cbCluster * cClusters;
52 #else
53   // FIXME:
54   return 999999999;
55 #endif
56 #endif
57 }
58
59 unsigned long GetDiskFree()
60 {
61  return d_getdiskfree();
62 }
63
64 // remove extension from filename, doesn't work with paths.
65 void removeext(const char *filename, char *out) {
66         char *p;
67         if ((p = strrchr(filename, '.'))) {
68                 strncpy(out, filename, p - filename);
69                 out[p - filename] = 0;
70         } else
71                 strcpy(out, filename);
72 }