annotate compat.c @ 580:d7c338ac926a

Sweeping changes to the compatibility module, moved all socket code out of the DLL and into macros in compat.h, socksprintf() is now gone, replaced by the sockprint() macro and the vargs() function. This allows the DLL and application to be compiled with different compilers (and C libraries).
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Fri, 20 May 2005 03:32:25 +0000
parents 1a210e2f214b
children f09977bc9b5c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
1 /* $Id$ */
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
2
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
3 #include "compat.h"
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
4 #if defined(__OS2__) || defined(__WIN32__)
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
5 #include <share.h>
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
6 #endif
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
7
433
f225f16bebbd Compile fixes for MacOS X.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 176
diff changeset
8 #if defined(__UNIX__) || defined(__MAC__)
f225f16bebbd Compile fixes for MacOS X.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 176
diff changeset
9 #if defined(__FreeBSD__) || defined(__MAC__)
36
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
10 #include <sys/param.h>
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
11 #include <sys/ucred.h>
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
12 #include <sys/mount.h>
42
eb003f77538c Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 37
diff changeset
13 #elif defined(__sun__)
eb003f77538c Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 37
diff changeset
14 #include <sys/mnttab.h>
eb003f77538c Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 37
diff changeset
15 #include <sys/param.h>
eb003f77538c Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 37
diff changeset
16 #include <sys/mount.h>
eb003f77538c Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 37
diff changeset
17 #include <sys/statfs.h>
36
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
18 #else
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
19 #include <mntent.h>
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
20 #include <sys/vfs.h>
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
21 #endif
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
22 #endif
47
997e9ed670ef Fixes for box alignment problem on OS/2, crash in dw_bitmap_new() on unix
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 42
diff changeset
23 #include <time.h>
36
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
24
441
b559c06a76c2 Implemented more functionality on MacOS and include the platform define
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 433
diff changeset
25 #if defined(__UNIX__) || defined(__MAC__)
37
360bc6a5f1c9 Sync with latest Dynamic Windows code.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 36
diff changeset
26 void msleep(long period)
360bc6a5f1c9 Sync with latest Dynamic Windows code.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 36
diff changeset
27 {
360bc6a5f1c9 Sync with latest Dynamic Windows code.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 36
diff changeset
28 #ifdef __sun__
360bc6a5f1c9 Sync with latest Dynamic Windows code.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 36
diff changeset
29 /* usleep() isn't threadsafe on Solaris */
360bc6a5f1c9 Sync with latest Dynamic Windows code.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 36
diff changeset
30 struct timespec req;
360bc6a5f1c9 Sync with latest Dynamic Windows code.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 36
diff changeset
31
360bc6a5f1c9 Sync with latest Dynamic Windows code.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 36
diff changeset
32 req.tv_sec = 0;
42
eb003f77538c Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 37
diff changeset
33 req.tv_nsec = period * 10000000;
37
360bc6a5f1c9 Sync with latest Dynamic Windows code.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 36
diff changeset
34
360bc6a5f1c9 Sync with latest Dynamic Windows code.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 36
diff changeset
35 nanosleep(&req, NULL);
360bc6a5f1c9 Sync with latest Dynamic Windows code.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 36
diff changeset
36 #else
360bc6a5f1c9 Sync with latest Dynamic Windows code.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 36
diff changeset
37 usleep(period * 1000);
360bc6a5f1c9 Sync with latest Dynamic Windows code.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 36
diff changeset
38 #endif
360bc6a5f1c9 Sync with latest Dynamic Windows code.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 36
diff changeset
39 }
360bc6a5f1c9 Sync with latest Dynamic Windows code.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 36
diff changeset
40 #endif
360bc6a5f1c9 Sync with latest Dynamic Windows code.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 36
diff changeset
41
176
4e3407df0e38 Specify calling convention for compat functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 172
diff changeset
42 int API makedir(char *path)
3
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
43 {
172
0fc45e386376 Get Dynamic Windows building with Watcom.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 101
diff changeset
44 #if defined(__IBMC__) || defined(__WATCOMC__) || (defined(__WIN32__) && !defined(__CYGWIN32__))
3
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
45 return mkdir(path);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
46 #else
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
47 return mkdir(path,S_IRWXU);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
48 #endif
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
49 }
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
50
580
d7c338ac926a Sweeping changes to the compatibility module, moved all socket code out
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 557
diff changeset
51 char * API vargs(char *buf, int len, char *format, ...)
3
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
52 {
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
53 va_list args;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
54
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
55 va_start(args, format);
580
d7c338ac926a Sweeping changes to the compatibility module, moved all socket code out
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 557
diff changeset
56 #ifdef HAVE_VSNPRINTF
d7c338ac926a Sweeping changes to the compatibility module, moved all socket code out
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 557
diff changeset
57 vsnprintf(buf, len, format, args);
d7c338ac926a Sweeping changes to the compatibility module, moved all socket code out
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 557
diff changeset
58 #else
d7c338ac926a Sweeping changes to the compatibility module, moved all socket code out
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 557
diff changeset
59 len = len;
d7c338ac926a Sweeping changes to the compatibility module, moved all socket code out
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 557
diff changeset
60 vsprintf(buf, format, args);
d7c338ac926a Sweeping changes to the compatibility module, moved all socket code out
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 557
diff changeset
61 #endif
3
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
62 va_end(args);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
63
580
d7c338ac926a Sweeping changes to the compatibility module, moved all socket code out
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 557
diff changeset
64 return buf;
3
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
65 }
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
66
176
4e3407df0e38 Specify calling convention for compat functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 172
diff changeset
67 long double API drivefree(int drive)
3
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
68 {
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
69 #if defined(__EMX__) || defined(__OS2__)
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
70 ULONG aulFSInfoBuf[40] = {0};
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
71 APIRET rc = NO_ERROR;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
72
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
73 DosError(FERR_DISABLEHARDERR);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
74 rc = DosQueryFSInfo(drive,
35
432c39a4ff86 New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 22
diff changeset
75 FSIL_ALLOC,
432c39a4ff86 New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 22
diff changeset
76 (PVOID)aulFSInfoBuf,
432c39a4ff86 New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 22
diff changeset
77 sizeof(aulFSInfoBuf));
3
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
78
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
79 DosError(FERR_ENABLEHARDERR);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
80 if (rc != NO_ERROR)
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
81 return 0;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
82
101
a5da1ac53b34 Use long double instead of long long for drivesize and drivefree.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 100
diff changeset
83 return (long double)((double)aulFSInfoBuf[3] * (double)aulFSInfoBuf[1] * (double)aulFSInfoBuf[4]);
3
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
84 #elif defined(__WIN32__) || defined(WINNT)
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
85 char buffer[10] = "C:\\";
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
86 DWORD spc, bps, fc, tc;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
87
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
88 buffer[0] = drive + 'A' - 1;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
89
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
90 if(GetDiskFreeSpace(buffer, &spc, &bps, &fc, &tc) == 0)
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
91 return 0;
36
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
92
101
a5da1ac53b34 Use long double instead of long long for drivesize and drivefree.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 100
diff changeset
93 return (long double)((double)spc*(double)bps*(double)fc);
433
f225f16bebbd Compile fixes for MacOS X.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 176
diff changeset
94 #elif defined(__FreeBSD__) || defined(__MAC__)
36
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
95 struct statfs *fsp;
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
96 int entries, index = 1;
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
97
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
98 entries = getmntinfo (&fsp, MNT_NOWAIT);
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
99
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
100 for (; entries-- > 0; fsp++)
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
101 {
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
102 if(index == drive)
101
a5da1ac53b34 Use long double instead of long long for drivesize and drivefree.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 100
diff changeset
103 return (long double)((double)fsp->f_bsize * (double)fsp->f_bavail);
98
c0388006bb0d Fixes for FreeBSD.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 74
diff changeset
104 index++;
36
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
105 }
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
106 return 0;
42
eb003f77538c Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 37
diff changeset
107 #elif defined(__sun__)
eb003f77538c Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 37
diff changeset
108 FILE *fp = fopen("/etc/mnttab", "r");
eb003f77538c Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 37
diff changeset
109 struct mnttab mnt;
eb003f77538c Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 37
diff changeset
110 struct statfs sfs;
eb003f77538c Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 37
diff changeset
111 int index = 1;
eb003f77538c Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 37
diff changeset
112
eb003f77538c Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 37
diff changeset
113 if(fp)
eb003f77538c Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 37
diff changeset
114 {
eb003f77538c Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 37
diff changeset
115 while((getmntent(fp, &mnt) == 0))
eb003f77538c Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 37
diff changeset
116 {
eb003f77538c Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 37
diff changeset
117 if(index == drive)
eb003f77538c Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 37
diff changeset
118 {
101
a5da1ac53b34 Use long double instead of long long for drivesize and drivefree.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 100
diff changeset
119 long double size = 0;
42
eb003f77538c Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 37
diff changeset
120
eb003f77538c Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 37
diff changeset
121 if(mnt.mnt_mountp)
eb003f77538c Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 37
diff changeset
122 {
eb003f77538c Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 37
diff changeset
123 statfs(mnt.mnt_mountp, &sfs, sizeof(struct statfs), 0);
101
a5da1ac53b34 Use long double instead of long long for drivesize and drivefree.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 100
diff changeset
124 size = (long double)((double)sfs.f_bsize * (double)sfs.f_bfree);
42
eb003f77538c Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 37
diff changeset
125 }
eb003f77538c Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 37
diff changeset
126 fclose(fp);
eb003f77538c Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 37
diff changeset
127 return size;
eb003f77538c Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 37
diff changeset
128 }
eb003f77538c Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 37
diff changeset
129 index++;
eb003f77538c Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 37
diff changeset
130 }
eb003f77538c Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 37
diff changeset
131 fclose(fp);
eb003f77538c Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 37
diff changeset
132 }
eb003f77538c Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 37
diff changeset
133 return 0;
3
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
134 #else
36
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
135 FILE *fp = setmntent(MOUNTED, "r");
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
136 struct mntent *mnt;
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
137 struct statfs sfs;
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
138 int index = 1;
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
139
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
140 if(fp)
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
141 {
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
142 while((mnt = getmntent(fp)))
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
143 {
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
144 if(index == drive)
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
145 {
101
a5da1ac53b34 Use long double instead of long long for drivesize and drivefree.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 100
diff changeset
146 long double size = 0;
36
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
147
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
148 if(mnt->mnt_dir)
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
149 {
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
150 statfs(mnt->mnt_dir, &sfs);
101
a5da1ac53b34 Use long double instead of long long for drivesize and drivefree.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 100
diff changeset
151 size = (long double)((double)sfs.f_bsize * (double)sfs.f_bavail);
36
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
152 }
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
153 endmntent(fp);
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
154 return size;
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
155 }
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
156 index++;
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
157 }
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
158 endmntent(fp);
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
159 }
3
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
160 return 0;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
161 #endif
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
162 }
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
163
176
4e3407df0e38 Specify calling convention for compat functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 172
diff changeset
164 long double API drivesize(int drive)
35
432c39a4ff86 New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 22
diff changeset
165 {
432c39a4ff86 New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 22
diff changeset
166 #if defined(__EMX__) || defined(__OS2__)
432c39a4ff86 New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 22
diff changeset
167 ULONG aulFSInfoBuf[40] = {0};
432c39a4ff86 New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 22
diff changeset
168 APIRET rc = NO_ERROR;
432c39a4ff86 New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 22
diff changeset
169
432c39a4ff86 New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 22
diff changeset
170 DosError(FERR_DISABLEHARDERR);
432c39a4ff86 New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 22
diff changeset
171 rc = DosQueryFSInfo(drive,
432c39a4ff86 New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 22
diff changeset
172 FSIL_ALLOC,
432c39a4ff86 New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 22
diff changeset
173 (PVOID)aulFSInfoBuf,
432c39a4ff86 New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 22
diff changeset
174 sizeof(aulFSInfoBuf));
432c39a4ff86 New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 22
diff changeset
175
432c39a4ff86 New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 22
diff changeset
176 DosError(FERR_ENABLEHARDERR);
432c39a4ff86 New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 22
diff changeset
177 if (rc != NO_ERROR)
432c39a4ff86 New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 22
diff changeset
178 return 0;
432c39a4ff86 New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 22
diff changeset
179
101
a5da1ac53b34 Use long double instead of long long for drivesize and drivefree.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 100
diff changeset
180 return (long double)((double)aulFSInfoBuf[2] * (double)aulFSInfoBuf[1] * (double)aulFSInfoBuf[4]);
35
432c39a4ff86 New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 22
diff changeset
181 #elif defined(__WIN32__) || defined(WINNT)
432c39a4ff86 New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 22
diff changeset
182 char buffer[10] = "C:\\";
432c39a4ff86 New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 22
diff changeset
183 DWORD spc, bps, fc, tc;
432c39a4ff86 New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 22
diff changeset
184
432c39a4ff86 New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 22
diff changeset
185 buffer[0] = drive + 'A' - 1;
432c39a4ff86 New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 22
diff changeset
186
432c39a4ff86 New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 22
diff changeset
187 if(GetDiskFreeSpace(buffer, &spc, &bps, &fc, &tc) == 0)
432c39a4ff86 New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 22
diff changeset
188 return 0;
36
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
189
101
a5da1ac53b34 Use long double instead of long long for drivesize and drivefree.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 100
diff changeset
190 return (long double)((double)spc*(double)bps*(double)tc);
433
f225f16bebbd Compile fixes for MacOS X.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 176
diff changeset
191 #elif defined(__FreeBSD__) || defined(__MAC__)
36
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
192 struct statfs *fsp;
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
193 int entries, index = 1;
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
194
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
195 entries = getmntinfo (&fsp, MNT_NOWAIT);
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
196
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
197 for (; entries-- > 0; fsp++)
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
198 {
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
199 if(index == drive)
101
a5da1ac53b34 Use long double instead of long long for drivesize and drivefree.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 100
diff changeset
200 return (long double)((double)fsp->f_bsize * (double)fsp->f_blocks);
98
c0388006bb0d Fixes for FreeBSD.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 74
diff changeset
201 index++;
36
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
202 }
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
203 return 0;
42
eb003f77538c Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 37
diff changeset
204 #elif defined(__sun__)
eb003f77538c Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 37
diff changeset
205 FILE *fp = fopen("/etc/mnttab", "r");
eb003f77538c Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 37
diff changeset
206 struct mnttab mnt;
eb003f77538c Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 37
diff changeset
207 struct statfs sfs;
eb003f77538c Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 37
diff changeset
208 int index = 1;
eb003f77538c Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 37
diff changeset
209
eb003f77538c Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 37
diff changeset
210 if(fp)
eb003f77538c Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 37
diff changeset
211 {
eb003f77538c Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 37
diff changeset
212 while(getmntent(fp, &mnt) == 0)
eb003f77538c Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 37
diff changeset
213 {
eb003f77538c Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 37
diff changeset
214 if(index == drive)
eb003f77538c Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 37
diff changeset
215 {
101
a5da1ac53b34 Use long double instead of long long for drivesize and drivefree.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 100
diff changeset
216 long double size = 0;
42
eb003f77538c Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 37
diff changeset
217
eb003f77538c Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 37
diff changeset
218 if(mnt.mnt_mountp)
eb003f77538c Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 37
diff changeset
219 {
eb003f77538c Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 37
diff changeset
220 statfs(mnt.mnt_mountp, &sfs, sizeof(struct statfs), 0);
101
a5da1ac53b34 Use long double instead of long long for drivesize and drivefree.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 100
diff changeset
221 size = (long double)((double)sfs.f_bsize * (double)sfs.f_blocks);
42
eb003f77538c Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 37
diff changeset
222 }
eb003f77538c Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 37
diff changeset
223 fclose(fp);
eb003f77538c Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 37
diff changeset
224 return size;
eb003f77538c Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 37
diff changeset
225 }
eb003f77538c Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 37
diff changeset
226 index++;
eb003f77538c Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 37
diff changeset
227 }
eb003f77538c Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 37
diff changeset
228 fclose(fp);
eb003f77538c Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 37
diff changeset
229 }
eb003f77538c Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 37
diff changeset
230 return 0;
35
432c39a4ff86 New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 22
diff changeset
231 #else
36
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
232 FILE *fp = setmntent(MOUNTED, "r");
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
233 struct mntent *mnt;
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
234 struct statfs sfs;
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
235 int index = 1;
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
236
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
237 if(fp)
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
238 {
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
239 while((mnt = getmntent(fp)))
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
240 {
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
241 if(index == drive)
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
242 {
101
a5da1ac53b34 Use long double instead of long long for drivesize and drivefree.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 100
diff changeset
243 long double size = 0;
36
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
244
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
245 if(mnt->mnt_dir)
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
246 {
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
247 statfs(mnt->mnt_dir, &sfs);
101
a5da1ac53b34 Use long double instead of long long for drivesize and drivefree.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 100
diff changeset
248 size = (long double)((double)sfs.f_bsize * (double)sfs.f_blocks);
36
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
249 }
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
250 endmntent(fp);
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
251 return size;
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
252 }
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
253 index++;
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
254 }
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
255 endmntent(fp);
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
256 }
35
432c39a4ff86 New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 22
diff changeset
257 return 0;
432c39a4ff86 New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 22
diff changeset
258 #endif
432c39a4ff86 New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 22
diff changeset
259 }
432c39a4ff86 New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 22
diff changeset
260
176
4e3407df0e38 Specify calling convention for compat functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 172
diff changeset
261 int API isdrive(int drive)
3
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
262 {
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
263 #if defined(__EMX__) || defined(__OS2__)
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
264 APIRET rc = NO_ERROR;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
265 FSINFO volinfo;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
266
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
267 DosError(FERR_DISABLEHARDERR);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
268 rc = DosQueryFSInfo(drive,
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
269 FSIL_VOLSER,
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
270 (PVOID)&volinfo,
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
271 sizeof(FSINFO));
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
272
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
273 DosError(FERR_ENABLEHARDERR);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
274 if (rc == NO_ERROR)
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
275 return 1;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
276
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
277 #elif defined(__WIN32__) || defined(WINNT)
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
278 char buffer[10] = "C:\\", volname[100];
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
279 DWORD spc, bps, fc;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
280
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
281 buffer[0] = drive + 'A' - 1;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
282
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
283 if(GetVolumeInformation(buffer, volname, 100, &spc, &bps, &fc, NULL, 0) != 0)
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
284 return 1;
433
f225f16bebbd Compile fixes for MacOS X.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 176
diff changeset
285 #elif defined(__FreeBSD__) || defined(__MAC__)
36
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
286 struct statfs *fsp;
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
287 int entries, index = 1;
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
288
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
289 entries = getmntinfo (&fsp, MNT_NOWAIT);
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
290
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
291 for (; entries-- > 0; fsp++)
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
292 {
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
293 if(index == drive && fsp->f_blocks)
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
294 return 1;
98
c0388006bb0d Fixes for FreeBSD.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 74
diff changeset
295 index++;
36
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
296 }
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
297 return 0;
42
eb003f77538c Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 37
diff changeset
298 #elif defined(__sun__)
eb003f77538c Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 37
diff changeset
299 FILE *fp = fopen("/etc/mnttab", "r");
eb003f77538c Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 37
diff changeset
300 struct mnttab mnt;
eb003f77538c Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 37
diff changeset
301 struct statfs sfs;
eb003f77538c Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 37
diff changeset
302 int index = 1;
eb003f77538c Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 37
diff changeset
303
eb003f77538c Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 37
diff changeset
304 if(fp)
eb003f77538c Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 37
diff changeset
305 {
eb003f77538c Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 37
diff changeset
306 while(getmntent(fp, &mnt) == 0)
eb003f77538c Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 37
diff changeset
307 {
eb003f77538c Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 37
diff changeset
308 if(index == drive)
eb003f77538c Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 37
diff changeset
309 {
eb003f77538c Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 37
diff changeset
310 fclose(fp);
eb003f77538c Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 37
diff changeset
311 if(mnt.mnt_mountp)
eb003f77538c Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 37
diff changeset
312 {
eb003f77538c Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 37
diff changeset
313 statfs(mnt.mnt_mountp, &sfs, sizeof(struct statfs), 0);
eb003f77538c Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 37
diff changeset
314 if(sfs.f_blocks)
eb003f77538c Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 37
diff changeset
315 return 1;
eb003f77538c Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 37
diff changeset
316 }
eb003f77538c Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 37
diff changeset
317 return 0;
eb003f77538c Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 37
diff changeset
318 }
eb003f77538c Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 37
diff changeset
319 index++;
eb003f77538c Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 37
diff changeset
320 }
eb003f77538c Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 37
diff changeset
321 fclose(fp);
eb003f77538c Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 37
diff changeset
322 }
36
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
323 #else
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
324 FILE *fp = setmntent(MOUNTED, "r");
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
325 struct mntent *mnt;
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
326 struct statfs sfs;
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
327 int index = 1;
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
328
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
329 if(fp)
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
330 {
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
331 while((mnt = getmntent(fp)))
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
332 {
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
333 if(index == drive)
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
334 {
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
335 endmntent(fp);
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
336 if(mnt->mnt_dir)
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
337 {
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
338 statfs(mnt->mnt_dir, &sfs);
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
339 if(sfs.f_blocks)
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
340 return 1;
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
341 }
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
342 return 0;
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
343 }
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
344 index++;
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
345 }
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
346 endmntent(fp);
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
347 }
3
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
348 #endif
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
349 return 0;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
350 }
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
351
176
4e3407df0e38 Specify calling convention for compat functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 172
diff changeset
352 void API getfsname(int drive, char *buf, int len)
36
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
353 {
433
f225f16bebbd Compile fixes for MacOS X.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 176
diff changeset
354 #if defined(__UNIX__) || defined(__MAC__)
f225f16bebbd Compile fixes for MacOS X.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 176
diff changeset
355 #if defined(__FreeBSD__) || defined(__MAC__)
36
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
356 struct statfs *fsp;
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
357 int entries, index = 1;
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
358
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
359 strncpy(buf, "Unknown", len);
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
360
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
361 entries = getmntinfo (&fsp, MNT_NOWAIT);
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
362
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
363 for (; entries-- > 0; fsp++)
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
364 {
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
365 if(index == drive)
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
366 strncpy(buf, fsp->f_mntonname, len);
98
c0388006bb0d Fixes for FreeBSD.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 74
diff changeset
367 index++;
36
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
368 }
42
eb003f77538c Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 37
diff changeset
369 #elif defined(__sun__)
eb003f77538c Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 37
diff changeset
370 FILE *fp = fopen("/etc/mnttab", "r");
eb003f77538c Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 37
diff changeset
371 struct mnttab mnt;
eb003f77538c Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 37
diff changeset
372 int index = 1;
eb003f77538c Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 37
diff changeset
373
eb003f77538c Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 37
diff changeset
374 strncpy(buf, "Unknown", len);
eb003f77538c Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 37
diff changeset
375
eb003f77538c Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 37
diff changeset
376 if(fp)
eb003f77538c Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 37
diff changeset
377 {
eb003f77538c Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 37
diff changeset
378 while(getmntent(fp, &mnt) == 0)
eb003f77538c Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 37
diff changeset
379 {
eb003f77538c Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 37
diff changeset
380 if(index == drive && mnt.mnt_mountp)
eb003f77538c Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 37
diff changeset
381 strncpy(buf, mnt.mnt_mountp, len);
eb003f77538c Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 37
diff changeset
382 index++;
eb003f77538c Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 37
diff changeset
383 }
eb003f77538c Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 37
diff changeset
384 fclose(fp);
eb003f77538c Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 37
diff changeset
385 }
36
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
386 #else
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
387 FILE *fp = setmntent(MOUNTED, "r");
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
388 struct mntent *mnt;
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
389 int index = 1;
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
390
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
391 strncpy(buf, "Unknown", len);
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
392
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
393 if(fp)
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
394 {
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
395 while((mnt = getmntent(fp)))
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
396 {
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
397 if(index == drive && mnt->mnt_dir)
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
398 strncpy(buf, mnt->mnt_dir, len);
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
399 index++;
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
400 }
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
401 endmntent(fp);
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
402 }
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
403 #endif
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
404 #elif defined(__OS2__)
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
405 /* No snprintf() on OS/2 ??? */
485
469ff8133ed3 Simplified the folder browser on OS/2, following some Unix changes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 441
diff changeset
406 len = len;
36
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
407 sprintf(buf, "Drive %c", (char)drive + 'A' - 1);
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
408 #else
37
360bc6a5f1c9 Sync with latest Dynamic Windows code.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 36
diff changeset
409 _snprintf(buf, len, "Drive %c", (char)drive + 'A' - 1);
36
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
410 #endif
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
411 }
cddb02f847e1 Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 35
diff changeset
412
176
4e3407df0e38 Specify calling convention for compat functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 172
diff changeset
413 void API setfileinfo(char *filename, char *url, char *logfile)
3
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
414 {
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
415 time_t ltime;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
416 struct tm *tm;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
417 char buffer[200], timebuf[200];
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
418 #ifdef __OS2__
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
419 const unsigned fea2listsize = 6000;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
420 char *pData;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
421 EAOP2 eaop2;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
422 PFEA2 pFEA2;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
423 #else
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
424 FILE *urlfile;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
425 #endif
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
426
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
427 ltime = time(NULL);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
428
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
429 tm = localtime(&ltime);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
430
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
431 strftime(timebuf, 200, "%c", tm);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
432
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
433 sprintf(buffer, "%s %s", url, timebuf);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
434
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
435 #ifdef __OS2__
485
469ff8133ed3 Simplified the folder browser on OS/2, following some Unix changes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 441
diff changeset
436 logfile = logfile;
3
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
437 eaop2.fpGEA2List = 0;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
438 eaop2.fpFEA2List = (PFEA2LIST)malloc(fea2listsize);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
439 pFEA2 = &eaop2.fpFEA2List->list[0];
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
440
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
441 pFEA2->fEA = 0;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
442 /* .COMMENTS is 9 characters long */
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
443 pFEA2->cbName = 9;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
444
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
445 /* space for the type and length field. */
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
446 pFEA2->cbValue = strlen(buffer)+2*sizeof(USHORT);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
447
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
448 strcpy(pFEA2->szName, ".COMMENTS");
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
449 pData = pFEA2->szName+pFEA2->cbName+1;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
450 /* data begins at first byte after the name */
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
451
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
452 *(USHORT*)pData = EAT_ASCII; /* type */
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
453 *((USHORT*)pData+1) = strlen(buffer); /* length */
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
454 strcpy(pData+2*sizeof(USHORT), buffer);/* content */
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
455
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
456 pFEA2->oNextEntryOffset = 0;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
457
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
458 eaop2.fpFEA2List->cbList = ((PCHAR)pData+2*sizeof(USHORT)+
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
459 pFEA2->cbValue)-((PCHAR)eaop2.fpFEA2List);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
460
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
461 DosSetPathInfo(filename,
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
462 FIL_QUERYEASIZE,
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
463 &eaop2,
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
464 sizeof(eaop2),
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
465 0);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
466
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
467 free((void *)eaop2.fpFEA2List);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
468 #else
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
469
53
8add9a616d0e Added a log filename parameter to setfileinfo().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 47
diff changeset
470 if((urlfile = fopen(logfile, "a"))!=NULL)
3
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
471 {
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
472 fprintf(urlfile, "%s\n", buffer);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
473 fclose(urlfile);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
474 }
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
475 #endif
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
476 }
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
477
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
478 #if defined(__OS2__) || defined(__WIN32__)
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
479 typedef struct _fsinfo {
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
480 FILE *fp;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
481 int fd;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
482 } FSInfo;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
483
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
484 FSInfo *FSIRoot = NULL;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
485
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
486 #define FSI_MAX 100
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
487 #endif
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
488
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
489 /* Sharable fopen() and fclose() calls. */
176
4e3407df0e38 Specify calling convention for compat functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 172
diff changeset
490 FILE * API fsopen(char *path, char *modes)
3
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
491 {
172
0fc45e386376 Get Dynamic Windows building with Watcom.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 101
diff changeset
492 #if (defined(__OS2__) && !defined(__WATCOMC__)) || defined(__WIN32__)
3
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
493 int z;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
494
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
495 if(!FSIRoot)
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
496 FSIRoot = calloc(sizeof(struct _fsinfo), FSI_MAX);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
497
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
498 for(z=0;z<FSI_MAX;z++)
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
499 {
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
500 if(FSIRoot[z].fd < 1)
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
501 {
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
502 int s, sopenmode = 0, wrmode = 0;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
503
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
504 /* Check the flags passed */
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
505 for(s=0;s<3;s++)
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
506 {
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
507 if(modes[s] == 'b')
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
508 sopenmode |= O_BINARY;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
509 if(modes[s] == 'r')
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
510 wrmode |= O_RDONLY;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
511 if(modes[s] == 'w')
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
512 wrmode |= O_WRONLY;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
513 if(modes[s] == 'a')
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
514 sopenmode |= O_APPEND;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
515 if(modes[s] == 't')
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
516 sopenmode |= O_TEXT;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
517 }
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
518
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
519 /* Check the read/write request */
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
520 if((wrmode & O_RDONLY) && (wrmode & O_WRONLY))
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
521 sopenmode |= O_RDWR;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
522 else
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
523 sopenmode |= wrmode;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
524 FSIRoot[z].fd = _sopen(path, sopenmode, SH_DENYNO, S_IREAD|S_IWRITE);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
525 if(FSIRoot[z].fd > 0)
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
526 {
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
527 FSIRoot[z].fp = fdopen(FSIRoot[z].fd, modes);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
528
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
529 return FSIRoot[z].fp;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
530 }
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
531 }
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
532 }
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
533 return NULL;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
534 #else
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
535 return fopen(path, modes);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
536 #endif
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
537 }
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
538
176
4e3407df0e38 Specify calling convention for compat functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 172
diff changeset
539 int API fsclose(FILE *fp)
3
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
540 {
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
541 #if defined(__OS2__) || defined(__WIN32__)
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
542 if(FSIRoot)
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
543 {
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
544
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
545 int z;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
546 for(z=0;z<FSI_MAX;z++)
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
547 {
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
548 if(fp == FSIRoot[z].fp)
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
549 {
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
550 int ret = fclose(fp);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
551 close(FSIRoot[z].fd);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
552 FSIRoot[z].fd = 0;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
553 FSIRoot[z].fp = NULL;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
554 return ret;
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
555 }
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
556 }
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
557 }
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
558 #endif
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
559 return fclose(fp);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
560 }
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
561
176
4e3407df0e38 Specify calling convention for compat functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 172
diff changeset
562 char * API fsgets(char *str, int size, FILE *stream)
3
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
563 {
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
564 return fgets(str, size, stream);
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
565 }
ktk@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
566
176
4e3407df0e38 Specify calling convention for compat functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 172
diff changeset
567 int API fsseek(FILE *stream, long offset, int whence)
22
6a246b3bb14f Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 3
diff changeset
568 {
6a246b3bb14f Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 3
diff changeset
569 return fseek(stream, offset, whence);
6a246b3bb14f Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 3
diff changeset
570 }
72
ab77a22a2a36 Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 62
diff changeset
571
557
1a210e2f214b Added a bunch of support routines I now own due to the settlement
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 485
diff changeset
572 void API nice_strformat(char *dest, long double val, int dec)
1a210e2f214b Added a bunch of support routines I now own due to the settlement
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 485
diff changeset
573 {
1a210e2f214b Added a bunch of support routines I now own due to the settlement
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 485
diff changeset
574 char formatbuf[10];
1a210e2f214b Added a bunch of support routines I now own due to the settlement
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 485
diff changeset
575 char format = 0;
1a210e2f214b Added a bunch of support routines I now own due to the settlement
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 485
diff changeset
576 double printval;
1a210e2f214b Added a bunch of support routines I now own due to the settlement
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 485
diff changeset
577
1a210e2f214b Added a bunch of support routines I now own due to the settlement
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 485
diff changeset
578 /* 1024 ^ 3 = Gigabytes */
1a210e2f214b Added a bunch of support routines I now own due to the settlement
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 485
diff changeset
579 if(val >= 1073741824L)
1a210e2f214b Added a bunch of support routines I now own due to the settlement
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 485
diff changeset
580 {
1a210e2f214b Added a bunch of support routines I now own due to the settlement
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 485
diff changeset
581 printval = val/(1073741824L);
1a210e2f214b Added a bunch of support routines I now own due to the settlement
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 485
diff changeset
582 format = 'G';
1a210e2f214b Added a bunch of support routines I now own due to the settlement
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 485
diff changeset
583 }
1a210e2f214b Added a bunch of support routines I now own due to the settlement
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 485
diff changeset
584 /* 1024 ^ 2 = Megabytes */
1a210e2f214b Added a bunch of support routines I now own due to the settlement
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 485
diff changeset
585 else if(val >= 1048576)
1a210e2f214b Added a bunch of support routines I now own due to the settlement
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 485
diff changeset
586 {
1a210e2f214b Added a bunch of support routines I now own due to the settlement
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 485
diff changeset
587 printval = val/(1048576);
1a210e2f214b Added a bunch of support routines I now own due to the settlement
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 485
diff changeset
588 format = 'M';
1a210e2f214b Added a bunch of support routines I now own due to the settlement
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 485
diff changeset
589 }
1a210e2f214b Added a bunch of support routines I now own due to the settlement
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 485
diff changeset
590 /* 1024 = Kilobytes */
1a210e2f214b Added a bunch of support routines I now own due to the settlement
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 485
diff changeset
591 else if(val > 1024)
1a210e2f214b Added a bunch of support routines I now own due to the settlement
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 485
diff changeset
592 {
1a210e2f214b Added a bunch of support routines I now own due to the settlement
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 485
diff changeset
593 printval = val/1024;
1a210e2f214b Added a bunch of support routines I now own due to the settlement
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 485
diff changeset
594 format = 'K';
1a210e2f214b Added a bunch of support routines I now own due to the settlement
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 485
diff changeset
595 }
1a210e2f214b Added a bunch of support routines I now own due to the settlement
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 485
diff changeset
596 else
1a210e2f214b Added a bunch of support routines I now own due to the settlement
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 485
diff changeset
597 printval = val;
1a210e2f214b Added a bunch of support routines I now own due to the settlement
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 485
diff changeset
598
1a210e2f214b Added a bunch of support routines I now own due to the settlement
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 485
diff changeset
599 /* Generate the format string */
1a210e2f214b Added a bunch of support routines I now own due to the settlement
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 485
diff changeset
600 sprintf(formatbuf, "%%.%df%c", dec, format);
1a210e2f214b Added a bunch of support routines I now own due to the settlement
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 485
diff changeset
601 /* Create the pretty value */
1a210e2f214b Added a bunch of support routines I now own due to the settlement
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 485
diff changeset
602 sprintf(dest, formatbuf, printval);
1a210e2f214b Added a bunch of support routines I now own due to the settlement
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 485
diff changeset
603 }
1a210e2f214b Added a bunch of support routines I now own due to the settlement
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 485
diff changeset
604
1a210e2f214b Added a bunch of support routines I now own due to the settlement
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 485
diff changeset
605 /* Update the current working directory based on the
1a210e2f214b Added a bunch of support routines I now own due to the settlement
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 485
diff changeset
606 * path of the executable being executed.
1a210e2f214b Added a bunch of support routines I now own due to the settlement
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 485
diff changeset
607 */
1a210e2f214b Added a bunch of support routines I now own due to the settlement
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 485
diff changeset
608 void API initdir(int argc, char *argv[])
1a210e2f214b Added a bunch of support routines I now own due to the settlement
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 485
diff changeset
609 {
1a210e2f214b Added a bunch of support routines I now own due to the settlement
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 485
diff changeset
610 if(argc > 0)
1a210e2f214b Added a bunch of support routines I now own due to the settlement
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 485
diff changeset
611 {
1a210e2f214b Added a bunch of support routines I now own due to the settlement
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 485
diff changeset
612 char *tmpdir = strdup(argv[0]);
1a210e2f214b Added a bunch of support routines I now own due to the settlement
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 485
diff changeset
613 int z, len = strlen(argv[0]);
1a210e2f214b Added a bunch of support routines I now own due to the settlement
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 485
diff changeset
614
1a210e2f214b Added a bunch of support routines I now own due to the settlement
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 485
diff changeset
615 for(z=len;z > -1;z--)
1a210e2f214b Added a bunch of support routines I now own due to the settlement
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 485
diff changeset
616 {
1a210e2f214b Added a bunch of support routines I now own due to the settlement
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 485
diff changeset
617 if(tmpdir[z] == '/')
1a210e2f214b Added a bunch of support routines I now own due to the settlement
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 485
diff changeset
618 {
1a210e2f214b Added a bunch of support routines I now own due to the settlement
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 485
diff changeset
619 tmpdir[z+1] = 0;
1a210e2f214b Added a bunch of support routines I now own due to the settlement
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 485
diff changeset
620 setpath(tmpdir);
1a210e2f214b Added a bunch of support routines I now own due to the settlement
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 485
diff changeset
621 free(tmpdir);
1a210e2f214b Added a bunch of support routines I now own due to the settlement
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 485
diff changeset
622 return;
1a210e2f214b Added a bunch of support routines I now own due to the settlement
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 485
diff changeset
623 }
1a210e2f214b Added a bunch of support routines I now own due to the settlement
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 485
diff changeset
624 }
1a210e2f214b Added a bunch of support routines I now own due to the settlement
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 485
diff changeset
625 free(tmpdir);
1a210e2f214b Added a bunch of support routines I now own due to the settlement
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 485
diff changeset
626 }
1a210e2f214b Added a bunch of support routines I now own due to the settlement
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 485
diff changeset
627 }
1a210e2f214b Added a bunch of support routines I now own due to the settlement
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 485
diff changeset
628
1a210e2f214b Added a bunch of support routines I now own due to the settlement
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 485
diff changeset
629 /*
1a210e2f214b Added a bunch of support routines I now own due to the settlement
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 485
diff changeset
630 * Sets the current directory (and drive) information.
1a210e2f214b Added a bunch of support routines I now own due to the settlement
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 485
diff changeset
631 * Parameters:
1a210e2f214b Added a bunch of support routines I now own due to the settlement
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 485
diff changeset
632 * path: A buffer containing the new path.
1a210e2f214b Added a bunch of support routines I now own due to the settlement
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 485
diff changeset
633 * Returns:
1a210e2f214b Added a bunch of support routines I now own due to the settlement
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 485
diff changeset
634 * -1 on error.
1a210e2f214b Added a bunch of support routines I now own due to the settlement
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 485
diff changeset
635 */
1a210e2f214b Added a bunch of support routines I now own due to the settlement
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 485
diff changeset
636 int API setpath(char *path)
1a210e2f214b Added a bunch of support routines I now own due to the settlement
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 485
diff changeset
637 {
1a210e2f214b Added a bunch of support routines I now own due to the settlement
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 485
diff changeset
638 #if defined(__OS2__) || defined(__WIN32__)
1a210e2f214b Added a bunch of support routines I now own due to the settlement
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 485
diff changeset
639 if(strlen(path) > 2)
1a210e2f214b Added a bunch of support routines I now own due to the settlement
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 485
diff changeset
640 {
1a210e2f214b Added a bunch of support routines I now own due to the settlement
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 485
diff changeset
641 if(path[1] == ':')
1a210e2f214b Added a bunch of support routines I now own due to the settlement
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 485
diff changeset
642 {
1a210e2f214b Added a bunch of support routines I now own due to the settlement
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 485
diff changeset
643 char drive = toupper(path[0]);
1a210e2f214b Added a bunch of support routines I now own due to the settlement
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 485
diff changeset
644 _chdrive((drive - 'A')+1);
1a210e2f214b Added a bunch of support routines I now own due to the settlement
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 485
diff changeset
645 }
1a210e2f214b Added a bunch of support routines I now own due to the settlement
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 485
diff changeset
646 }
1a210e2f214b Added a bunch of support routines I now own due to the settlement
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 485
diff changeset
647 #endif
1a210e2f214b Added a bunch of support routines I now own due to the settlement
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 485
diff changeset
648 return chdir(path);
1a210e2f214b Added a bunch of support routines I now own due to the settlement
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 485
diff changeset
649 }
1a210e2f214b Added a bunch of support routines I now own due to the settlement
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 485
diff changeset
650
72
ab77a22a2a36 Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 62
diff changeset
651 static int locale_number = -1, locale_count = 0;
ab77a22a2a36 Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 62
diff changeset
652 static char **locale_text = NULL;
ab77a22a2a36 Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 62
diff changeset
653
ab77a22a2a36 Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 62
diff changeset
654 void _free_locale(void)
ab77a22a2a36 Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 62
diff changeset
655 {
ab77a22a2a36 Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 62
diff changeset
656 if(locale_text)
ab77a22a2a36 Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 62
diff changeset
657 {
ab77a22a2a36 Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 62
diff changeset
658 int z;
ab77a22a2a36 Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 62
diff changeset
659
ab77a22a2a36 Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 62
diff changeset
660 for(z=0;z<locale_count;z++)
ab77a22a2a36 Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 62
diff changeset
661 {
ab77a22a2a36 Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 62
diff changeset
662 if(locale_text[z])
ab77a22a2a36 Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 62
diff changeset
663 free(locale_text[z]);
ab77a22a2a36 Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 62
diff changeset
664 }
ab77a22a2a36 Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 62
diff changeset
665 free(locale_text);
ab77a22a2a36 Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 62
diff changeset
666 locale_text = NULL;
ab77a22a2a36 Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 62
diff changeset
667 }
ab77a22a2a36 Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 62
diff changeset
668 }
ab77a22a2a36 Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 62
diff changeset
669
ab77a22a2a36 Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 62
diff changeset
670 void _stripcrlf(char *buf)
ab77a22a2a36 Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 62
diff changeset
671 {
ab77a22a2a36 Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 62
diff changeset
672 int z, len = strlen(buf);
ab77a22a2a36 Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 62
diff changeset
673
ab77a22a2a36 Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 62
diff changeset
674 for(z=0;z<len;z++)
ab77a22a2a36 Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 62
diff changeset
675 {
ab77a22a2a36 Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 62
diff changeset
676 if(buf[z] == '\r' || buf[z] == '\n')
ab77a22a2a36 Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 62
diff changeset
677 {
ab77a22a2a36 Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 62
diff changeset
678 buf[z] = 0;
ab77a22a2a36 Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 62
diff changeset
679 return;
ab77a22a2a36 Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 62
diff changeset
680 }
ab77a22a2a36 Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 62
diff changeset
681 }
ab77a22a2a36 Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 62
diff changeset
682 }
ab77a22a2a36 Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 62
diff changeset
683
74
f794f2baabf2 Added codepage translation for Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 73
diff changeset
684 #ifdef __WIN32__
f794f2baabf2 Added codepage translation for Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 73
diff changeset
685 #define LOCALE_CHARACTERS 62
f794f2baabf2 Added codepage translation for Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 73
diff changeset
686 static char locale_table[LOCALE_CHARACTERS * 2] = {
f794f2baabf2 Added codepage translation for Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 73
diff changeset
687 0xc0, 0xb7, 0xc1, 0xb5, 0xc2, 0xb6, 0xc3, 0xc7, 0xc4, 0x8e, 0xc5, 0x8f,
f794f2baabf2 Added codepage translation for Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 73
diff changeset
688 0xc6, 0x92, 0xc7, 0x80, 0xc8, 0xd4, 0xc9, 0x90, 0xcb, 0xd3, 0xcc, 0xde,
f794f2baabf2 Added codepage translation for Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 73
diff changeset
689 0xcd, 0xd6, 0xce, 0xd7, 0xcf, 0xd8, 0xd0, 0xd1, 0xd1, 0xa5, 0xd2, 0xe3,
f794f2baabf2 Added codepage translation for Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 73
diff changeset
690 0xd3, 0xe0, 0xd4, 0xe2, 0xd5, 0xe5, 0xd6, 0x99, 0xd8, 0x9d, 0xd9, 0xeb,
f794f2baabf2 Added codepage translation for Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 73
diff changeset
691 0xda, 0xe9, 0xdb, 0xea, 0xdc, 0x9a, 0xde, 0xed, 0xde, 0xe8, 0xdf, 0xe1,
f794f2baabf2 Added codepage translation for Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 73
diff changeset
692 0xe0, 0x85, 0xe1, 0xa0, 0xe2, 0x83, 0xe3, 0xc6, 0xe4, 0x84, 0xe5, 0x86,
f794f2baabf2 Added codepage translation for Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 73
diff changeset
693 0xe6, 0x91, 0xe7, 0x87, 0xe8, 0x8a, 0xe9, 0x82, 0xea, 0x88, 0xeb, 0x89,
f794f2baabf2 Added codepage translation for Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 73
diff changeset
694 0xec, 0x8d, 0xed, 0xa1, 0xee, 0x8c, 0xef, 0x8b, 0xf0, 0xd0, 0xf1, 0xa4,
f794f2baabf2 Added codepage translation for Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 73
diff changeset
695 0xf2, 0x95, 0xf3, 0xa3, 0xf4, 0x93, 0xf5, 0xe4, 0xf6, 0x94, 0xf7, 0xf6,
f794f2baabf2 Added codepage translation for Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 73
diff changeset
696 0xf8, 0x9b, 0xf9, 0x97, 0xfa, 0xa3, 0xfb, 0x96, 0xfc, 0x81, 0xfd, 0xec,
f794f2baabf2 Added codepage translation for Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 73
diff changeset
697 0xfe, 0xe7, 0xff, 0x9e
f794f2baabf2 Added codepage translation for Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 73
diff changeset
698
f794f2baabf2 Added codepage translation for Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 73
diff changeset
699 };
f794f2baabf2 Added codepage translation for Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 73
diff changeset
700
f794f2baabf2 Added codepage translation for Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 73
diff changeset
701 char locale_convert(int codepage, char c)
f794f2baabf2 Added codepage translation for Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 73
diff changeset
702 {
f794f2baabf2 Added codepage translation for Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 73
diff changeset
703 int z;
f794f2baabf2 Added codepage translation for Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 73
diff changeset
704
f794f2baabf2 Added codepage translation for Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 73
diff changeset
705 for(z=0;z<LOCALE_CHARACTERS;z++)
f794f2baabf2 Added codepage translation for Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 73
diff changeset
706 {
f794f2baabf2 Added codepage translation for Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 73
diff changeset
707 if(locale_table[(z*2)+1] == c)
f794f2baabf2 Added codepage translation for Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 73
diff changeset
708 return locale_table[z*2];
f794f2baabf2 Added codepage translation for Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 73
diff changeset
709 }
f794f2baabf2 Added codepage translation for Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 73
diff changeset
710 return c;
f794f2baabf2 Added codepage translation for Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 73
diff changeset
711 }
f794f2baabf2 Added codepage translation for Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 73
diff changeset
712 #endif
f794f2baabf2 Added codepage translation for Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 73
diff changeset
713
72
ab77a22a2a36 Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 62
diff changeset
714 /* Initialize the locale engine
ab77a22a2a36 Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 62
diff changeset
715 * Returns: TRUE on success, FALSE on failure.
ab77a22a2a36 Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 62
diff changeset
716 */
176
4e3407df0e38 Specify calling convention for compat functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 172
diff changeset
717 int API locale_init(char *filename, int my_locale)
72
ab77a22a2a36 Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 62
diff changeset
718 {
ab77a22a2a36 Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 62
diff changeset
719 FILE *fp = fopen(filename, FOPEN_READ_TEXT);
ab77a22a2a36 Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 62
diff changeset
720 static char text[1025];
ab77a22a2a36 Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 62
diff changeset
721 int count = 0;
ab77a22a2a36 Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 62
diff changeset
722
ab77a22a2a36 Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 62
diff changeset
723 _free_locale();
ab77a22a2a36 Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 62
diff changeset
724
ab77a22a2a36 Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 62
diff changeset
725 if(fp)
ab77a22a2a36 Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 62
diff changeset
726 {
ab77a22a2a36 Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 62
diff changeset
727
ab77a22a2a36 Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 62
diff changeset
728 fgets(text, 1024, fp);
ab77a22a2a36 Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 62
diff changeset
729 if(strncasecmp(text, "MESSAGES=", 9) == 0 && (count = atoi(&text[9])) > 0)
ab77a22a2a36 Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 62
diff changeset
730 {
ab77a22a2a36 Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 62
diff changeset
731 int current = -1;
ab77a22a2a36 Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 62
diff changeset
732
ab77a22a2a36 Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 62
diff changeset
733 locale_text = calloc(count, sizeof(char *));
ab77a22a2a36 Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 62
diff changeset
734
ab77a22a2a36 Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 62
diff changeset
735 while(!feof(fp))
ab77a22a2a36 Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 62
diff changeset
736 {
ab77a22a2a36 Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 62
diff changeset
737 fgets(text, 1024, fp);
ab77a22a2a36 Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 62
diff changeset
738 _stripcrlf(text);
ab77a22a2a36 Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 62
diff changeset
739
ab77a22a2a36 Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 62
diff changeset
740 if(strncasecmp(text, "LOCALE=", 7) == 0)
ab77a22a2a36 Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 62
diff changeset
741 {
ab77a22a2a36 Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 62
diff changeset
742 if(current > -1)
ab77a22a2a36 Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 62
diff changeset
743 {
ab77a22a2a36 Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 62
diff changeset
744 fclose(fp);
ab77a22a2a36 Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 62
diff changeset
745 locale_count = count;
ab77a22a2a36 Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 62
diff changeset
746 locale_number = my_locale;
ab77a22a2a36 Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 62
diff changeset
747 return 1;
ab77a22a2a36 Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 62
diff changeset
748 }
ab77a22a2a36 Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 62
diff changeset
749 if(atoi(&text[7]) == my_locale)
ab77a22a2a36 Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 62
diff changeset
750 current = 0;
ab77a22a2a36 Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 62
diff changeset
751 }
ab77a22a2a36 Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 62
diff changeset
752 else if(current > -1 && current < count)
ab77a22a2a36 Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 62
diff changeset
753 {
ab77a22a2a36 Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 62
diff changeset
754 /* Use defaults on blank lines */
ab77a22a2a36 Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 62
diff changeset
755 if(text[0])
73
2f339dd13496 Added C/C++ style escape sequence processing. And fixed a couple OS/2 and
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 72
diff changeset
756 {
2f339dd13496 Added C/C++ style escape sequence processing. And fixed a couple OS/2 and
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 72
diff changeset
757 int x = 0, z, len = strlen(text);
2f339dd13496 Added C/C++ style escape sequence processing. And fixed a couple OS/2 and
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 72
diff changeset
758
2f339dd13496 Added C/C++ style escape sequence processing. And fixed a couple OS/2 and
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 72
diff changeset
759 locale_text[current] = calloc(1, len + 1);
2f339dd13496 Added C/C++ style escape sequence processing. And fixed a couple OS/2 and
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 72
diff changeset
760
2f339dd13496 Added C/C++ style escape sequence processing. And fixed a couple OS/2 and
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 72
diff changeset
761 for(z=0;z<len;z++)
2f339dd13496 Added C/C++ style escape sequence processing. And fixed a couple OS/2 and
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 72
diff changeset
762 {
2f339dd13496 Added C/C++ style escape sequence processing. And fixed a couple OS/2 and
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 72
diff changeset
763 if(text[z] == '\\' && (text[z+1] == 'r' || text[z+1] == 'n'
2f339dd13496 Added C/C++ style escape sequence processing. And fixed a couple OS/2 and
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 72
diff changeset
764 || text[z+1] == '\"' || text[z+1] == '\''))
2f339dd13496 Added C/C++ style escape sequence processing. And fixed a couple OS/2 and
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 72
diff changeset
765 {
2f339dd13496 Added C/C++ style escape sequence processing. And fixed a couple OS/2 and
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 72
diff changeset
766 switch(text[z+1])
2f339dd13496 Added C/C++ style escape sequence processing. And fixed a couple OS/2 and
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 72
diff changeset
767 {
2f339dd13496 Added C/C++ style escape sequence processing. And fixed a couple OS/2 and
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 72
diff changeset
768 case 'r':
2f339dd13496 Added C/C++ style escape sequence processing. And fixed a couple OS/2 and
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 72
diff changeset
769 locale_text[current][x] = '\r';
2f339dd13496 Added C/C++ style escape sequence processing. And fixed a couple OS/2 and
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 72
diff changeset
770 break;
2f339dd13496 Added C/C++ style escape sequence processing. And fixed a couple OS/2 and
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 72
diff changeset
771 case 'n':
2f339dd13496 Added C/C++ style escape sequence processing. And fixed a couple OS/2 and
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 72
diff changeset
772 locale_text[current][x] = '\n';
2f339dd13496 Added C/C++ style escape sequence processing. And fixed a couple OS/2 and
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 72
diff changeset
773 break;
2f339dd13496 Added C/C++ style escape sequence processing. And fixed a couple OS/2 and
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 72
diff changeset
774 case '\"':
2f339dd13496 Added C/C++ style escape sequence processing. And fixed a couple OS/2 and
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 72
diff changeset
775 locale_text[current][x] = '\"';
2f339dd13496 Added C/C++ style escape sequence processing. And fixed a couple OS/2 and
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 72
diff changeset
776 break;
2f339dd13496 Added C/C++ style escape sequence processing. And fixed a couple OS/2 and
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 72
diff changeset
777 case '\'':
2f339dd13496 Added C/C++ style escape sequence processing. And fixed a couple OS/2 and
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 72
diff changeset
778 locale_text[current][x] = '\'';
2f339dd13496 Added C/C++ style escape sequence processing. And fixed a couple OS/2 and
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 72
diff changeset
779 break;
2f339dd13496 Added C/C++ style escape sequence processing. And fixed a couple OS/2 and
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 72
diff changeset
780 }
2f339dd13496 Added C/C++ style escape sequence processing. And fixed a couple OS/2 and
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 72
diff changeset
781 x++;
2f339dd13496 Added C/C++ style escape sequence processing. And fixed a couple OS/2 and
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 72
diff changeset
782 z++;
2f339dd13496 Added C/C++ style escape sequence processing. And fixed a couple OS/2 and
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 72
diff changeset
783 }
2f339dd13496 Added C/C++ style escape sequence processing. And fixed a couple OS/2 and
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 72
diff changeset
784 else
2f339dd13496 Added C/C++ style escape sequence processing. And fixed a couple OS/2 and
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 72
diff changeset
785 {
74
f794f2baabf2 Added codepage translation for Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 73
diff changeset
786 #ifdef __WIN32__
f794f2baabf2 Added codepage translation for Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 73
diff changeset
787 locale_text[current][x] = locale_convert(1252, text[z]);
f794f2baabf2 Added codepage translation for Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 73
diff changeset
788 #else
73
2f339dd13496 Added C/C++ style escape sequence processing. And fixed a couple OS/2 and
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 72
diff changeset
789 locale_text[current][x] = text[z];
74
f794f2baabf2 Added codepage translation for Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 73
diff changeset
790 #endif
73
2f339dd13496 Added C/C++ style escape sequence processing. And fixed a couple OS/2 and
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 72
diff changeset
791 x++;
2f339dd13496 Added C/C++ style escape sequence processing. And fixed a couple OS/2 and
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 72
diff changeset
792 }
2f339dd13496 Added C/C++ style escape sequence processing. And fixed a couple OS/2 and
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 72
diff changeset
793 }
2f339dd13496 Added C/C++ style escape sequence processing. And fixed a couple OS/2 and
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 72
diff changeset
794 }
72
ab77a22a2a36 Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 62
diff changeset
795 current++;
ab77a22a2a36 Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 62
diff changeset
796 }
ab77a22a2a36 Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 62
diff changeset
797 }
ab77a22a2a36 Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 62
diff changeset
798 }
ab77a22a2a36 Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 62
diff changeset
799 fclose(fp);
ab77a22a2a36 Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 62
diff changeset
800 }
ab77a22a2a36 Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 62
diff changeset
801 if(locale_text && count)
ab77a22a2a36 Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 62
diff changeset
802 {
ab77a22a2a36 Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 62
diff changeset
803 locale_count = count;
ab77a22a2a36 Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 62
diff changeset
804 locale_number = my_locale;
ab77a22a2a36 Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 62
diff changeset
805 return 1;
ab77a22a2a36 Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 62
diff changeset
806 }
ab77a22a2a36 Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 62
diff changeset
807 return 0;
ab77a22a2a36 Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 62
diff changeset
808 }
ab77a22a2a36 Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 62
diff changeset
809
ab77a22a2a36 Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 62
diff changeset
810 /* Retrieve a localized string if available */
176
4e3407df0e38 Specify calling convention for compat functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 172
diff changeset
811 char * API locale_string(char *default_text, int message)
72
ab77a22a2a36 Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 62
diff changeset
812 {
ab77a22a2a36 Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 62
diff changeset
813 if(locale_number > -1 && message < locale_count && message > -1 && locale_text[message])
ab77a22a2a36 Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 62
diff changeset
814 return locale_text[message];
ab77a22a2a36 Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 62
diff changeset
815 return default_text;
ab77a22a2a36 Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 62
diff changeset
816 }
ab77a22a2a36 Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 62
diff changeset
817