Mercurial > dwindows
comparison dwcompat.c @ 2644:45a6b33a003a
Linux: Isolate linux/android specific code in #ifdef __linux__
So on unrecognized platforms the functions should just return 0.
This should allow Android to get filesystem info through Linux calls.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Mon, 16 Aug 2021 06:51:28 +0000 |
parents | 736282fddac5 |
children | cb984fab3a17 |
comparison
equal
deleted
inserted
replaced
2643:28ca1e59e76f | 2644:45a6b33a003a |
---|---|
20 #elif defined(__sun__) | 20 #elif defined(__sun__) |
21 #include <sys/mnttab.h> | 21 #include <sys/mnttab.h> |
22 #include <sys/param.h> | 22 #include <sys/param.h> |
23 #include <sys/mount.h> | 23 #include <sys/mount.h> |
24 #include <sys/statvfs.h> | 24 #include <sys/statvfs.h> |
25 #else | 25 #elif defined(__linux__) |
26 #include <mntent.h> | 26 #include <mntent.h> |
27 #include <sys/vfs.h> | 27 #include <sys/vfs.h> |
28 #endif | 28 #endif |
29 #endif | 29 #endif |
30 #include <time.h> | 30 #include <time.h> |
167 index++; | 167 index++; |
168 } | 168 } |
169 fclose(fp); | 169 fclose(fp); |
170 } | 170 } |
171 return 0; | 171 return 0; |
172 #elif !defined(__ANDROID__) | 172 #elif defined(__linux__) |
173 FILE *fp = setmntent(MOUNTED, "r"); | 173 FILE *fp = setmntent(MOUNTED, "r"); |
174 struct mntent mnt; | 174 struct mntent mnt; |
175 struct statfs sfs; | 175 struct statfs sfs; |
176 char buffer[1024]; | 176 char buffer[1024]; |
177 int index = 1; | 177 int index = 1; |
275 index++; | 275 index++; |
276 } | 276 } |
277 fclose(fp); | 277 fclose(fp); |
278 } | 278 } |
279 return 0; | 279 return 0; |
280 #elif !defined(__ANDROID__) | 280 #elif defined(__linux__) |
281 FILE *fp = setmntent(MOUNTED, "r"); | 281 FILE *fp = setmntent(MOUNTED, "r"); |
282 struct mntent mnt; | 282 struct mntent mnt; |
283 char buffer[1024]; | 283 char buffer[1024]; |
284 struct statfs sfs; | 284 struct statfs sfs; |
285 int index = 1; | 285 int index = 1; |
325 sizeof(FSINFO)); | 325 sizeof(FSINFO)); |
326 | 326 |
327 DosError(FERR_ENABLEHARDERR); | 327 DosError(FERR_ENABLEHARDERR); |
328 if (rc == NO_ERROR) | 328 if (rc == NO_ERROR) |
329 return 1; | 329 return 1; |
330 | |
331 #elif defined(__WIN32__) || defined(WINNT) | 330 #elif defined(__WIN32__) || defined(WINNT) |
332 char buffer[10] = "C:\\", volname[100]; | 331 char buffer[10] = "C:\\", volname[100]; |
333 DWORD spc, bps, fc; | 332 DWORD spc, bps, fc; |
334 | 333 |
335 buffer[0] = drive + 'A' - 1; | 334 buffer[0] = drive + 'A' - 1; |
346 { | 345 { |
347 if(index == drive && fsp->f_blocks) | 346 if(index == drive && fsp->f_blocks) |
348 return 1; | 347 return 1; |
349 index++; | 348 index++; |
350 } | 349 } |
351 return 0; | |
352 #elif defined(__sun__) | 350 #elif defined(__sun__) |
353 FILE *fp = fopen("/etc/mnttab", "r"); | 351 FILE *fp = fopen("/etc/mnttab", "r"); |
354 struct mnttab mnt; | 352 struct mnttab mnt; |
355 struct statvfs sfs; | 353 struct statvfs sfs; |
356 int index = 1; | 354 int index = 1; |
371 } | 369 } |
372 index++; | 370 index++; |
373 } | 371 } |
374 fclose(fp); | 372 fclose(fp); |
375 } | 373 } |
376 #elif !defined(__ANDROID__) | 374 #elif defined(__linux__) |
377 FILE *fp = setmntent(MOUNTED, "r"); | 375 FILE *fp = setmntent(MOUNTED, "r"); |
378 struct mntent mnt; | 376 struct mntent mnt; |
379 char buffer[1024]; | 377 char buffer[1024]; |
380 struct statfs sfs; | 378 struct statfs sfs; |
381 int index = 1; | 379 int index = 1; |
404 return 0; | 402 return 0; |
405 } | 403 } |
406 | 404 |
407 void API getfsname(int drive, char *buf, int len) | 405 void API getfsname(int drive, char *buf, int len) |
408 { | 406 { |
409 #if defined(__UNIX__) || defined(__MAC__) || defined(__IOS__) | 407 #if defined(__UNIX__) || defined(__MAC__) || defined(__IOS__) || defined(__ANDROID__) |
410 #if defined(__FreeBSD__) || defined(__MAC__) || defined(__IOS__) | 408 #if defined(__FreeBSD__) || defined(__MAC__) || defined(__IOS__) |
411 struct statfs *fsp = NULL; | 409 struct statfs *fsp = NULL; |
412 int entries, index = 1; | 410 int entries, index = 1; |
413 | 411 |
414 strncpy(buf, "Unknown", len); | 412 strncpy(buf, "Unknown", len); |
436 strncpy(buf, mnt.mnt_mountp, len); | 434 strncpy(buf, mnt.mnt_mountp, len); |
437 index++; | 435 index++; |
438 } | 436 } |
439 fclose(fp); | 437 fclose(fp); |
440 } | 438 } |
441 #else | 439 #elif defined(__linux__) |
442 FILE *fp = setmntent(MOUNTED, "r"); | 440 FILE *fp = setmntent(MOUNTED, "r"); |
443 struct mntent mnt; | 441 struct mntent mnt; |
444 char buffer[1024]; | 442 char buffer[1024]; |
445 int index = 1; | 443 int index = 1; |
446 | 444 |
701 } | 699 } |
702 | 700 |
703 static int locale_number = -1, locale_count = 0; | 701 static int locale_number = -1, locale_count = 0; |
704 static char **locale_text = NULL; | 702 static char **locale_text = NULL; |
705 | 703 |
706 void _compat_free_locale(void) | 704 void _dwcompat_free_locale(void) |
707 { | 705 { |
708 if(locale_text) | 706 if(locale_text) |
709 { | 707 { |
710 int z; | 708 int z; |
711 | 709 |
717 free(locale_text); | 715 free(locale_text); |
718 locale_text = NULL; | 716 locale_text = NULL; |
719 } | 717 } |
720 } | 718 } |
721 | 719 |
722 int _stripcrlf(char *buf) | 720 int _dwcompat_stripcrlf(char *buf) |
723 { | 721 { |
724 int z, len = (int)strlen(buf); | 722 int z, len = (int)strlen(buf); |
725 | 723 |
726 for(z=0;z<len;z++) | 724 for(z=0;z<len;z++) |
727 { | 725 { |
741 { | 739 { |
742 FILE *fp = fopen(filename, FOPEN_READ_TEXT); | 740 FILE *fp = fopen(filename, FOPEN_READ_TEXT); |
743 static char text[1025]; | 741 static char text[1025]; |
744 int count = 0; | 742 int count = 0; |
745 | 743 |
746 _compat_free_locale(); | 744 _dwcompat_free_locale(); |
747 | 745 |
748 if(fp) | 746 if(fp) |
749 { | 747 { |
750 if(fgets(text, 1024, fp) && strncasecmp(text, "MESSAGES=", 9) == 0 && (count = atoi(&text[9])) > 0) | 748 if(fgets(text, 1024, fp) && strncasecmp(text, "MESSAGES=", 9) == 0 && (count = atoi(&text[9])) > 0) |
751 { | 749 { |
753 | 751 |
754 locale_text = calloc(count, sizeof(char *)); | 752 locale_text = calloc(count, sizeof(char *)); |
755 | 753 |
756 while(!feof(fp)) | 754 while(!feof(fp)) |
757 { | 755 { |
758 if(fgets(text, 1024, fp) && _stripcrlf(text) && | 756 if(fgets(text, 1024, fp) && _dwcompat_stripcrlf(text) && |
759 strncasecmp(text, "LOCALE=", 7) == 0) | 757 strncasecmp(text, "LOCALE=", 7) == 0) |
760 { | 758 { |
761 if(current > -1) | 759 if(current > -1) |
762 { | 760 { |
763 fclose(fp); | 761 fclose(fp); |