linux.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /* contrib/mips-msa/linux.c
  2. *
  3. * Copyright (c) 2016 Glenn Randers-Pehrson
  4. * Written by Mandar Sahastrabuddhe, 2016.
  5. * Last changed in libpng 1.6.25beta03 [August 29, 2016]
  6. *
  7. * This code is released under the libpng license.
  8. * For conditions of distribution and use, see the disclaimer
  9. * and license in png.h
  10. *
  11. * SEE contrib/mips-msa/README before reporting bugs
  12. *
  13. * STATUS: SUPPORTED
  14. * BUG REPORTS: png-mng-implement@sourceforge.net
  15. *
  16. * png_have_msa implemented for Linux by reading the widely available
  17. * pseudo-file /proc/cpuinfo.
  18. *
  19. * This code is strict ANSI-C and is probably moderately portable; it does
  20. * however use <stdio.h> and it assumes that /proc/cpuinfo is never localized.
  21. */
  22. #include <stdio.h>
  23. #include <string.h>
  24. #include <stdlib.h>
  25. static int
  26. png_have_msa(png_structp png_ptr)
  27. {
  28. FILE *f = fopen("/proc/cpuinfo", "rb");
  29. char *string = "msa";
  30. char word[10];
  31. if (f != NULL)
  32. {
  33. while(!feof(f))
  34. {
  35. int ch = fgetc(f);
  36. static int i = 0;
  37. while(!(ch <= 32))
  38. {
  39. word[i++] = ch;
  40. ch = fgetc(f);
  41. }
  42. int val = strcmp(string, word);
  43. if (val == 0)
  44. return 1;
  45. i = 0;
  46. memset(word, 0, 10);
  47. }
  48. fclose(f);
  49. }
  50. #ifdef PNG_WARNINGS_SUPPORTED
  51. else
  52. png_warning(png_ptr, "/proc/cpuinfo open failed");
  53. #endif
  54. return 0;
  55. }