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