Mercurial > dwindows
annotate compat.c @ 966:d90222530bb9
Added code to detect the actual color depth of loaded bitmap files on Windows.
It seems that any LoadImage() loaded bitmaps are converted to the native screen depth...
So using the internal functions to check the depth is useless.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Tue, 03 May 2011 01:43:51 +0000 |
parents | 13debcad9757 |
children | 1c24949cf853 |
rev | line source |
---|---|
3 | 1 /* $Id$ */ |
2 | |
3 #include "compat.h" | |
697
830e1f3672b9
Added draining mechanism for threads that don't have run loops.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
649
diff
changeset
|
4 #include "dw.h" |
3 | 5 #if defined(__OS2__) || defined(__WIN32__) |
6 #include <share.h> | |
7 #endif | |
8 | |
433
f225f16bebbd
Compile fixes for MacOS X.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
176
diff
changeset
|
9 #if defined(__UNIX__) || defined(__MAC__) |
f225f16bebbd
Compile fixes for MacOS X.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
176
diff
changeset
|
10 #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
|
11 #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
|
12 #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
|
13 #include <sys/mount.h> |
42
eb003f77538c
Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
37
diff
changeset
|
14 #elif defined(__sun__) |
eb003f77538c
Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
37
diff
changeset
|
15 #include <sys/mnttab.h> |
eb003f77538c
Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
37
diff
changeset
|
16 #include <sys/param.h> |
eb003f77538c
Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
37
diff
changeset
|
17 #include <sys/mount.h> |
871
b15ad609365e
Solaris recommends using statvfs() instead of statfs()
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
870
diff
changeset
|
18 #include <sys/statvfs.h> |
36
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
19 #else |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
20 #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
|
21 #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
|
22 #endif |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
23 #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
|
24 #include <time.h> |
870
59c4fac42fb5
Need to use tv_sec if tv_nsec exceeds one second on Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
697
diff
changeset
|
25 #include <errno.h> |
36
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
26 |
441
b559c06a76c2
Implemented more functionality on MacOS and include the platform define
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
433
diff
changeset
|
27 #if defined(__UNIX__) || defined(__MAC__) |
37
360bc6a5f1c9
Sync with latest Dynamic Windows code.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
36
diff
changeset
|
28 void msleep(long period) |
360bc6a5f1c9
Sync with latest Dynamic Windows code.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
36
diff
changeset
|
29 { |
360bc6a5f1c9
Sync with latest Dynamic Windows code.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
36
diff
changeset
|
30 #ifdef __sun__ |
360bc6a5f1c9
Sync with latest Dynamic Windows code.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
36
diff
changeset
|
31 /* usleep() isn't threadsafe on Solaris */ |
360bc6a5f1c9
Sync with latest Dynamic Windows code.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
36
diff
changeset
|
32 struct timespec req; |
360bc6a5f1c9
Sync with latest Dynamic Windows code.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
36
diff
changeset
|
33 |
360bc6a5f1c9
Sync with latest Dynamic Windows code.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
36
diff
changeset
|
34 req.tv_sec = 0; |
870
59c4fac42fb5
Need to use tv_sec if tv_nsec exceeds one second on Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
697
diff
changeset
|
35 if(period >= 1000) |
59c4fac42fb5
Need to use tv_sec if tv_nsec exceeds one second on Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
697
diff
changeset
|
36 { |
59c4fac42fb5
Need to use tv_sec if tv_nsec exceeds one second on Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
697
diff
changeset
|
37 req.tv_sec = (int)(period / 1000); |
59c4fac42fb5
Need to use tv_sec if tv_nsec exceeds one second on Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
697
diff
changeset
|
38 period -= (req.tv_sec * 1000); |
59c4fac42fb5
Need to use tv_sec if tv_nsec exceeds one second on Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
697
diff
changeset
|
39 } |
42
eb003f77538c
Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
37
diff
changeset
|
40 req.tv_nsec = period * 10000000; |
870
59c4fac42fb5
Need to use tv_sec if tv_nsec exceeds one second on Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
697
diff
changeset
|
41 |
37
360bc6a5f1c9
Sync with latest Dynamic Windows code.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
36
diff
changeset
|
42 nanosleep(&req, NULL); |
360bc6a5f1c9
Sync with latest Dynamic Windows code.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
36
diff
changeset
|
43 #else |
360bc6a5f1c9
Sync with latest Dynamic Windows code.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
36
diff
changeset
|
44 usleep(period * 1000); |
872
13debcad9757
Another test fix at reported crash in dw_window_default().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
871
diff
changeset
|
45 #if defined(__MAC__) && !defined(GARBAGE_COLLECT) |
697
830e1f3672b9
Added draining mechanism for threads that don't have run loops.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
649
diff
changeset
|
46 _dw_pool_drain(); |
830e1f3672b9
Added draining mechanism for threads that don't have run loops.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
649
diff
changeset
|
47 #endif |
37
360bc6a5f1c9
Sync with latest Dynamic Windows code.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
36
diff
changeset
|
48 #endif |
360bc6a5f1c9
Sync with latest Dynamic Windows code.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
36
diff
changeset
|
49 } |
360bc6a5f1c9
Sync with latest Dynamic Windows code.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
36
diff
changeset
|
50 #endif |
360bc6a5f1c9
Sync with latest Dynamic Windows code.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
36
diff
changeset
|
51 |
176
4e3407df0e38
Specify calling convention for compat functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
172
diff
changeset
|
52 int API makedir(char *path) |
3 | 53 { |
172
0fc45e386376
Get Dynamic Windows building with Watcom.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
101
diff
changeset
|
54 #if defined(__IBMC__) || defined(__WATCOMC__) || (defined(__WIN32__) && !defined(__CYGWIN32__)) |
3 | 55 return mkdir(path); |
56 #else | |
57 return mkdir(path,S_IRWXU); | |
58 #endif | |
59 } | |
60 | |
580
d7c338ac926a
Sweeping changes to the compatibility module, moved all socket code out
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
557
diff
changeset
|
61 char * API vargs(char *buf, int len, char *format, ...) |
3 | 62 { |
63 va_list args; | |
64 | |
65 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
|
66 #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
|
67 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
|
68 #else |
d7c338ac926a
Sweeping changes to the compatibility module, moved all socket code out
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
557
diff
changeset
|
69 len = len; |
d7c338ac926a
Sweeping changes to the compatibility module, moved all socket code out
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
557
diff
changeset
|
70 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
|
71 #endif |
3 | 72 va_end(args); |
73 | |
580
d7c338ac926a
Sweeping changes to the compatibility module, moved all socket code out
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
557
diff
changeset
|
74 return buf; |
3 | 75 } |
76 | |
176
4e3407df0e38
Specify calling convention for compat functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
172
diff
changeset
|
77 long double API drivefree(int drive) |
3 | 78 { |
79 #if defined(__EMX__) || defined(__OS2__) | |
80 ULONG aulFSInfoBuf[40] = {0}; | |
81 APIRET rc = NO_ERROR; | |
82 | |
83 DosError(FERR_DISABLEHARDERR); | |
84 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
|
85 FSIL_ALLOC, |
432c39a4ff86
New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
86 (PVOID)aulFSInfoBuf, |
432c39a4ff86
New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
87 sizeof(aulFSInfoBuf)); |
3 | 88 |
89 DosError(FERR_ENABLEHARDERR); | |
90 if (rc != NO_ERROR) | |
91 return 0; | |
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)aulFSInfoBuf[3] * (double)aulFSInfoBuf[1] * (double)aulFSInfoBuf[4]); |
3 | 94 #elif defined(__WIN32__) || defined(WINNT) |
95 char buffer[10] = "C:\\"; | |
96 DWORD spc, bps, fc, tc; | |
97 | |
98 buffer[0] = drive + 'A' - 1; | |
99 | |
100 if(GetDiskFreeSpace(buffer, &spc, &bps, &fc, &tc) == 0) | |
101 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
|
102 |
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)spc*(double)bps*(double)fc); |
433
f225f16bebbd
Compile fixes for MacOS X.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
176
diff
changeset
|
104 #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
|
105 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
|
106 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
|
107 |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
108 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
|
109 |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
110 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
|
111 { |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
112 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
|
113 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
|
114 index++; |
36
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
115 } |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
116 return 0; |
42
eb003f77538c
Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
37
diff
changeset
|
117 #elif defined(__sun__) |
eb003f77538c
Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
37
diff
changeset
|
118 FILE *fp = fopen("/etc/mnttab", "r"); |
eb003f77538c
Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
37
diff
changeset
|
119 struct mnttab mnt; |
871
b15ad609365e
Solaris recommends using statvfs() instead of statfs()
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
870
diff
changeset
|
120 struct statvfs sfs; |
42
eb003f77538c
Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
37
diff
changeset
|
121 int index = 1; |
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 if(fp) |
eb003f77538c
Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
37
diff
changeset
|
124 { |
eb003f77538c
Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
37
diff
changeset
|
125 while((getmntent(fp, &mnt) == 0)) |
eb003f77538c
Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
37
diff
changeset
|
126 { |
eb003f77538c
Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
37
diff
changeset
|
127 if(index == drive) |
eb003f77538c
Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
37
diff
changeset
|
128 { |
101
a5da1ac53b34
Use long double instead of long long for drivesize and drivefree.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
100
diff
changeset
|
129 long double size = 0; |
42
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 if(mnt.mnt_mountp) |
eb003f77538c
Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
37
diff
changeset
|
132 { |
871
b15ad609365e
Solaris recommends using statvfs() instead of statfs()
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
870
diff
changeset
|
133 if(!statvfs(mnt.mnt_mountp, &sfs)) |
649
3e2ada9ee0ac
Switched to using reentrant version of getmntent on Linux.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
647
diff
changeset
|
134 { |
871
b15ad609365e
Solaris recommends using statvfs() instead of statfs()
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
870
diff
changeset
|
135 size = (long double)((double)sfs.f_bsize * (double)sfs.f_bavail); |
649
3e2ada9ee0ac
Switched to using reentrant version of getmntent on Linux.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
647
diff
changeset
|
136 } |
42
eb003f77538c
Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
37
diff
changeset
|
137 } |
eb003f77538c
Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
37
diff
changeset
|
138 fclose(fp); |
eb003f77538c
Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
37
diff
changeset
|
139 return size; |
eb003f77538c
Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
37
diff
changeset
|
140 } |
eb003f77538c
Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
37
diff
changeset
|
141 index++; |
eb003f77538c
Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
37
diff
changeset
|
142 } |
eb003f77538c
Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
37
diff
changeset
|
143 fclose(fp); |
eb003f77538c
Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
37
diff
changeset
|
144 } |
eb003f77538c
Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
37
diff
changeset
|
145 return 0; |
3 | 146 #else |
36
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
147 FILE *fp = setmntent(MOUNTED, "r"); |
649
3e2ada9ee0ac
Switched to using reentrant version of getmntent on Linux.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
647
diff
changeset
|
148 struct mntent mnt; |
36
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
149 struct statfs sfs; |
649
3e2ada9ee0ac
Switched to using reentrant version of getmntent on Linux.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
647
diff
changeset
|
150 char buffer[1024]; |
36
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
151 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
|
152 |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
153 if(fp) |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
154 { |
649
3e2ada9ee0ac
Switched to using reentrant version of getmntent on Linux.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
647
diff
changeset
|
155 while(getmntent_r(fp, &mnt, buffer, sizeof(buffer))) |
36
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
156 { |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
157 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
|
158 { |
101
a5da1ac53b34
Use long double instead of long long for drivesize and drivefree.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
100
diff
changeset
|
159 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
|
160 |
649
3e2ada9ee0ac
Switched to using reentrant version of getmntent on Linux.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
647
diff
changeset
|
161 if(mnt.mnt_dir) |
36
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
162 { |
649
3e2ada9ee0ac
Switched to using reentrant version of getmntent on Linux.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
647
diff
changeset
|
163 if(!statfs(mnt.mnt_dir, &sfs)) |
3e2ada9ee0ac
Switched to using reentrant version of getmntent on Linux.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
647
diff
changeset
|
164 { |
3e2ada9ee0ac
Switched to using reentrant version of getmntent on Linux.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
647
diff
changeset
|
165 size = (long double)((double)sfs.f_bsize * (double)sfs.f_bavail); |
3e2ada9ee0ac
Switched to using reentrant version of getmntent on Linux.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
647
diff
changeset
|
166 } |
36
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
167 } |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
168 endmntent(fp); |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
169 return size; |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
170 } |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
171 index++; |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
172 } |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
173 endmntent(fp); |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
174 } |
3 | 175 return 0; |
176 #endif | |
177 } | |
178 | |
176
4e3407df0e38
Specify calling convention for compat functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
172
diff
changeset
|
179 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
|
180 { |
432c39a4ff86
New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
181 #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
|
182 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
|
183 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
|
184 |
432c39a4ff86
New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
185 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
|
186 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
|
187 FSIL_ALLOC, |
432c39a4ff86
New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
188 (PVOID)aulFSInfoBuf, |
432c39a4ff86
New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
189 sizeof(aulFSInfoBuf)); |
432c39a4ff86
New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
190 |
432c39a4ff86
New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
191 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
|
192 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
|
193 return 0; |
432c39a4ff86
New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
194 |
101
a5da1ac53b34
Use long double instead of long long for drivesize and drivefree.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
100
diff
changeset
|
195 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
|
196 #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
|
197 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
|
198 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
|
199 |
432c39a4ff86
New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
200 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
|
201 |
432c39a4ff86
New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
202 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
|
203 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
|
204 |
101
a5da1ac53b34
Use long double instead of long long for drivesize and drivefree.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
100
diff
changeset
|
205 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
|
206 #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
|
207 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
|
208 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
|
209 |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
210 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
|
211 |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
212 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
|
213 { |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
214 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
|
215 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
|
216 index++; |
36
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
217 } |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
218 return 0; |
42
eb003f77538c
Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
37
diff
changeset
|
219 #elif defined(__sun__) |
eb003f77538c
Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
37
diff
changeset
|
220 FILE *fp = fopen("/etc/mnttab", "r"); |
eb003f77538c
Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
37
diff
changeset
|
221 struct mnttab mnt; |
871
b15ad609365e
Solaris recommends using statvfs() instead of statfs()
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
870
diff
changeset
|
222 struct statvfs sfs; |
42
eb003f77538c
Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
37
diff
changeset
|
223 int index = 1; |
eb003f77538c
Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
37
diff
changeset
|
224 |
eb003f77538c
Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
37
diff
changeset
|
225 if(fp) |
eb003f77538c
Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
37
diff
changeset
|
226 { |
eb003f77538c
Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
37
diff
changeset
|
227 while(getmntent(fp, &mnt) == 0) |
eb003f77538c
Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
37
diff
changeset
|
228 { |
eb003f77538c
Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
37
diff
changeset
|
229 if(index == drive) |
eb003f77538c
Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
37
diff
changeset
|
230 { |
101
a5da1ac53b34
Use long double instead of long long for drivesize and drivefree.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
100
diff
changeset
|
231 long double size = 0; |
42
eb003f77538c
Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
37
diff
changeset
|
232 |
eb003f77538c
Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
37
diff
changeset
|
233 if(mnt.mnt_mountp) |
eb003f77538c
Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
37
diff
changeset
|
234 { |
871
b15ad609365e
Solaris recommends using statvfs() instead of statfs()
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
870
diff
changeset
|
235 if(!statvfs(mnt.mnt_mountp, &sfs)) |
649
3e2ada9ee0ac
Switched to using reentrant version of getmntent on Linux.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
647
diff
changeset
|
236 { |
3e2ada9ee0ac
Switched to using reentrant version of getmntent on Linux.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
647
diff
changeset
|
237 size = (long double)((double)sfs.f_bsize * (double)sfs.f_blocks); |
3e2ada9ee0ac
Switched to using reentrant version of getmntent on Linux.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
647
diff
changeset
|
238 } |
42
eb003f77538c
Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
37
diff
changeset
|
239 } |
eb003f77538c
Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
37
diff
changeset
|
240 fclose(fp); |
eb003f77538c
Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
37
diff
changeset
|
241 return size; |
eb003f77538c
Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
37
diff
changeset
|
242 } |
eb003f77538c
Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
37
diff
changeset
|
243 index++; |
eb003f77538c
Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
37
diff
changeset
|
244 } |
eb003f77538c
Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
37
diff
changeset
|
245 fclose(fp); |
eb003f77538c
Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
37
diff
changeset
|
246 } |
eb003f77538c
Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
37
diff
changeset
|
247 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
|
248 #else |
36
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
249 FILE *fp = setmntent(MOUNTED, "r"); |
649
3e2ada9ee0ac
Switched to using reentrant version of getmntent on Linux.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
647
diff
changeset
|
250 struct mntent mnt; |
3e2ada9ee0ac
Switched to using reentrant version of getmntent on Linux.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
647
diff
changeset
|
251 char buffer[1024]; |
36
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
252 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
|
253 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
|
254 |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
255 if(fp) |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
256 { |
649
3e2ada9ee0ac
Switched to using reentrant version of getmntent on Linux.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
647
diff
changeset
|
257 while(getmntent_r(fp, &mnt, buffer, sizeof(buffer))) |
36
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
258 { |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
259 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
|
260 { |
101
a5da1ac53b34
Use long double instead of long long for drivesize and drivefree.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
100
diff
changeset
|
261 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
|
262 |
649
3e2ada9ee0ac
Switched to using reentrant version of getmntent on Linux.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
647
diff
changeset
|
263 if(mnt.mnt_dir) |
36
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
264 { |
649
3e2ada9ee0ac
Switched to using reentrant version of getmntent on Linux.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
647
diff
changeset
|
265 if(!statfs(mnt.mnt_dir, &sfs)) |
3e2ada9ee0ac
Switched to using reentrant version of getmntent on Linux.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
647
diff
changeset
|
266 { |
3e2ada9ee0ac
Switched to using reentrant version of getmntent on Linux.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
647
diff
changeset
|
267 size = (long double)((double)sfs.f_bsize * (double)sfs.f_blocks); |
3e2ada9ee0ac
Switched to using reentrant version of getmntent on Linux.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
647
diff
changeset
|
268 } |
36
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
269 } |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
270 endmntent(fp); |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
271 return size; |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
272 } |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
273 index++; |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
274 } |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
275 endmntent(fp); |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
276 } |
35
432c39a4ff86
New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
277 return 0; |
432c39a4ff86
New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
278 #endif |
432c39a4ff86
New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
279 } |
432c39a4ff86
New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
280 |
176
4e3407df0e38
Specify calling convention for compat functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
172
diff
changeset
|
281 int API isdrive(int drive) |
3 | 282 { |
283 #if defined(__EMX__) || defined(__OS2__) | |
284 APIRET rc = NO_ERROR; | |
285 FSINFO volinfo; | |
286 | |
287 DosError(FERR_DISABLEHARDERR); | |
288 rc = DosQueryFSInfo(drive, | |
289 FSIL_VOLSER, | |
290 (PVOID)&volinfo, | |
291 sizeof(FSINFO)); | |
292 | |
293 DosError(FERR_ENABLEHARDERR); | |
294 if (rc == NO_ERROR) | |
295 return 1; | |
296 | |
297 #elif defined(__WIN32__) || defined(WINNT) | |
298 char buffer[10] = "C:\\", volname[100]; | |
299 DWORD spc, bps, fc; | |
300 | |
301 buffer[0] = drive + 'A' - 1; | |
302 | |
303 if(GetVolumeInformation(buffer, volname, 100, &spc, &bps, &fc, NULL, 0) != 0) | |
304 return 1; | |
433
f225f16bebbd
Compile fixes for MacOS X.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
176
diff
changeset
|
305 #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
|
306 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
|
307 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
|
308 |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
309 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
|
310 |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
311 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
|
312 { |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
313 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
|
314 return 1; |
98
c0388006bb0d
Fixes for FreeBSD.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
74
diff
changeset
|
315 index++; |
36
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
316 } |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
317 return 0; |
42
eb003f77538c
Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
37
diff
changeset
|
318 #elif defined(__sun__) |
eb003f77538c
Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
37
diff
changeset
|
319 FILE *fp = fopen("/etc/mnttab", "r"); |
eb003f77538c
Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
37
diff
changeset
|
320 struct mnttab mnt; |
871
b15ad609365e
Solaris recommends using statvfs() instead of statfs()
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
870
diff
changeset
|
321 struct statvfs sfs; |
42
eb003f77538c
Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
37
diff
changeset
|
322 int index = 1; |
eb003f77538c
Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
37
diff
changeset
|
323 |
eb003f77538c
Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
37
diff
changeset
|
324 if(fp) |
eb003f77538c
Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
37
diff
changeset
|
325 { |
eb003f77538c
Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
37
diff
changeset
|
326 while(getmntent(fp, &mnt) == 0) |
eb003f77538c
Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
37
diff
changeset
|
327 { |
eb003f77538c
Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
37
diff
changeset
|
328 if(index == drive) |
eb003f77538c
Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
37
diff
changeset
|
329 { |
eb003f77538c
Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
37
diff
changeset
|
330 fclose(fp); |
eb003f77538c
Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
37
diff
changeset
|
331 if(mnt.mnt_mountp) |
eb003f77538c
Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
37
diff
changeset
|
332 { |
871
b15ad609365e
Solaris recommends using statvfs() instead of statfs()
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
870
diff
changeset
|
333 if(!statvfs(mnt.mnt_mountp, &sfs) && sfs.f_blocks) |
42
eb003f77538c
Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
37
diff
changeset
|
334 return 1; |
eb003f77538c
Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
37
diff
changeset
|
335 } |
eb003f77538c
Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
37
diff
changeset
|
336 return 0; |
eb003f77538c
Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
37
diff
changeset
|
337 } |
eb003f77538c
Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
37
diff
changeset
|
338 index++; |
eb003f77538c
Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
37
diff
changeset
|
339 } |
eb003f77538c
Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
37
diff
changeset
|
340 fclose(fp); |
eb003f77538c
Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
37
diff
changeset
|
341 } |
36
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
342 #else |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
343 FILE *fp = setmntent(MOUNTED, "r"); |
649
3e2ada9ee0ac
Switched to using reentrant version of getmntent on Linux.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
647
diff
changeset
|
344 struct mntent mnt; |
3e2ada9ee0ac
Switched to using reentrant version of getmntent on Linux.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
647
diff
changeset
|
345 char buffer[1024]; |
36
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
346 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
|
347 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
|
348 |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
349 if(fp) |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
350 { |
649
3e2ada9ee0ac
Switched to using reentrant version of getmntent on Linux.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
647
diff
changeset
|
351 while(getmntent_r(fp, &mnt, buffer, sizeof(buffer))) |
36
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
352 { |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
353 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
|
354 { |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
355 endmntent(fp); |
649
3e2ada9ee0ac
Switched to using reentrant version of getmntent on Linux.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
647
diff
changeset
|
356 if(mnt.mnt_dir) |
36
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
357 { |
649
3e2ada9ee0ac
Switched to using reentrant version of getmntent on Linux.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
647
diff
changeset
|
358 if(!statfs(mnt.mnt_dir, &sfs) && sfs.f_blocks) |
3e2ada9ee0ac
Switched to using reentrant version of getmntent on Linux.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
647
diff
changeset
|
359 { |
36
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
360 return 1; |
649
3e2ada9ee0ac
Switched to using reentrant version of getmntent on Linux.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
647
diff
changeset
|
361 } |
36
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 return 0; |
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 index++; |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
366 } |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
367 endmntent(fp); |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
368 } |
3 | 369 #endif |
370 return 0; | |
371 } | |
372 | |
176
4e3407df0e38
Specify calling convention for compat functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
172
diff
changeset
|
373 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
|
374 { |
433
f225f16bebbd
Compile fixes for MacOS X.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
176
diff
changeset
|
375 #if defined(__UNIX__) || defined(__MAC__) |
f225f16bebbd
Compile fixes for MacOS X.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
176
diff
changeset
|
376 #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
|
377 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
|
378 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
|
379 |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
380 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
|
381 |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
382 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
|
383 |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
384 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
|
385 { |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
386 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
|
387 strncpy(buf, fsp->f_mntonname, len); |
98
c0388006bb0d
Fixes for FreeBSD.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
74
diff
changeset
|
388 index++; |
36
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
389 } |
42
eb003f77538c
Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
37
diff
changeset
|
390 #elif defined(__sun__) |
eb003f77538c
Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
37
diff
changeset
|
391 FILE *fp = fopen("/etc/mnttab", "r"); |
eb003f77538c
Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
37
diff
changeset
|
392 struct mnttab mnt; |
eb003f77538c
Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
37
diff
changeset
|
393 int index = 1; |
eb003f77538c
Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
37
diff
changeset
|
394 |
eb003f77538c
Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
37
diff
changeset
|
395 strncpy(buf, "Unknown", len); |
eb003f77538c
Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
37
diff
changeset
|
396 |
eb003f77538c
Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
37
diff
changeset
|
397 if(fp) |
eb003f77538c
Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
37
diff
changeset
|
398 { |
eb003f77538c
Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
37
diff
changeset
|
399 while(getmntent(fp, &mnt) == 0) |
eb003f77538c
Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
37
diff
changeset
|
400 { |
eb003f77538c
Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
37
diff
changeset
|
401 if(index == drive && mnt.mnt_mountp) |
eb003f77538c
Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
37
diff
changeset
|
402 strncpy(buf, mnt.mnt_mountp, len); |
eb003f77538c
Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
37
diff
changeset
|
403 index++; |
eb003f77538c
Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
37
diff
changeset
|
404 } |
eb003f77538c
Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
37
diff
changeset
|
405 fclose(fp); |
eb003f77538c
Added the filesystem functions for Solaris.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
37
diff
changeset
|
406 } |
36
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
407 #else |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
408 FILE *fp = setmntent(MOUNTED, "r"); |
649
3e2ada9ee0ac
Switched to using reentrant version of getmntent on Linux.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
647
diff
changeset
|
409 struct mntent mnt; |
3e2ada9ee0ac
Switched to using reentrant version of getmntent on Linux.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
647
diff
changeset
|
410 char buffer[1024]; |
36
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
411 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
|
412 |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
413 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
|
414 |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
415 if(fp) |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
416 { |
649
3e2ada9ee0ac
Switched to using reentrant version of getmntent on Linux.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
647
diff
changeset
|
417 while(getmntent_r(fp, &mnt, buffer, sizeof(buffer))) |
36
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
418 { |
649
3e2ada9ee0ac
Switched to using reentrant version of getmntent on Linux.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
647
diff
changeset
|
419 if(index == drive && mnt.mnt_dir) |
3e2ada9ee0ac
Switched to using reentrant version of getmntent on Linux.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
647
diff
changeset
|
420 strncpy(buf, mnt.mnt_dir, len); |
36
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
421 index++; |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
422 } |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
423 endmntent(fp); |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
424 } |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
425 #endif |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
426 #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
|
427 /* 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
|
428 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
|
429 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
|
430 #else |
37
360bc6a5f1c9
Sync with latest Dynamic Windows code.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
36
diff
changeset
|
431 _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
|
432 #endif |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
433 } |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
434 |
176
4e3407df0e38
Specify calling convention for compat functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
172
diff
changeset
|
435 void API setfileinfo(char *filename, char *url, char *logfile) |
3 | 436 { |
437 time_t ltime; | |
438 struct tm *tm; | |
439 char buffer[200], timebuf[200]; | |
440 #ifdef __OS2__ | |
441 const unsigned fea2listsize = 6000; | |
442 char *pData; | |
443 EAOP2 eaop2; | |
444 PFEA2 pFEA2; | |
445 #else | |
446 FILE *urlfile; | |
447 #endif | |
448 | |
449 ltime = time(NULL); | |
450 | |
451 tm = localtime(<ime); | |
452 | |
453 strftime(timebuf, 200, "%c", tm); | |
454 | |
455 sprintf(buffer, "%s %s", url, timebuf); | |
456 | |
457 #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
|
458 logfile = logfile; |
3 | 459 eaop2.fpGEA2List = 0; |
460 eaop2.fpFEA2List = (PFEA2LIST)malloc(fea2listsize); | |
461 pFEA2 = &eaop2.fpFEA2List->list[0]; | |
462 | |
463 pFEA2->fEA = 0; | |
464 /* .COMMENTS is 9 characters long */ | |
465 pFEA2->cbName = 9; | |
466 | |
467 /* space for the type and length field. */ | |
468 pFEA2->cbValue = strlen(buffer)+2*sizeof(USHORT); | |
469 | |
470 strcpy(pFEA2->szName, ".COMMENTS"); | |
471 pData = pFEA2->szName+pFEA2->cbName+1; | |
472 /* data begins at first byte after the name */ | |
473 | |
474 *(USHORT*)pData = EAT_ASCII; /* type */ | |
475 *((USHORT*)pData+1) = strlen(buffer); /* length */ | |
476 strcpy(pData+2*sizeof(USHORT), buffer);/* content */ | |
477 | |
478 pFEA2->oNextEntryOffset = 0; | |
479 | |
480 eaop2.fpFEA2List->cbList = ((PCHAR)pData+2*sizeof(USHORT)+ | |
481 pFEA2->cbValue)-((PCHAR)eaop2.fpFEA2List); | |
482 | |
483 DosSetPathInfo(filename, | |
484 FIL_QUERYEASIZE, | |
485 &eaop2, | |
486 sizeof(eaop2), | |
487 0); | |
488 | |
489 free((void *)eaop2.fpFEA2List); | |
490 #else | |
491 | |
53
8add9a616d0e
Added a log filename parameter to setfileinfo().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
47
diff
changeset
|
492 if((urlfile = fopen(logfile, "a"))!=NULL) |
3 | 493 { |
494 fprintf(urlfile, "%s\n", buffer); | |
495 fclose(urlfile); | |
496 } | |
497 #endif | |
498 } | |
499 | |
500 #if defined(__OS2__) || defined(__WIN32__) | |
501 typedef struct _fsinfo { | |
502 FILE *fp; | |
503 int fd; | |
504 } FSInfo; | |
505 | |
506 FSInfo *FSIRoot = NULL; | |
507 | |
508 #define FSI_MAX 100 | |
509 #endif | |
510 | |
511 /* Sharable fopen() and fclose() calls. */ | |
176
4e3407df0e38
Specify calling convention for compat functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
172
diff
changeset
|
512 FILE * API fsopen(char *path, char *modes) |
3 | 513 { |
172
0fc45e386376
Get Dynamic Windows building with Watcom.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
101
diff
changeset
|
514 #if (defined(__OS2__) && !defined(__WATCOMC__)) || defined(__WIN32__) |
3 | 515 int z; |
516 | |
517 if(!FSIRoot) | |
518 FSIRoot = calloc(sizeof(struct _fsinfo), FSI_MAX); | |
519 | |
520 for(z=0;z<FSI_MAX;z++) | |
521 { | |
522 if(FSIRoot[z].fd < 1) | |
523 { | |
524 int s, sopenmode = 0, wrmode = 0; | |
525 | |
526 /* Check the flags passed */ | |
527 for(s=0;s<3;s++) | |
528 { | |
529 if(modes[s] == 'b') | |
530 sopenmode |= O_BINARY; | |
531 if(modes[s] == 'r') | |
532 wrmode |= O_RDONLY; | |
533 if(modes[s] == 'w') | |
534 wrmode |= O_WRONLY; | |
535 if(modes[s] == 'a') | |
536 sopenmode |= O_APPEND; | |
537 if(modes[s] == 't') | |
538 sopenmode |= O_TEXT; | |
539 } | |
540 | |
541 /* Check the read/write request */ | |
542 if((wrmode & O_RDONLY) && (wrmode & O_WRONLY)) | |
543 sopenmode |= O_RDWR; | |
544 else | |
545 sopenmode |= wrmode; | |
546 FSIRoot[z].fd = _sopen(path, sopenmode, SH_DENYNO, S_IREAD|S_IWRITE); | |
547 if(FSIRoot[z].fd > 0) | |
548 { | |
549 FSIRoot[z].fp = fdopen(FSIRoot[z].fd, modes); | |
550 | |
551 return FSIRoot[z].fp; | |
552 } | |
553 } | |
554 } | |
555 return NULL; | |
556 #else | |
557 return fopen(path, modes); | |
558 #endif | |
559 } | |
560 | |
176
4e3407df0e38
Specify calling convention for compat functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
172
diff
changeset
|
561 int API fsclose(FILE *fp) |
3 | 562 { |
563 #if defined(__OS2__) || defined(__WIN32__) | |
564 if(FSIRoot) | |
565 { | |
566 | |
567 int z; | |
568 for(z=0;z<FSI_MAX;z++) | |
569 { | |
570 if(fp == FSIRoot[z].fp) | |
571 { | |
572 int ret = fclose(fp); | |
573 close(FSIRoot[z].fd); | |
574 FSIRoot[z].fd = 0; | |
575 FSIRoot[z].fp = NULL; | |
576 return ret; | |
577 } | |
578 } | |
579 } | |
580 #endif | |
581 return fclose(fp); | |
582 } | |
583 | |
176
4e3407df0e38
Specify calling convention for compat functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
172
diff
changeset
|
584 char * API fsgets(char *str, int size, FILE *stream) |
3 | 585 { |
586 return fgets(str, size, stream); | |
587 } | |
588 | |
176
4e3407df0e38
Specify calling convention for compat functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
172
diff
changeset
|
589 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
|
590 { |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
591 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
|
592 } |
72
ab77a22a2a36
Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
62
diff
changeset
|
593 |
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
|
594 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
|
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 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
|
597 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
|
598 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
|
599 |
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 /* 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
|
601 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
|
602 { |
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 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
|
604 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
|
605 } |
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 /* 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
|
607 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
|
608 { |
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 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
|
610 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
|
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 /* 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
|
613 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
|
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 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
|
616 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
|
617 } |
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 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
|
619 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
|
620 |
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 /* 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
|
622 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
|
623 /* 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
|
624 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
|
625 } |
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 /* 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
|
628 * 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
|
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 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
|
631 { |
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 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
|
633 { |
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 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
|
635 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
|
636 |
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 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
|
638 { |
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(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
|
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 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
|
642 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
|
643 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
|
644 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
|
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 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
|
648 } |
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 |
1a210e2f214b
Added a bunch of support routines I now own due to the settlement
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
485
diff
changeset
|
651 /* |
1a210e2f214b
Added a bunch of support routines I now own due to the settlement
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
485
diff
changeset
|
652 * 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
|
653 * 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
|
654 * 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
|
655 * 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
|
656 * -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
|
657 */ |
1a210e2f214b
Added a bunch of support routines I now own due to the settlement
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
485
diff
changeset
|
658 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
|
659 { |
1a210e2f214b
Added a bunch of support routines I now own due to the settlement
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
485
diff
changeset
|
660 #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
|
661 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
|
662 { |
1a210e2f214b
Added a bunch of support routines I now own due to the settlement
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
485
diff
changeset
|
663 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
|
664 { |
1a210e2f214b
Added a bunch of support routines I now own due to the settlement
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
485
diff
changeset
|
665 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
|
666 _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
|
667 } |
1a210e2f214b
Added a bunch of support routines I now own due to the settlement
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
485
diff
changeset
|
668 } |
1a210e2f214b
Added a bunch of support routines I now own due to the settlement
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
485
diff
changeset
|
669 #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
|
670 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
|
671 } |
1a210e2f214b
Added a bunch of support routines I now own due to the settlement
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
485
diff
changeset
|
672 |
72
ab77a22a2a36
Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
62
diff
changeset
|
673 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
|
674 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
|
675 |
647
f09977bc9b5c
Fixed building with Visual Studio 2008.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
580
diff
changeset
|
676 void _compat_free_locale(void) |
72
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 if(locale_text) |
ab77a22a2a36
Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
62
diff
changeset
|
679 { |
ab77a22a2a36
Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
62
diff
changeset
|
680 int z; |
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 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
|
683 { |
ab77a22a2a36
Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
62
diff
changeset
|
684 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
|
685 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
|
686 } |
ab77a22a2a36
Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
62
diff
changeset
|
687 free(locale_text); |
ab77a22a2a36
Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
62
diff
changeset
|
688 locale_text = NULL; |
ab77a22a2a36
Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
62
diff
changeset
|
689 } |
ab77a22a2a36
Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
62
diff
changeset
|
690 } |
ab77a22a2a36
Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
62
diff
changeset
|
691 |
ab77a22a2a36
Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
62
diff
changeset
|
692 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
|
693 { |
ab77a22a2a36
Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
62
diff
changeset
|
694 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
|
695 |
ab77a22a2a36
Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
62
diff
changeset
|
696 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
|
697 { |
ab77a22a2a36
Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
62
diff
changeset
|
698 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
|
699 { |
ab77a22a2a36
Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
62
diff
changeset
|
700 buf[z] = 0; |
ab77a22a2a36
Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
62
diff
changeset
|
701 return; |
ab77a22a2a36
Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
62
diff
changeset
|
702 } |
ab77a22a2a36
Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
62
diff
changeset
|
703 } |
ab77a22a2a36
Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
62
diff
changeset
|
704 } |
ab77a22a2a36
Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
62
diff
changeset
|
705 |
74
f794f2baabf2
Added codepage translation for Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
73
diff
changeset
|
706 #ifdef __WIN32__ |
f794f2baabf2
Added codepage translation for Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
73
diff
changeset
|
707 #define LOCALE_CHARACTERS 62 |
f794f2baabf2
Added codepage translation for Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
73
diff
changeset
|
708 static char locale_table[LOCALE_CHARACTERS * 2] = { |
f794f2baabf2
Added codepage translation for Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
73
diff
changeset
|
709 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
|
710 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
|
711 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
|
712 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
|
713 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
|
714 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
|
715 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
|
716 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
|
717 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
|
718 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
|
719 0xfe, 0xe7, 0xff, 0x9e |
f794f2baabf2
Added codepage translation for Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
73
diff
changeset
|
720 |
f794f2baabf2
Added codepage translation for Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
73
diff
changeset
|
721 }; |
f794f2baabf2
Added codepage translation for Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
73
diff
changeset
|
722 |
f794f2baabf2
Added codepage translation for Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
73
diff
changeset
|
723 char locale_convert(int codepage, char c) |
f794f2baabf2
Added codepage translation for Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
73
diff
changeset
|
724 { |
f794f2baabf2
Added codepage translation for Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
73
diff
changeset
|
725 int z; |
f794f2baabf2
Added codepage translation for Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
73
diff
changeset
|
726 |
f794f2baabf2
Added codepage translation for Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
73
diff
changeset
|
727 for(z=0;z<LOCALE_CHARACTERS;z++) |
f794f2baabf2
Added codepage translation for Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
73
diff
changeset
|
728 { |
f794f2baabf2
Added codepage translation for Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
73
diff
changeset
|
729 if(locale_table[(z*2)+1] == c) |
f794f2baabf2
Added codepage translation for Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
73
diff
changeset
|
730 return locale_table[z*2]; |
f794f2baabf2
Added codepage translation for Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
73
diff
changeset
|
731 } |
f794f2baabf2
Added codepage translation for Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
73
diff
changeset
|
732 return c; |
f794f2baabf2
Added codepage translation for Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
73
diff
changeset
|
733 } |
f794f2baabf2
Added codepage translation for Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
73
diff
changeset
|
734 #endif |
f794f2baabf2
Added codepage translation for Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
73
diff
changeset
|
735 |
72
ab77a22a2a36
Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
62
diff
changeset
|
736 /* 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
|
737 * 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
|
738 */ |
176
4e3407df0e38
Specify calling convention for compat functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
172
diff
changeset
|
739 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
|
740 { |
ab77a22a2a36
Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
62
diff
changeset
|
741 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
|
742 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
|
743 int count = 0; |
ab77a22a2a36
Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
62
diff
changeset
|
744 |
647
f09977bc9b5c
Fixed building with Visual Studio 2008.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
580
diff
changeset
|
745 _compat_free_locale(); |
72
ab77a22a2a36
Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
62
diff
changeset
|
746 |
ab77a22a2a36
Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
62
diff
changeset
|
747 if(fp) |
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 |
ab77a22a2a36
Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
62
diff
changeset
|
750 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
|
751 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
|
752 { |
ab77a22a2a36
Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
62
diff
changeset
|
753 int current = -1; |
ab77a22a2a36
Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
62
diff
changeset
|
754 |
ab77a22a2a36
Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
62
diff
changeset
|
755 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
|
756 |
ab77a22a2a36
Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
62
diff
changeset
|
757 while(!feof(fp)) |
ab77a22a2a36
Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
62
diff
changeset
|
758 { |
ab77a22a2a36
Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
62
diff
changeset
|
759 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
|
760 _stripcrlf(text); |
ab77a22a2a36
Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
62
diff
changeset
|
761 |
ab77a22a2a36
Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
62
diff
changeset
|
762 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
|
763 { |
ab77a22a2a36
Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
62
diff
changeset
|
764 if(current > -1) |
ab77a22a2a36
Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
62
diff
changeset
|
765 { |
ab77a22a2a36
Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
62
diff
changeset
|
766 fclose(fp); |
ab77a22a2a36
Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
62
diff
changeset
|
767 locale_count = count; |
ab77a22a2a36
Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
62
diff
changeset
|
768 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
|
769 return 1; |
ab77a22a2a36
Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
62
diff
changeset
|
770 } |
ab77a22a2a36
Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
62
diff
changeset
|
771 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
|
772 current = 0; |
ab77a22a2a36
Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
62
diff
changeset
|
773 } |
ab77a22a2a36
Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
62
diff
changeset
|
774 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
|
775 { |
ab77a22a2a36
Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
62
diff
changeset
|
776 /* 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
|
777 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
|
778 { |
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 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
|
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 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
|
782 |
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 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
|
784 { |
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 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
|
786 || 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
|
787 { |
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
|
788 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
|
789 { |
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
|
790 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
|
791 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
|
792 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
|
793 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
|
794 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
|
795 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
|
796 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
|
797 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
|
798 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
|
799 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
|
800 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
|
801 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
|
802 } |
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
|
803 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
|
804 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
|
805 } |
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
|
806 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
|
807 { |
74
f794f2baabf2
Added codepage translation for Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
73
diff
changeset
|
808 #ifdef __WIN32__ |
f794f2baabf2
Added codepage translation for Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
73
diff
changeset
|
809 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
|
810 #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
|
811 locale_text[current][x] = text[z]; |
74
f794f2baabf2
Added codepage translation for Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
73
diff
changeset
|
812 #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
|
813 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
|
814 } |
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
|
815 } |
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
|
816 } |
72
ab77a22a2a36
Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
62
diff
changeset
|
817 current++; |
ab77a22a2a36
Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
62
diff
changeset
|
818 } |
ab77a22a2a36
Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
62
diff
changeset
|
819 } |
ab77a22a2a36
Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
62
diff
changeset
|
820 } |
ab77a22a2a36
Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
62
diff
changeset
|
821 fclose(fp); |
ab77a22a2a36
Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
62
diff
changeset
|
822 } |
ab77a22a2a36
Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
62
diff
changeset
|
823 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
|
824 { |
ab77a22a2a36
Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
62
diff
changeset
|
825 locale_count = count; |
ab77a22a2a36
Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
62
diff
changeset
|
826 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
|
827 return 1; |
ab77a22a2a36
Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
62
diff
changeset
|
828 } |
ab77a22a2a36
Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
62
diff
changeset
|
829 return 0; |
ab77a22a2a36
Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
62
diff
changeset
|
830 } |
ab77a22a2a36
Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
62
diff
changeset
|
831 |
ab77a22a2a36
Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
62
diff
changeset
|
832 /* Retrieve a localized string if available */ |
176
4e3407df0e38
Specify calling convention for compat functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
172
diff
changeset
|
833 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
|
834 { |
ab77a22a2a36
Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
62
diff
changeset
|
835 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
|
836 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
|
837 return default_text; |
ab77a22a2a36
Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
62
diff
changeset
|
838 } |
ab77a22a2a36
Added localization APIs as well as some miscellaneous bug fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
62
diff
changeset
|
839 |