Mercurial > dwindows
comparison 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 |
comparison
equal
deleted
inserted
replaced
35:432c39a4ff86 | 36:cddb02f847e1 |
---|---|
1 /* $Id$ */ | 1 /* $Id$ */ |
2 | 2 |
3 #include "compat.h" | 3 #include "compat.h" |
4 #if defined(__OS2__) || defined(__WIN32__) | 4 #if defined(__OS2__) || defined(__WIN32__) |
5 #include <share.h> | 5 #include <share.h> |
6 #endif | |
7 | |
8 #ifdef __UNIX__ | |
9 #ifdef __FreeBSD__ | |
10 #include <sys/param.h> | |
11 #include <sys/ucred.h> | |
12 #include <sys/mount.h> | |
13 #else | |
14 #include <mntent.h> | |
15 #include <sys/vfs.h> | |
16 #endif | |
6 #endif | 17 #endif |
7 | 18 |
8 int sockread (int a, void *b, int c, int d) | 19 int sockread (int a, void *b, int c, int d) |
9 { | 20 { |
10 #if defined(__IBMC__) || (defined(__WIN32__) && !defined(__CYGWIN32__)) | 21 #if defined(__IBMC__) || (defined(__WIN32__) && !defined(__CYGWIN32__)) |
186 | 197 |
187 return (unsigned long)(kbytes * aulFSInfoBuf[1] * aulFSInfoBuf[4]); | 198 return (unsigned long)(kbytes * aulFSInfoBuf[1] * aulFSInfoBuf[4]); |
188 #elif defined(__WIN32__) || defined(WINNT) | 199 #elif defined(__WIN32__) || defined(WINNT) |
189 char buffer[10] = "C:\\"; | 200 char buffer[10] = "C:\\"; |
190 DWORD spc, bps, fc, tc; | 201 DWORD spc, bps, fc, tc; |
202 ULONG kbytes; | |
191 | 203 |
192 buffer[0] = drive + 'A' - 1; | 204 buffer[0] = drive + 'A' - 1; |
193 | 205 |
194 if(GetDiskFreeSpace(buffer, &spc, &bps, &fc, &tc) == 0) | 206 if(GetDiskFreeSpace(buffer, &spc, &bps, &fc, &tc) == 0) |
195 return 0; | 207 return 0; |
196 return (unsigned long)(spc*bps*(fc/1024)); | 208 |
197 #else | 209 kbytes = fc/1024; |
210 | |
211 return (unsigned long)(spc*bps*kbytes); | |
212 #elif defined(__FreeBSD__) | |
213 struct statfs *fsp; | |
214 int entries, index = 1; | |
215 | |
216 entries = getmntinfo (&fsp, MNT_NOWAIT); | |
217 | |
218 for (; entries-- > 0; fsp++) | |
219 { | |
220 if(index == drive) | |
221 return (fsp->f_bsize * fsp->f_bavail) / 1024; | |
222 } | |
223 return 0; | |
224 #else | |
225 FILE *fp = setmntent(MOUNTED, "r"); | |
226 struct mntent *mnt; | |
227 struct statfs sfs; | |
228 int index = 1; | |
229 | |
230 if(fp) | |
231 { | |
232 while((mnt = getmntent(fp))) | |
233 { | |
234 if(index == drive) | |
235 { | |
236 long long size = 0; | |
237 | |
238 if(mnt->mnt_dir) | |
239 { | |
240 statfs(mnt->mnt_dir, &sfs); | |
241 size = sfs.f_bsize * (sfs.f_bavail / 1024); | |
242 } | |
243 endmntent(fp); | |
244 return size; | |
245 } | |
246 index++; | |
247 } | |
248 endmntent(fp); | |
249 } | |
198 return 0; | 250 return 0; |
199 #endif | 251 #endif |
200 } | 252 } |
201 | 253 |
202 /* Return in K to avoid big problems exceeding an | 254 /* Return in K to avoid big problems exceeding an |
226 | 278 |
227 return (unsigned long)(kbytes * aulFSInfoBuf[1] * aulFSInfoBuf[4]); | 279 return (unsigned long)(kbytes * aulFSInfoBuf[1] * aulFSInfoBuf[4]); |
228 #elif defined(__WIN32__) || defined(WINNT) | 280 #elif defined(__WIN32__) || defined(WINNT) |
229 char buffer[10] = "C:\\"; | 281 char buffer[10] = "C:\\"; |
230 DWORD spc, bps, fc, tc; | 282 DWORD spc, bps, fc, tc; |
283 ULONG kbytes; | |
231 | 284 |
232 buffer[0] = drive + 'A' - 1; | 285 buffer[0] = drive + 'A' - 1; |
233 | 286 |
234 if(GetDiskFreeSpace(buffer, &spc, &bps, &fc, &tc) == 0) | 287 if(GetDiskFreeSpace(buffer, &spc, &bps, &fc, &tc) == 0) |
235 return 0; | 288 return 0; |
236 return (unsigned long)(spc*bps*(tc/1024)); | 289 |
237 #else | 290 kbytes = tc/1024; |
291 | |
292 return (unsigned long)(spc*bps*kbytes); | |
293 #elif defined(__FreeBSD__) | |
294 struct statfs *fsp; | |
295 int entries, index = 1; | |
296 | |
297 entries = getmntinfo (&fsp, MNT_NOWAIT); | |
298 | |
299 for (; entries-- > 0; fsp++) | |
300 { | |
301 if(index == drive) | |
302 return (fsp->f_bsize * fsp->f_blocks) / 1024; | |
303 } | |
304 return 0; | |
305 #else | |
306 FILE *fp = setmntent(MOUNTED, "r"); | |
307 struct mntent *mnt; | |
308 struct statfs sfs; | |
309 int index = 1; | |
310 | |
311 if(fp) | |
312 { | |
313 while((mnt = getmntent(fp))) | |
314 { | |
315 if(index == drive) | |
316 { | |
317 long long size = 0; | |
318 | |
319 if(mnt->mnt_dir) | |
320 { | |
321 statfs(mnt->mnt_dir, &sfs); | |
322 size = sfs.f_bsize * (sfs.f_blocks / 1024); | |
323 } | |
324 endmntent(fp); | |
325 return size; | |
326 } | |
327 index++; | |
328 } | |
329 endmntent(fp); | |
330 } | |
238 return 0; | 331 return 0; |
239 #endif | 332 #endif |
240 } | 333 } |
241 | 334 |
242 int isdrive(int drive) | 335 int isdrive(int drive) |
261 | 354 |
262 buffer[0] = drive + 'A' - 1; | 355 buffer[0] = drive + 'A' - 1; |
263 | 356 |
264 if(GetVolumeInformation(buffer, volname, 100, &spc, &bps, &fc, NULL, 0) != 0) | 357 if(GetVolumeInformation(buffer, volname, 100, &spc, &bps, &fc, NULL, 0) != 0) |
265 return 1; | 358 return 1; |
266 #endif | 359 #elif defined(__FreeBSD__) |
267 return 0; | 360 struct statfs *fsp; |
361 int entries, index = 1; | |
362 | |
363 entries = getmntinfo (&fsp, MNT_NOWAIT); | |
364 | |
365 for (; entries-- > 0; fsp++) | |
366 { | |
367 if(index == drive && fsp->f_blocks) | |
368 return 1; | |
369 } | |
370 return 0; | |
371 #else | |
372 FILE *fp = setmntent(MOUNTED, "r"); | |
373 struct mntent *mnt; | |
374 struct statfs sfs; | |
375 int index = 1; | |
376 | |
377 if(fp) | |
378 { | |
379 while((mnt = getmntent(fp))) | |
380 { | |
381 if(index == drive) | |
382 { | |
383 endmntent(fp); | |
384 if(mnt->mnt_dir) | |
385 { | |
386 statfs(mnt->mnt_dir, &sfs); | |
387 if(sfs.f_blocks) | |
388 return 1; | |
389 } | |
390 return 0; | |
391 } | |
392 index++; | |
393 } | |
394 endmntent(fp); | |
395 } | |
396 #endif | |
397 return 0; | |
398 } | |
399 | |
400 void getfsname(int drive, char *buf, int len) | |
401 { | |
402 #ifdef __UNIX__ | |
403 #ifdef __FreeBSD__ | |
404 struct statfs *fsp; | |
405 int entries, index = 1; | |
406 | |
407 strncpy(buf, "Unknown", len); | |
408 | |
409 entries = getmntinfo (&fsp, MNT_NOWAIT); | |
410 | |
411 for (; entries-- > 0; fsp++) | |
412 { | |
413 if(index == drive) | |
414 strncpy(buf, fsp->f_mntonname, len); | |
415 } | |
416 #else | |
417 FILE *fp = setmntent(MOUNTED, "r"); | |
418 struct mntent *mnt; | |
419 int index = 1; | |
420 | |
421 strncpy(buf, "Unknown", len); | |
422 | |
423 if(fp) | |
424 { | |
425 while((mnt = getmntent(fp))) | |
426 { | |
427 if(index == drive && mnt->mnt_dir) | |
428 strncpy(buf, mnt->mnt_dir, len); | |
429 index++; | |
430 } | |
431 endmntent(fp); | |
432 } | |
433 #endif | |
434 #elif defined(__OS2__) | |
435 /* No snprintf() on OS/2 ??? */ | |
436 sprintf(buf, "Drive %c", (char)drive + 'A' - 1); | |
437 #else | |
438 snprintf(buf, len, "Drive %c", (char)drive + 'A' - 1); | |
439 #endif | |
268 } | 440 } |
269 | 441 |
270 void setfileinfo(char *filename, char *url) | 442 void setfileinfo(char *filename, char *url) |
271 { | 443 { |
272 time_t ltime; | 444 time_t ltime; |