Mercurial > dwindows
annotate compat.c @ 36:cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
some GTK fixes.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Mon, 17 Sep 2001 09:15:40 +0000 |
parents | 432c39a4ff86 |
children | 360bc6a5f1c9 |
rev | line source |
---|---|
3 | 1 /* $Id$ */ |
2 | |
3 #include "compat.h" | |
4 #if defined(__OS2__) || defined(__WIN32__) | |
5 #include <share.h> | |
6 #endif | |
7 | |
36
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
8 #ifdef __UNIX__ |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
9 #ifdef __FreeBSD__ |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
10 #include <sys/param.h> |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
11 #include <sys/ucred.h> |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
12 #include <sys/mount.h> |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
13 #else |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
14 #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
|
15 #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
|
16 #endif |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
17 #endif |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
18 |
3 | 19 int sockread (int a, void *b, int c, int d) |
20 { | |
21 #if defined(__IBMC__) || (defined(__WIN32__) && !defined(__CYGWIN32__)) | |
22 return recv(a,b,c,d); | |
23 #else | |
24 return read(a,b,c); | |
25 #endif | |
26 } | |
27 | |
28 int sockwrite (int a, void *b, int c, int d) | |
29 { | |
30 #if defined(__IBMC__) || (defined(__WIN32__) && !defined(__CYGWIN32__)) | |
31 return send(a,b,c,d); | |
32 #else | |
33 return write(a,b,c); | |
34 #endif | |
35 } | |
36 | |
37 int sockclose(int a) | |
38 { | |
39 #ifdef __IBMC__ | |
40 return soclose(a); | |
41 #elif defined(__WIN32__) && !defined(__CYGWIN32__) | |
42 return closesocket(a); | |
43 #else | |
44 return close(a); | |
45 #endif | |
46 } | |
47 | |
48 int makedir(char *path) | |
49 { | |
50 #if defined(__IBMC__) || (defined(__WIN32__) && !defined(__CYGWIN32__)) | |
51 return mkdir(path); | |
52 #else | |
53 return mkdir(path,S_IRWXU); | |
54 #endif | |
55 } | |
56 | |
57 void nonblock(int fd) | |
58 { | |
59 #ifdef __IBMC__ | |
60 static int _nonblock = 1; | |
61 | |
62 ioctl(fd, FIONBIO, (char *)&_nonblock, sizeof(_nonblock)); | |
63 #elif defined(__WIN32__) && !defined(__CYGWIN32__) | |
64 static unsigned long _nonblock = 1; | |
65 | |
66 ioctlsocket(fd, FIONBIO, &_nonblock); | |
67 #else | |
68 fcntl(fd, F_SETFL, O_NONBLOCK); | |
69 #endif | |
70 } | |
71 | |
72 int socksprintf(int fd, char *format, ...) | |
73 { | |
74 va_list args; | |
75 char outbuf[1024]; | |
76 int len; | |
77 | |
78 va_start(args, format); | |
79 vsprintf(outbuf, format, args); | |
80 va_end(args); | |
81 | |
82 len = strlen(outbuf); | |
83 sockwrite(fd, outbuf, len, 0); | |
84 | |
85 return len; | |
86 } | |
87 | |
88 void sockinit(void) | |
89 { | |
90 #ifdef __IBMC__ | |
91 sock_init(); | |
92 #elif defined(__WIN32__) || defined(WINNT) | |
93 WSADATA wsa; | |
94 | |
95 WSAStartup(MAKEWORD (1, 1), &wsa); | |
96 #endif /* !WIN32 */ | |
97 } | |
98 | |
99 void sockshutdown(void) | |
100 { | |
101 #if defined(__WIN32__) || defined(WINNT) | |
102 WSACleanup(); | |
103 #endif /* !WIN32 */ | |
104 } | |
105 | |
106 int sockpipe(int *pipes) | |
107 { | |
108 #ifndef NO_DOMAIN_SOCKETS | |
109 #ifndef HAVE_PIPE | |
110 struct sockaddr_un un; | |
111 #endif | |
112 #else | |
113 struct sockaddr_in server_addr; | |
114 struct sockaddr_in listen_addr = { 0 }; | |
115 int len = sizeof(struct sockaddr_in); | |
116 struct hostent *he; | |
117 #endif | |
118 #ifndef HAVE_PIPE | |
119 int tmpsock; | |
120 #endif | |
121 | |
122 #ifdef HAVE_PIPE | |
123 return pipe(pipes); | |
124 #elif !defined(NO_DOMAIN_SOCKETS) | |
125 static int instance = -1; | |
126 | |
127 instance++; | |
128 | |
129 /* Use UNIX domain sockets to pass messages */ | |
130 tmpsock = socket(AF_UNIX, SOCK_STREAM, 0); | |
131 pipes[1] = socket(AF_UNIX, SOCK_STREAM, 0); | |
132 memset(&un, 0, sizeof(un)); | |
133 un.sun_family=AF_UNIX; | |
134 sprintf(un.sun_path, PIPENAME, instance); | |
135 bind(tmpsock, (struct sockaddr *)&un, sizeof(un)); | |
136 listen(tmpsock, 0); | |
137 connect(pipes[1], (struct sockaddr *)&un, sizeof(un)); | |
138 pipes[0] = accept(tmpsock, 0, 0); | |
139 sockclose(tmpsock); | |
140 #else | |
141 /* Use localhost socket to pass messages if no domain sockets */ | |
142 he = gethostbyname("localhost"); | |
143 | |
144 if(he) | |
145 { | |
146 memset(&server_addr, 0, sizeof(server_addr)); | |
147 server_addr.sin_family = AF_INET; | |
148 server_addr.sin_port = 0; | |
149 server_addr.sin_addr.s_addr = INADDR_ANY; | |
150 if ((tmpsock = socket(AF_INET, SOCK_STREAM, 0)) < 0 || bind(tmpsock, (struct sockaddr *)&server_addr, sizeof(server_addr)) < 0 || listen(tmpsock, 0) < 0) | |
151 return -1; | |
152 | |
153 memset(&listen_addr, 0, sizeof(listen_addr)); | |
154 getsockname(tmpsock, (struct sockaddr *)&listen_addr, &len); | |
155 | |
156 server_addr.sin_family = AF_INET; | |
157 server_addr.sin_port = listen_addr.sin_port; | |
158 server_addr.sin_addr.s_addr = *((unsigned long *)he->h_addr); | |
159 if((pipes[1] = socket(AF_INET, SOCK_STREAM, 0)) < 0 || connect(pipes[1], (struct sockaddr *)&server_addr, sizeof(server_addr))) | |
160 return -1; | |
161 else | |
162 pipes[0] = accept(tmpsock, 0, 0); | |
163 sockclose(tmpsock); | |
164 } | |
165 else | |
166 return -1; | |
167 #endif | |
168 if(pipes[0] < 0 || pipes[1] < 0) | |
169 return -1; | |
170 return 0; | |
171 } | |
172 | |
173 /* Return in K to avoid big problems exceeding an | |
174 unsigned long when no 64bit integers are available */ | |
175 #if defined(__IBMC__) || (defined(__WIN32__) && !defined(__CYGWIN32__)) | |
176 unsigned long drivefree(int drive) | |
177 #else | |
178 unsigned long long drivefree(int drive) | |
179 #endif | |
180 { | |
181 #if defined(__EMX__) || defined(__OS2__) | |
182 ULONG aulFSInfoBuf[40] = {0}; | |
183 APIRET rc = NO_ERROR; | |
35
432c39a4ff86
New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
184 ULONG kbytes; |
3 | 185 |
186 DosError(FERR_DISABLEHARDERR); | |
187 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
|
188 FSIL_ALLOC, |
432c39a4ff86
New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
189 (PVOID)aulFSInfoBuf, |
432c39a4ff86
New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
190 sizeof(aulFSInfoBuf)); |
3 | 191 |
192 DosError(FERR_ENABLEHARDERR); | |
193 if (rc != NO_ERROR) | |
194 return 0; | |
195 | |
35
432c39a4ff86
New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
196 kbytes = aulFSInfoBuf[3]/1024; |
432c39a4ff86
New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
197 |
432c39a4ff86
New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
198 return (unsigned long)(kbytes * aulFSInfoBuf[1] * aulFSInfoBuf[4]); |
3 | 199 #elif defined(__WIN32__) || defined(WINNT) |
200 char buffer[10] = "C:\\"; | |
201 DWORD spc, bps, fc, tc; | |
36
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
202 ULONG kbytes; |
3 | 203 |
204 buffer[0] = drive + 'A' - 1; | |
205 | |
206 if(GetDiskFreeSpace(buffer, &spc, &bps, &fc, &tc) == 0) | |
207 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
|
208 |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
209 kbytes = fc/1024; |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
210 |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
211 return (unsigned long)(spc*bps*kbytes); |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
212 #elif defined(__FreeBSD__) |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
213 struct statfs *fsp; |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
214 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
|
215 |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
216 entries = getmntinfo (&fsp, MNT_NOWAIT); |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
217 |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
218 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
|
219 { |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
220 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
|
221 return (fsp->f_bsize * fsp->f_bavail) / 1024; |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
222 } |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
223 return 0; |
3 | 224 #else |
36
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
225 FILE *fp = setmntent(MOUNTED, "r"); |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
226 struct mntent *mnt; |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
227 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
|
228 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
|
229 |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
230 if(fp) |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
231 { |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
232 while((mnt = getmntent(fp))) |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
233 { |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
234 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
|
235 { |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
236 long long size = 0; |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
237 |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
238 if(mnt->mnt_dir) |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
239 { |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
240 statfs(mnt->mnt_dir, &sfs); |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
241 size = sfs.f_bsize * (sfs.f_bavail / 1024); |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
242 } |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
243 endmntent(fp); |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
244 return size; |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
245 } |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
246 index++; |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
247 } |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
248 endmntent(fp); |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
249 } |
3 | 250 return 0; |
251 #endif | |
252 } | |
253 | |
35
432c39a4ff86
New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
254 /* Return in K to avoid big problems exceeding an |
432c39a4ff86
New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
255 unsigned long when no 64bit integers are available */ |
432c39a4ff86
New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
256 #if defined(__IBMC__) || (defined(__WIN32__) && !defined(__CYGWIN32__)) |
432c39a4ff86
New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
257 unsigned long drivesize(int drive) |
432c39a4ff86
New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
258 #else |
432c39a4ff86
New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
259 unsigned long long drivesize(int drive) |
432c39a4ff86
New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
260 #endif |
432c39a4ff86
New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
261 { |
432c39a4ff86
New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
262 #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
|
263 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
|
264 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
|
265 ULONG kbytes; |
432c39a4ff86
New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
266 |
432c39a4ff86
New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
267 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
|
268 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
|
269 FSIL_ALLOC, |
432c39a4ff86
New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
270 (PVOID)aulFSInfoBuf, |
432c39a4ff86
New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
271 sizeof(aulFSInfoBuf)); |
432c39a4ff86
New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
272 |
432c39a4ff86
New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
273 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
|
274 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
|
275 return 0; |
432c39a4ff86
New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
276 |
432c39a4ff86
New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
277 kbytes = aulFSInfoBuf[2]/1024; |
432c39a4ff86
New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
278 |
432c39a4ff86
New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
279 return (unsigned long)(kbytes * aulFSInfoBuf[1] * aulFSInfoBuf[4]); |
432c39a4ff86
New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
280 #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
|
281 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
|
282 DWORD spc, bps, fc, tc; |
36
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
283 ULONG kbytes; |
35
432c39a4ff86
New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
284 |
432c39a4ff86
New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
285 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
|
286 |
432c39a4ff86
New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
287 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
|
288 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
|
289 |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
290 kbytes = tc/1024; |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
291 |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
292 return (unsigned long)(spc*bps*kbytes); |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
293 #elif defined(__FreeBSD__) |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
294 struct statfs *fsp; |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
295 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
|
296 |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
297 entries = getmntinfo (&fsp, MNT_NOWAIT); |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
298 |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
299 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
|
300 { |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
301 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
|
302 return (fsp->f_bsize * fsp->f_blocks) / 1024; |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
303 } |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
304 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
|
305 #else |
36
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
306 FILE *fp = setmntent(MOUNTED, "r"); |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
307 struct mntent *mnt; |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
308 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
|
309 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
|
310 |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
311 if(fp) |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
312 { |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
313 while((mnt = getmntent(fp))) |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
314 { |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
315 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
|
316 { |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
317 long long size = 0; |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
318 |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
319 if(mnt->mnt_dir) |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
320 { |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
321 statfs(mnt->mnt_dir, &sfs); |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
322 size = sfs.f_bsize * (sfs.f_blocks / 1024); |
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 endmntent(fp); |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
325 return size; |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
326 } |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
327 index++; |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
328 } |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
329 endmntent(fp); |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
330 } |
35
432c39a4ff86
New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
331 return 0; |
432c39a4ff86
New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
332 #endif |
432c39a4ff86
New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
333 } |
432c39a4ff86
New code for checking drive size on OS/2 and Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
22
diff
changeset
|
334 |
3 | 335 int isdrive(int drive) |
336 { | |
337 #if defined(__EMX__) || defined(__OS2__) | |
338 APIRET rc = NO_ERROR; | |
339 FSINFO volinfo; | |
340 | |
341 DosError(FERR_DISABLEHARDERR); | |
342 rc = DosQueryFSInfo(drive, | |
343 FSIL_VOLSER, | |
344 (PVOID)&volinfo, | |
345 sizeof(FSINFO)); | |
346 | |
347 DosError(FERR_ENABLEHARDERR); | |
348 if (rc == NO_ERROR) | |
349 return 1; | |
350 | |
351 #elif defined(__WIN32__) || defined(WINNT) | |
352 char buffer[10] = "C:\\", volname[100]; | |
353 DWORD spc, bps, fc; | |
354 | |
355 buffer[0] = drive + 'A' - 1; | |
356 | |
357 if(GetVolumeInformation(buffer, volname, 100, &spc, &bps, &fc, NULL, 0) != 0) | |
358 return 1; | |
36
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
359 #elif defined(__FreeBSD__) |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
360 struct statfs *fsp; |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
361 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
|
362 |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
363 entries = getmntinfo (&fsp, MNT_NOWAIT); |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
364 |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
365 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
|
366 { |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
367 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
|
368 return 1; |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
369 } |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
370 return 0; |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
371 #else |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
372 FILE *fp = setmntent(MOUNTED, "r"); |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
373 struct mntent *mnt; |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
374 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
|
375 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
|
376 |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
377 if(fp) |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
378 { |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
379 while((mnt = getmntent(fp))) |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
380 { |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
381 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
|
382 { |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
383 endmntent(fp); |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
384 if(mnt->mnt_dir) |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
385 { |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
386 statfs(mnt->mnt_dir, &sfs); |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
387 if(sfs.f_blocks) |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
388 return 1; |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
389 } |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
390 return 0; |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
391 } |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
392 index++; |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
393 } |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
394 endmntent(fp); |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
395 } |
3 | 396 #endif |
397 return 0; | |
398 } | |
399 | |
36
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
400 void getfsname(int drive, char *buf, int len) |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
401 { |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
402 #ifdef __UNIX__ |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
403 #ifdef __FreeBSD__ |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
404 struct statfs *fsp; |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
405 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
|
406 |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
407 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
|
408 |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
409 entries = getmntinfo (&fsp, MNT_NOWAIT); |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
410 |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
411 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
|
412 { |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
413 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
|
414 strncpy(buf, fsp->f_mntonname, len); |
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 #else |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
417 FILE *fp = setmntent(MOUNTED, "r"); |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
418 struct mntent *mnt; |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
419 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
|
420 |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
421 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
|
422 |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
423 if(fp) |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
424 { |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
425 while((mnt = getmntent(fp))) |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
426 { |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
427 if(index == drive && mnt->mnt_dir) |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
428 strncpy(buf, mnt->mnt_dir, len); |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
429 index++; |
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 endmntent(fp); |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
432 } |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
433 #endif |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
434 #elif defined(__OS2__) |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
435 /* No snprintf() on OS/2 ??? */ |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
436 sprintf(buf, "Drive %c", (char)drive + 'A' - 1); |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
437 #else |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
438 snprintf(buf, len, "Drive %c", (char)drive + 'A' - 1); |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
439 #endif |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
440 } |
cddb02f847e1
Added unix versions of functions in compat, and added getfsname, plus
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
35
diff
changeset
|
441 |
3 | 442 void setfileinfo(char *filename, char *url) |
443 { | |
444 time_t ltime; | |
445 struct tm *tm; | |
446 char buffer[200], timebuf[200]; | |
447 #ifdef __OS2__ | |
448 const unsigned fea2listsize = 6000; | |
449 char *pData; | |
450 EAOP2 eaop2; | |
451 PFEA2 pFEA2; | |
452 #else | |
453 FILE *urlfile; | |
454 #endif | |
455 | |
456 ltime = time(NULL); | |
457 | |
458 tm = localtime(<ime); | |
459 | |
460 strftime(timebuf, 200, "%c", tm); | |
461 | |
462 sprintf(buffer, "%s %s", url, timebuf); | |
463 | |
464 #ifdef __OS2__ | |
465 eaop2.fpGEA2List = 0; | |
466 eaop2.fpFEA2List = (PFEA2LIST)malloc(fea2listsize); | |
467 pFEA2 = &eaop2.fpFEA2List->list[0]; | |
468 | |
469 pFEA2->fEA = 0; | |
470 /* .COMMENTS is 9 characters long */ | |
471 pFEA2->cbName = 9; | |
472 | |
473 /* space for the type and length field. */ | |
474 pFEA2->cbValue = strlen(buffer)+2*sizeof(USHORT); | |
475 | |
476 strcpy(pFEA2->szName, ".COMMENTS"); | |
477 pData = pFEA2->szName+pFEA2->cbName+1; | |
478 /* data begins at first byte after the name */ | |
479 | |
480 *(USHORT*)pData = EAT_ASCII; /* type */ | |
481 *((USHORT*)pData+1) = strlen(buffer); /* length */ | |
482 strcpy(pData+2*sizeof(USHORT), buffer);/* content */ | |
483 | |
484 pFEA2->oNextEntryOffset = 0; | |
485 | |
486 eaop2.fpFEA2List->cbList = ((PCHAR)pData+2*sizeof(USHORT)+ | |
487 pFEA2->cbValue)-((PCHAR)eaop2.fpFEA2List); | |
488 | |
489 DosSetPathInfo(filename, | |
490 FIL_QUERYEASIZE, | |
491 &eaop2, | |
492 sizeof(eaop2), | |
493 0); | |
494 | |
495 free((void *)eaop2.fpFEA2List); | |
496 #else | |
497 | |
498 if((urlfile = fopen("handyftp.url", "a"))!=NULL) | |
499 { | |
500 fprintf(urlfile, "%s\n", buffer); | |
501 fclose(urlfile); | |
502 } | |
503 #endif | |
504 } | |
505 | |
506 #if defined(__OS2__) || defined(__WIN32__) | |
507 typedef struct _fsinfo { | |
508 FILE *fp; | |
509 int fd; | |
510 } FSInfo; | |
511 | |
512 FSInfo *FSIRoot = NULL; | |
513 | |
514 #define FSI_MAX 100 | |
515 #endif | |
516 | |
517 /* Sharable fopen() and fclose() calls. */ | |
518 FILE *fsopen(char *path, char *modes) | |
519 { | |
520 #if defined(__OS2__) || defined(__WIN32__) | |
521 int z; | |
522 | |
523 if(!FSIRoot) | |
524 FSIRoot = calloc(sizeof(struct _fsinfo), FSI_MAX); | |
525 | |
526 for(z=0;z<FSI_MAX;z++) | |
527 { | |
528 if(FSIRoot[z].fd < 1) | |
529 { | |
530 int s, sopenmode = 0, wrmode = 0; | |
531 | |
532 /* Check the flags passed */ | |
533 for(s=0;s<3;s++) | |
534 { | |
535 if(modes[s] == 'b') | |
536 sopenmode |= O_BINARY; | |
537 if(modes[s] == 'r') | |
538 wrmode |= O_RDONLY; | |
539 if(modes[s] == 'w') | |
540 wrmode |= O_WRONLY; | |
541 if(modes[s] == 'a') | |
542 sopenmode |= O_APPEND; | |
543 if(modes[s] == 't') | |
544 sopenmode |= O_TEXT; | |
545 } | |
546 | |
547 /* Check the read/write request */ | |
548 if((wrmode & O_RDONLY) && (wrmode & O_WRONLY)) | |
549 sopenmode |= O_RDWR; | |
550 else | |
551 sopenmode |= wrmode; | |
552 FSIRoot[z].fd = _sopen(path, sopenmode, SH_DENYNO, S_IREAD|S_IWRITE); | |
553 if(FSIRoot[z].fd > 0) | |
554 { | |
555 FSIRoot[z].fp = fdopen(FSIRoot[z].fd, modes); | |
556 | |
557 return FSIRoot[z].fp; | |
558 } | |
559 } | |
560 } | |
561 return NULL; | |
562 #else | |
563 return fopen(path, modes); | |
564 #endif | |
565 } | |
566 | |
567 int fsclose(FILE *fp) | |
568 { | |
569 #if defined(__OS2__) || defined(__WIN32__) | |
570 if(FSIRoot) | |
571 { | |
572 | |
573 int z; | |
574 for(z=0;z<FSI_MAX;z++) | |
575 { | |
576 if(fp == FSIRoot[z].fp) | |
577 { | |
578 int ret = fclose(fp); | |
579 close(FSIRoot[z].fd); | |
580 FSIRoot[z].fd = 0; | |
581 FSIRoot[z].fp = NULL; | |
582 return ret; | |
583 } | |
584 } | |
585 } | |
586 #endif | |
587 return fclose(fp); | |
588 } | |
589 | |
590 char *fsgets(char *str, int size, FILE *stream) | |
591 { | |
592 return fgets(str, size, stream); | |
593 } | |
594 | |
22
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
595 int fsseek(FILE *stream, long offset, int whence) |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
596 { |
6a246b3bb14f
Added tree widgets, fixed some delete event processing, fixed a layout bug
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
597 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
|
598 } |