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